Closed jrfnl closed 5 months ago
As per https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/421#issuecomment-2027997416:
Hmm.. turns out the code sample which triggered me to look into this was actually a parse error 🤦🏻♀️. I do still believe the change has value, but I've updated the PR description to reflect the reality (and simplified the tests a little).
Upstream PR has been merged and will be included in PHPCS 3.9.2.
Sister-PR to upstream PR PHPCSStandards/PHP_CodeSniffer#421
This PR improves performance of the
BCFile::getMethodProperties()
and theFunctionDeclarations::getProperties()
methods and prevents incorrect return type information for closuresuse
clauses containing invalid variable imports in theuse
clause (defensive coding).Closure
use
statements can only import plain variables, not properties or other more complex variables.As things were, when such "illegal" variables were imported in a closure
use
, the information for the return type could get mangled. While this would be a parse error, for the purposes of static analysis, theBCFile::getMethodProperties()
method and theFunctionDeclarations::getProperties()
method should still handle this correctly.This commit updates both methods to always skip over the complete
use
clause, which prevents the issue and improves performance as the same time (less token walking).Includes unit tests.