Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PHP 7.4 introduced numeric literal separators which break number tokenization in older PHP versions.
PHPCS backfills this since PHPCS 3.5.3, but that backfill implementation is broken in such a bad way that PHPCS 3.5.3 can not be supported.
A fix for the backfill has been merged and will be included in PHPCS 3.5.4.
Having said that, if an external standard intends to support PHPCS < 3.5.3 and/or PHP < 7.4, working with number tokens has become a challenge, as without the backfill any number token is potentially broken
The functions in this class have been put in place to ease that pain and it is strongly recommended to always use these functions when sniffing for and/or examining the contents of
T_LNUMBER
orT_DNUMBER
tokens.Note: sniffing for
T_STRING
tokens is also affected by this PHP 7.4 change, but that is not addressed here.The
Numbers
class introduces two new methods:getCompleteNumber()
- Helper function to deal with numeric literals, potentially with underscore separators. Returns an array with information about the number.getDecimalValue()
- Get the decimal number value of a numeric string. Returns the value as a string or false if the passed parameter was not a (numeric) string.isDecimalInt()
- Check if an arbitrary string represents a decimal integer. Returns boolean.isHexidecimalInt()
- Check if an arbitrary string represents a hexidecimal integer. Returns boolean.isBinaryInt()
- Check if an arbitrary string represents a binary integer. Returns boolean.isOctalInt()
- Check if an arbitrary string represents a octal integer. Returns boolean.isFloat()
- Check if an arbitrary string represents a floating point number. Returns boolean.Includes dedicated unit tests for these methods.