You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a file called test.php with the code sample above...
Run phpcs -ps ./test.php --standard=squiz --sniffs=squiz.classes.selfmemberreference
See error message displayed
------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------
11 | ERROR | [x] Must use "self::" for local static member reference (Squiz.Classes.SelfMemberReference.NotUsed)
------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------
Now uncomment line 5 containing the namespace keyword used as an operator.
Run phpcs -ps ./test.php --standard=squiz --sniffs=squiz.classes.selfmemberreference again.
See no error displayed <= this is the false negative.
Expected behavior
That namespace keywords used as an operator are ignored when determining the applicable namespace name.
Versions (please complete the following information)
Operating System
not relevant (Windows 10)
PHP version
not relevant (8.3.8)
PHP_CodeSniffer version
3.10.1 / master as of today
Standard
Squiz
Install type
not relevant (git clone)
Please confirm
I have searched the issue list and am not opening a duplicate issue.
Describe the bug
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.
Code sample
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs -ps ./test.php --standard=squiz --sniffs=squiz.classes.selfmemberreference
namespace
keyword used as an operator.phpcs -ps ./test.php --standard=squiz --sniffs=squiz.classes.selfmemberreference
again.Expected behavior
That
namespace
keywords used as an operator are ignored when determining the applicable namespace name.Versions (please complete the following information)
master
as of todayPlease confirm
master
branch of PHP_CodeSniffer.The text was updated successfully, but these errors were encountered: