Closed jrfnl closed 3 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.
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.
This commit adds a new set of utility methods to the
ObjectDeclarations
class:getDeclaredConstants(File $phpcsFile, int $stackPtr): array
getDeclaredEnumCases(File $phpcsFile, int $stackPtr): array
getDeclaredProperties(File $phpcsFile, int $stackPtr): array
getDeclaredMethods(File $phpcsFile, int $stackPtr): array
private
)analyzeOOStructure(File $phpcsFile, int $stackPtr): array
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
orT_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