Skip to content

Commit

Permalink
Merge pull request #405 from PHPCSStandards/feature/collections-add-l…
Browse files Browse the repository at this point in the history
…istopentokens

Collections: add new `listOpenTokensBC()` method
  • Loading branch information
jrfnl committed Dec 18, 2022
2 parents 3d9a543 + c46701b commit 6e2cb6e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
25 changes: 24 additions & 1 deletion PHPCSUtils/Tokens/Collections.php
Expand Up @@ -38,6 +38,7 @@
* @method static array functionDeclarationTokens() Tokens which represent a keyword which starts
* a function declaration.
* @method static array incrementDecrementOperators() Increment/decrement operator tokens.
* @method static array listOpenTokensBC() Tokens which can open a list (PHPCS cross-version compatible).
* @method static array listTokens() Tokens which are used to create lists.
* @method static array listTokensBC() Tokens which are used to create lists
* (PHPCS cross-version compatible)
Expand Down Expand Up @@ -217,7 +218,7 @@ final class Collections
* - PHP 7.1 added class constants visibility support.
* - PHP 8.1 added support for final class constants.
*
* @since 1.0.0-alpha4 Use the {@see Collections::constantModifierKeywords()} method for access.
* @since 1.0.0-rc1 Use the {@see Collections::constantModifierKeywords()} method for access.
*
* @var array <int|string> => <int|string>
*/
Expand Down Expand Up @@ -278,6 +279,28 @@ final class Collections
\T_INC => \T_INC,
];

/**
* Tokens which can open a list construct (PHPCS cross-version compatible).
*
* Includes `T_OPEN_SQUARE_BRACKET` to allow for handling intermittent tokenizer issues related
* to the retokenization to `T_OPEN_SHORT_ARRAY`.
* Should only be used selectively.
*
* @see \PHPCSUtils\Tokens\Collections::listTokensBC() Related method to retrieve tokens used
* for lists (PHPCS cross-version).
* @see \PHPCSUtils\Tokens\Collections::shortListTokensBC() Related method to retrieve only tokens used
* for short lists (PHPCS cross-version).
*
* @since 1.0.0-rc1 Use the {@see Collections::listOpenTokensBC()} method for access.
*
* @return array <int|string> => <int|string>
*/
private static $listOpenTokensBC = [
\T_LIST => \T_LIST,
\T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY,
\T_OPEN_SQUARE_BRACKET => \T_OPEN_SQUARE_BRACKET,
];

/**
* DEPRECATED: Tokens which are used to create lists.
*
Expand Down
1 change: 1 addition & 0 deletions Tests/Tokens/Collections/PropertyBasedTokenArraysTest.php
Expand Up @@ -69,6 +69,7 @@ public function dataPropertyBasedTokenArrays()
'controlStructureTokens',
'functionDeclarationTokens',
'incrementDecrementOperators',
'listOpenTokensBC',
'listTokens',
'listTokensBC',
'namespaceDeclarationClosers',
Expand Down

0 comments on commit 6e2cb6e

Please sign in to comment.