-
-
Notifications
You must be signed in to change notification settings - Fork 77
Open
Description
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:
namespace Foo;
function define($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:
namespace Foo;
use function Bar\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.
- I have read the Contribution Guidelines and this is not a support question.
- I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
- I have verified the issue still exists in the
master
branch of PHP_CodeSniffer.