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

:sparkles: New ObjectDeclarations::getDeclared*() utility methods #592

Closed jrfnl closed 3 months ago

jrfnl commented 4 months ago

This commit adds a new set of utility methods to the ObjectDeclarations class:

These methods allow for retrieving an array with the names of all constants, enum cases, properties and methods as the keys and the stack pointer to the relevant T_CONST, T_ENUM_CASE, T_VARIABLE or T_FUNCTION token as the value.

As these methods all used the same analyzeOOStructure() method under the hood and the results of that method are cached, the method are highly optimized for performance.

If a sniff needs to search for a named constant/enum case/property/method in an OO structure, in most cases, these methods should be the recommended way for finding the declaration, instead of the sniff attempting to do this itself.

Includes extensive unit tests.

Closes #124

jrfnl commented 4 months ago

Rebased on top of https://github.com/PHPCSStandards/PHPCSUtils/pull/600 and added a commit to take advantage of the new exceptions. Moving to draft until https://github.com/PHPCSStandards/PHPCSUtils/pull/600 has been merged.

jrfnl commented 3 months ago

Rebased without changes, other than squashing the "use new exceptions" commit into the base commit. Marking as ready as https://github.com/PHPCSStandards/PHPCSUtils/pull/600 has been merged now. Merging once the build passes.