Merged
Conversation
... to allow for optimizing the token arrays in the `PHPCSUtils\Tokens\Collections` class without affecting functions and tests in PHPCSUtils itself.
The token collections from the `Collections` class can return different tokens depending on the PHPCS version used. This can impact the functionality of various utilities in PHPCSUtils. While for _most_ functionality, this is exactly the intended behaviour, for the code in the `Internal` classes, it is not and that code should still support the _full_ functionality (determining whether a square bracket is a real square bracket, a short array or a short list) as otherwise the code becomes untestable (and more difficult to maintain). Sniffs should use the `Collections` class token arrays and should - depending on the PHPCS version - just no longer send "plain square brackets" to these classes, which will optimize sniff performance.
Make sure the `Collections::parameterPassingTokens()` also no longer accepts the `T_OPEN_SQUARE_BRACKET` token when on PHPCS 3.7.2 or higher (as it will never be a short array). Includes updating one test to be in line with this.
PHPCS 3.7.2 has been released with a fix related to the tokenization of short arrays/short lists. With that fix included, sniffs no longer need to examine square bracket tokens anymore to check if those happen to be a short list/short array (well, not until the next bug is discovered). This commit updates all BC compatible token collections related to short lists/short arrays to only include the `T_[OPEN|CLOSE]_SQUARE_BRACKET` tokens when on PHPCS < 3.7.2. The net effect of this change should be that sniffing will be significantly faster on PHPCS 3.7.2. Includes adjusted unit tests for the Collections. **Note: _if/when the minimum supported PHPCS version goes up to PHPCS 3.7.2 or higher, this commit can be reverted and the square bracket tokens can be removed from the property based arrays instead._** Ref: squizlabs/PHP_CodeSniffer 3632
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Internal: new StableCollections class
... to allow for optimizing the token arrays in the
PHPCSUtils\Tokens\Collectionsclass without affecting functions and tests in PHPCSUtils itself.Internal/IsShortArrayOrList[WithCache]: use stable token collections
The token collections from the
Collectionsclass can return different tokens depending on the PHPCS version used.This can impact the functionality of various utilities in PHPCSUtils.
While for most functionality, this is exactly the intended behaviour, for the code in the
Internalclasses, it is not and that code should still support the full functionality (determining whether a square bracket is a real square bracket, a short array or a short list) as otherwise the code becomes untestable (and more difficult to maintain).Sniffs should use the
Collectionsclass token arrays and should - depending on the PHPCS version - just no longer send "plain square brackets" to these classes, which will optimize sniff performance.PassedParameters: update for PHPCS 3.7.2
Make sure the
Collections::parameterPassingTokens()also no longer accepts theT_OPEN_SQUARE_BRACKETtoken when on PHPCS 3.7.2 or higher (as it will never be a short array).Includes updating one test to be in line with this.
Collections: update array/list token collection for PHPCS 3.7.2
PHPCS 3.7.2 has been released with a fix related to the tokenization of short arrays/short lists.
With that fix included, sniffs no longer need to examine square bracket tokens anymore to check if those happen to be a short list/short array (well, not until the next bug is discovered).
This commit updates all BC compatible token collections related to short lists/short arrays to only include the
T_[OPEN|CLOSE]_SQUARE_BRACKETtokens when on PHPCS < 3.7.2.The net effect of this change should be that sniffing will be significantly faster on PHPCS 3.7.2.
Includes adjusted unit tests for the Collections.
Note: if/when the minimum supported PHPCS version goes up to PHPCS 3.7.2 or higher, this commit can be reverted and the square bracket tokens can be removed from the property based arrays instead.
Ref: squizlabs/PHP_CodeSniffer#3632