Closed aymanrady closed 3 weeks ago
@aymanrady Thank you for reporting this issue! The actual problem is in the underlying PHPCSUtils package, so I'll transfer the issue to that repo.
Technical explanation of the bug:
The PHPCSUtils Numbers::is*()
methods (like Numbers::isDecimalInt()
, which is used in the AbstractArrayDeclarationSniff::getActualArrayKey()
method, which is what the DuplicateArrayKey
sniff uses to determine the real key), strips underscores from a textual representation of the array key as part of its handling of PHP 7.4 numeric literals with separators.
However, the underscore separator is not allowed at the start or end of the number, but the Numbers
class did not take this into account properly.
This was partially by design to make the class developer-error tolerant - which allows for PHPCS sniffs using the functions to report on such developer errors -, but this bug report makes a good case for removing this developer error tolerance from these methods.
FYI: PR #620 should fix this issue and will be included in PHPCSUtils1.1.0, which I'm hoping to release later this week.
Bug Description
Universal.Arrays.DuplicateArrayKey.Found is incorrectly reported in an array with number-like keys.
Given the following reproduction Scenario
The issue happens when running this command:
... over a file containing this code:
I'd expect the following behaviour
No errors.
Instead this happened
Environment
Additional Context (optional)
Ran unit tests with this patch
Tested Against
develop
branch?develop
branch of PHPCSExtra.