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

New Utils\Lists class #49

Merged
merged 4 commits into from
Jan 22, 2020
Merged

New Utils\Lists class #49

merged 4 commits into from
Jan 22, 2020

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jan 22, 2020

New Utils\Lists class

This adds a new utility method:

  • isShortList() - to check whether a short array is in actual fact a short list. Returns boolean.

This method has been battle-tested in the past year or so in the PHPCompatibility standard.

This commit also adds two convenience token arrays for working with lists to the PHPCSUtils\Tokens\Collections class.

Includes dedicated unit tests.

Lists::isShortList(): 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 unit tests.

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

Ref: squizlabs/PHP_CodeSniffer#1971

Lists::isShortList(): safeguard PHPCS cross-version compatibility [2]

Add unit tests safeguarding that the method handles upstream tokenizer bug 1381 correctly.

Ref: squizlabs/PHP_CodeSniffer#1381

Lists::isShortList(): fix compatibility with PHPCS < 2.8.0 [3]

PHPCS < 2.8.0 contained a bug where a square open bracket [ directly following a closing curly would always be tokenized as T_OPEN_SQUARE_BRACKET, presuming this was array dereferencing/assignment on a variable variable.

If the closing curly however belonged to a control structure, this was incorrect and the token should have been changed to T_OPEN_SHORT_ARRAY.

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

Includes unit tests.

Ref: squizlabs/PHP_CodeSniffer#1284

This adds a new utility method:
* `isShortList()` - to check whether a short array is in actual fact a short list. Returns boolean.

This method has been battle-tested in the past year or so in the PHPCompatibility standard.

This commit also adds two convenience token arrays for working with lists to the `PHPCSUtils\Tokens\Collections` class.

Includes dedicated unit tests.
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 unit tests.

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

Ref: squizlabs/PHP_CodeSniffer 1971
Add unit tests safeguarding that the method handles upstream tokenizer bug 1381 correctly.

Ref: squizlabs/PHP_CodeSniffer 1381
PHPCS < 2.8.0 contained a bug where a square open bracket `[` directly following a closing curly would always be tokenized as `T_OPEN_SQUARE_BRACKET`, presuming this was array dereferencing/assignment on a variable variable.

If the closing curly however belonged to a control structure, this was incorrect and the token should have been changed to `T_OPEN_SHORT_ARRAY`.

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

Includes unit tests.

Ref: squizlabs/PHP_CodeSniffer 1284
@jrfnl jrfnl added this to the 1.0.0 milestone Jan 22, 2020
@jrfnl jrfnl merged commit d8d28a1 into develop Jan 22, 2020
@jrfnl jrfnl deleted the feature/new-lists-class branch January 22, 2020 23:37
@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