Skip to content

ValidIntegers: move to Numbers category, split the sniff & support PHP 7.4 numeric literals#1004

Merged
wimg merged 7 commits intodevelopfrom
feature/validintegers-phpcsutils
Apr 10, 2020
Merged

ValidIntegers: move to Numbers category, split the sniff & support PHP 7.4 numeric literals#1004
wimg merged 7 commits intodevelopfrom
feature/validintegers-phpcsutils

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Apr 4, 2020

ValidIntegers: move to the new Numbers category

PR #984 introduces a new Numbers category, so it seem appropriate to move the sniff to that category.

⚠️ This is a BC-break and should be annotated as such in the changelog. ⚠️

New RemovedHexadecimalNumericStrings sniff, split off from ValidIntegers

Split the ValidIntegers sniff in two:

  • A new PHPCompatibility.Numbers.RemovedHexadecimalNumericStrings which examines hexadecimal numeric strings.
  • The existing ValidIntegers sniff will now only focus on actual numbers (binary, octal).

⚠️ This is a BC-break and should be annotated as such in the changelog. ⚠️

Note: the new sniff implements the PHPCSUtils Numbers::isHexidecimalInt() method.

ValidIntegers: reduce memory usage

As the token "type" no longer needs to be checked as the sniff no longer looks for anything but T_LNUMBER tokens, a number of the private helper methods can be simplified and not passing the whole token stack to each function will reduce memory usage.

ValidIntegers: use PHPCSUtils x 2

  • Use the Numbers::isBinaryInt() method to determine if something is a binary integer.
  • Use the GetTokensAsString::normal() method to retrieve a code snippet for display in an error message.

ValidIntegers: minor simplification

Just call the Numbers::isBinaryInt() method directly.

ValidIntegers: add unit tests for PHP 7.4 numeric literals with underscores

ValidIntegers: add support for PHP 7.4 numeric literals with underscores

... by using the Numbers::getCompleteNumber() method to obtain the relevant information in a PHP + PHPCS cross-version compatible way.

jrfnl added 7 commits April 4, 2020 06:23
This is a BC-break and should be annotated as such in the changelog.
Split the `ValidIntegers` sniff in two:
* A new `PHPCompatibility.Numbers.RemovedHexadecimalNumericStrings` which examines hexadecimal numeric strings.
* The existing `ValidIntegers` sniff will now only focus on actual numbers (binary, octal).

This is a BC-break and should be annotated as such in the changelog.

Note: the new sniff implements the PHPCSUtils `Numbers::isHexidecimalInt()` method.
As the token "type" no longer needs to be checked as the sniff no longer looks for anything but `T_LNUMBER` tokens, a number of the private helper methods can be simplified and not passing the whole token stack to each function will reduce memory usage.
* Use the `Numbers::isBinaryInt()` method to determine if something is a binary integer.
* Use the `GetTokensAsString::normal()` method to retrieve a code snippet for display in an error message.
Just call the `Numbers::isBinaryInt()` method directly.
... by using the `Numbers::getCompleteNumber()` method to obtain the relevant information in a PHP + PHPCS cross-version compatible way.
@wimg wimg merged commit a93768a into develop Apr 10, 2020
@wimg wimg deleted the feature/validintegers-phpcsutils branch April 10, 2020 13:27
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.

2 participants