Skip to content

Feature suggestion: utilities to examine PHP attributes #616

Open
@jrfnl

Description

@jrfnl

Is your feature request related to a problem?

PHP 8.0 introduced attributes.

Attributes can reference either a single attribute class or multiple attribute classes.

While splitting the attribute up to its individual parts and potentially retrieving a list of attribute class names is not that hard to do, it still makes for duplicate code and could benefit from caching if this action is executed in multiple sniffs.

#[MyAttributeA(12, 34), MyAttributeB(5678)]

Describe the solution you'd like

I imagine a new PHPCSUtils\Utils\Attributes utility class could be added with one or more helper methods, the precise form these will take, is yet to be determined.

Additional context (optional)

The above could also benefit from the namespace resolution features which are already planned for PHPCSUtils.

Also note that the PassedParameters class can already handle parsing the parameters passed to an attribute class.

This ticket is inspired by PHPCompatibility/PHPCompatibility#1480

  • I intend to create a pull request to implement this feature.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions