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

Update after release of PHPCS 3.7.2 #444

Merged
merged 4 commits into from
Mar 28, 2023

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Mar 28, 2023

Internal: new StableCollections class

... to allow for optimizing the token arrays in the PHPCSUtils\Tokens\Collections class without affecting functions and tests in PHPCSUtils itself.

Internal/IsShortArrayOrList[WithCache]: use stable token collections

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.

PassedParameters: update for PHPCS 3.7.2

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.

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_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

jrfnl added 4 commits March 28, 2023 16:46
... 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
@jrfnl jrfnl added this to the 1.0.x Next milestone Mar 28, 2023
@jrfnl jrfnl changed the title Update after release pof PHPCS 3.7.2 Update after release of PHPCS 3.7.2 Mar 28, 2023
@jrfnl jrfnl merged commit 344d342 into develop Mar 28, 2023
@jrfnl jrfnl deleted the feature/update-after-release-phpcs-3.7.2 branch March 28, 2023 15:17
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.

1 participant