Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numbers::is*(): remove fault tolerance for invalid numeric literals with underscores #620

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Aug 19, 2024

Numbers::is*(): remove fault tolerance for invalid numeric literals with underscores

Numeric literals with underscores have restrictions as to where the underscores are allowed.

The Numbers class did not take this into account to have some allowance for developer error, but as a bug has now been reported for the AbstractArrayDeclarationSniff::getActualArrayKey() method, which is due to this fault tolerance, the fault tolerance will be removed and the Numbers::is*() methods will now only allow underscore separators in places where PHP allows them.

Note: There is still one restriction which is not yet handled: 1__1, i.e. two underscores next to each.
If at some point in the future a bug for this would be reported, this can be reconsidered.

Includes a plenitude of additional tests.

Fixes #619

Refs:

AbstractArrayDeclarationSniff::getActualArrayKey(): add extra tests

…ith underscores

Numeric literals with underscores have restrictions as to where the underscores are allowed.

The `Numbers` class did not take this into account to have some allowance for developer error, but as a bug has now been reported for the `AbstractArrayDeclarationSniff::getActualArrayKey()` method, which is due to this fault tolerance, the fault tolerance will be removed and the `Numbers::is*()` methods will now only allow underscore separators in places where PHP allows them.

Note: There is still one restriction which is not yet handled: `1__1`, i.e. two underscores next to each.
If at some point in the future a bug for this would be reported, this can be reconsidered.

Includes a plenitude of additional tests.

Fixes 619

Refs:
* https://wiki.php.net/rfc/numeric_literal_separator#restrictions
@jrfnl jrfnl added this to the 1.1.0 milestone Aug 19, 2024
@jrfnl jrfnl merged commit 8a1f3f5 into develop Aug 19, 2024
54 checks passed
@jrfnl jrfnl deleted the feature/619-numbers-reduce-fault-tolerance-for-numeric-literals-with-separator branch August 19, 2024 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive Universal.Arrays.DuplicateArrayKey.Found when array keys look numeric
1 participant