PHPCSStandards / PHPCSUtils

A suite of utility functions for use with PHP_CodeSniffer
https://phpcsutils.com/
GNU Lesser General Public License v3.0
53 stars 7 forks source link

Feature suggestion: utilities to examine PHP attributes #616

Open jrfnl opened 1 month ago

jrfnl commented 1 month ago

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 https://github.com/PHPCompatibility/PHPCompatibility/issues/1480