PHPCSStandards / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
880 stars 54 forks source link

Squiz/SelfMemberReference: bug fix - false negative with namespace keyword as operator #587

Closed jrfnl closed 1 month ago

jrfnl commented 1 month ago

Description

The namespace keyword can both be used for namespace declarations as well as as an operator - "magic keyword" - to resolve to the current namespace. See: https://www.php.net/manual/en/language.namespaces.nsconstants.php#example-298

This last case is not correctly taken into account when determining the current namespace, which leads to false negatives.

Fixed now.

Includes test.

Suggested changelog entry

Fixed: Squiz.Classes.SelfMemberReference: false negatives when namespace keyword used as operator was encountered between the namespace declaration and the OO declaration.

Related issues/external references

Fixes #553

Types of changes