pub trait Reflection: HasSpan + HasSource {
// Required methods
fn get_category(&self) -> SourceCategory;
fn is_populated(&self) -> bool;
fn take_issues(&mut self) -> IssueCollection;
// Provided methods
fn is_user_defined(&self) -> bool { ... }
fn is_external(&self) -> bool { ... }
fn is_built_in(&self) -> bool { ... }
}Expand description
The Reflection trait is implemented by all reflection types in the system.
It provides a consistent interface for querying metadata about PHP constructs such as classes, functions, and other entities. This trait allows the system to introspect and categorize these constructs based on their origin, source, and other attributes.
Required Methods§
Sourcefn get_category(&self) -> SourceCategory
fn get_category(&self) -> SourceCategory
Retrieves the SourceCategory for the entity.
The SourceCategory indicates whether the entity belongs to one of the following:
BuiltIn: A PHP construct that is part of the PHP core or standard library.External: A construct defined in third-party or vendor-provided libraries.UserDefined: A construct written by the user or part of the current project.
§Returns
- A
SourceCategoryenum variant corresponding to the entity’s origin.
Sourcefn is_populated(&self) -> bool
fn is_populated(&self) -> bool
Indicates whether the entity has been fully populated with metadata.
This can be useful to determine whether lazy-loaded or partially processed entities have had their information fully resolved.
§Returns
trueif the entity’s metadata is fully populated.falseif additional processing is needed to populate the metadata.
Sourcefn take_issues(&mut self) -> IssueCollection
fn take_issues(&mut self) -> IssueCollection
Take any issues found during the population of the reflection.
The returned IssueCollection contains errors, warnings, or notices
related to the metadata of the entity.
This method is particularly useful for static analysis tools or compilers to report potential problems in the code being analyzed.
§Returns
- A reference to an
IssueCollectioncontaining all detected issues.
Provided Methods§
Sourcefn is_user_defined(&self) -> bool
fn is_user_defined(&self) -> bool
Indicates whether the entity is user-defined or part of the current project.
§Returns
trueif the entity’sSourceCategoryisUserDefined.falseotherwise.
Sourcefn is_external(&self) -> bool
fn is_external(&self) -> bool
Indicates whether the entity originates from an external source (e.g., vendor libraries).
§Returns
trueif the entity’sSourceCategoryisVendoror similar external categories.falseotherwise.
Sourcefn is_built_in(&self) -> bool
fn is_built_in(&self) -> bool
Indicates whether the entity is a built-in PHP construct.
Built-in constructs include classes, functions, and constants that are part of the PHP core or extensions.
§Returns
trueif the entity’sSourceCategoryisBuiltIn.falseotherwise.