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
When a codebase contains a namespaced function called define, the sniff may throw false positives.
Code sample
File 1:
namespaceFoo;
functiondefine($name, $value) {
// Do something.
}
// These are calls to the namespaced function, not the global one.define('name', 'value');
namespace\define('name', 'value');
// This is a call to another namespaced function `Foo\Sub\define()`, not the global one.Sub\define('name', 'value');
// This is a call to yet another namespaced function `My\Other\NS\define()`, not the global one.\My\Other\NS\define('name', 'value');
File 2:
namespaceFoo;
usefunctionBar\define;
// This is a call to the imported namespaced function, not the global one.define('name', 'value');
To reproduce
Steps to reproduce the behavior:
Create a file called test.php with the code sample above...
Run phpcs test.php --standard=generic --sniffs=generic.namingconventions.uppercaseconstantname
See error message displayed
# File 1:
---------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
---------------------------------------------------------------------------------------------------------------------------------------------------
10 | ERROR | Constants must be uppercase; expected 'NAME' but found 'name' (Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase)
11 | ERROR | Constants must be uppercase; expected 'NAME' but found 'name' (Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase)
14 | ERROR | Constants must be uppercase; expected 'NAME' but found 'name' (Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase)
17 | ERROR | Constants must be uppercase; expected 'NAME' but found 'name' (Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase)
---------------------------------------------------------------------------------------------------------------------------------------------------
# File 2:
--------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------------------------------
8 | ERROR | Constants must be uppercase; expected 'NAME' but found 'name' (Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase)
--------------------------------------------------------------------------------------------------------------------------------------------------
Expected behavior
No errors.
Versions (please complete the following information)
Operating System
not relevant
PHP version
not relevant
PHP_CodeSniffer version
master
Standard
Generic
Install type
not relevant
Additional context
Add any other context about the problem here.
Please confirm
I have searched the issue list and am not opening a duplicate issue.
Describe the bug
Inspired by #665
When a codebase contains a namespaced function called
define
, the sniff may throw false positives.Code sample
File 1:
File 2:
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php --standard=generic --sniffs=generic.namingconventions.uppercaseconstantname
Expected behavior
No errors.
Versions (please complete the following information)
master
Generic
Additional context
Add any other context about the problem here.
Please confirm
master
branch of PHP_CodeSniffer.The text was updated successfully, but these errors were encountered: