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

Arrays::isShortArray(): fix compatibility with older PHPCS versions #54

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jan 23, 2020

Arrays::isShortArray(): add tests for PHPCS BC compatibility

The PHPCS tokenizer has had a number of issues over the years where the brackets for short arrays were being incorrectly tokenized.
These tests cover those situations.

Arrays::isShortArray(): fix compatibility with PHPCS 2.8.0 - 3.2.3 [1]

PHPCS 2.8.0 - 3.2.3 contained a bug where a square open bracket [ as the first code content after the PHP open tag in a file would be tokenized as T_OPEN_SQUARE_BRACKET not T_OPEN_SHORT_ARRAY.

This is an edge-case bug as it can only occur when following the very first PHP open tag in a file and only if there is nothing before that open tag.

Either way, this commit adds work-arounds to the utility method to handle the situation correctly.

Includes adding two convenience token arrays for working with arrays in older PHPCS versions to the PHPCSUtils\Tokens\Collections class.

Ref: squizlabs/PHP_CodeSniffer#1971

Arrays::isShortArray(): fix compatibility with PHPCS < 2.9.0 [2]

Work around a bug in the tokenizer of PHPCS < 2.9.0 where array dereferencing of short arrays and string literals would be incorrectly tokenized as short array.
I.e. the square brackets in 'PHP'[0] would be tokenized as short array.

This commit adds work-arounds to the utility method to handle the situation correctly.

Ref: squizlabs/PHP_CodeSniffer#1381

Arrays::isShortArray(): fix compatibility with PHPCS 2.8.0 - 2.8.1 [3]

Work around a bug in the tokenizer of PHPCS 2.8.0 and 2.8.1 where array dereferencing of a variable variable would be incorrectly tokenized as short array.

This commit adds work-arounds to the utility method to handle the situation correctly.

Ref: squizlabs/PHP_CodeSniffer#1284

Arrays::isShortArray(): fix compatibility with PHPCS < 2.8.0 [4]

Work around a bug in the tokenizer of PHPCS < 2.8.0 where a [ would be tokenized as T_OPEN_SQUARE_BRACKET instead of T_OPEN_SHORT_ARRAY if it was preceded by a close curly of a control structure.

This commit adds work-arounds to the utility method to handle the situation correctly.

Ref: squizlabs/PHP_CodeSniffer#1284

jrfnl added 5 commits January 23, 2020 02:32
The PHPCS tokenizer has had a number of issues over the years where the brackets for short arrays were being incorrectly tokenized.
These tests cover those situations.
PHPCS 2.8.0 - 3.2.3 contained a bug where a square open bracket `[` as the first code content after the PHP open tag in a file would be tokenized as `T_OPEN_SQUARE_BRACKET` not `T_OPEN_SHORT_ARRAY`.

This is an edge-case bug as it can only occur when following the very first PHP open tag in a file and only if there is nothing before that open tag.

Either way, this commit adds work-arounds to the utility method to handle the situation correctly.

Includes adding two convenience token arrays for working with arrays in older PHPCS versions to the `PHPCSUtils\Tokens\Collections` class.

Ref: squizlabs/PHP_CodeSniffer 1971
Work around a bug in the tokenizer of PHPCS < 2.9.0 where array dereferencing of short arrays and string literals would be incorrectly tokenized as short array.
I.e. the square brackets in `'PHP'[0]` would be tokenized as short array.

This commit adds work-arounds to the utility method to handle the situation correctly.

Ref: squizlabs/PHP_CodeSniffer 1381
Work around a bug in the tokenizer of PHPCS 2.8.0 and 2.8.1 where array dereferencing of a variable variable would be incorrectly tokenized as short array.

This commit adds work-arounds to the utility method to handle the situation correctly.

Ref: squizlabs/PHP_CodeSniffer 1284
Work around a bug in the tokenizer of PHPCS < 2.8.0 where a `[` would be tokenized as T_OPEN_SQUARE_BRACKET instead of T_OPEN_SHORT_ARRAY if it was preceded by a close curly of a control structure.

This commit adds work-arounds to the utility method to handle the situation correctly.

Ref: squizlabs/PHP_CodeSniffer 1284
@jrfnl jrfnl added this to the 1.0.0 milestone Jan 23, 2020
@jrfnl jrfnl merged commit 139d8a0 into develop Jan 23, 2020
@jrfnl jrfnl deleted the feature/arrays-isshortarray-make-compatible-with-older-phpcs branch January 23, 2020 02:10
@jrfnl jrfnl modified the milestones: 1.0.0, 1.0.0-alpha1 May 1, 2020
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