Reflection

Trait Reflection 

Source
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§

Source

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 SourceCategory enum variant corresponding to the entity’s origin.
Source

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
  • true if the entity’s metadata is fully populated.
  • false if additional processing is needed to populate the metadata.
Source

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 IssueCollection containing all detected issues.

Provided Methods§

Source

fn is_user_defined(&self) -> bool

Indicates whether the entity is user-defined or part of the current project.

§Returns
  • true if the entity’s SourceCategory is UserDefined.
  • false otherwise.
Source

fn is_external(&self) -> bool

Indicates whether the entity originates from an external source (e.g., vendor libraries).

§Returns
  • true if the entity’s SourceCategory is Vendor or similar external categories.
  • false otherwise.
Source

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
  • true if the entity’s SourceCategory is BuiltIn.
  • false otherwise.

Implementors§