Skip to content

Commit 344d342

Browse files
authored
Merge pull request #444 from PHPCSStandards/feature/update-after-release-phpcs-3.7.2
Update after release of PHPCS 3.7.2
2 parents 343c01e + ec0c098 commit 344d342

23 files changed

+656
-153
lines changed

PHPCSUtils/Internal/IsShortArrayOrList.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPCSUtils\BackCompat\Helper;
1717
use PHPCSUtils\Internal\Cache;
1818
use PHPCSUtils\Internal\IsShortArrayOrListWithCache;
19+
use PHPCSUtils\Internal\StableCollections;
1920
use PHPCSUtils\Tokens\Collections;
2021
use PHPCSUtils\Utils\Arrays;
2122
use PHPCSUtils\Utils\Context;
@@ -187,7 +188,7 @@ final class IsShortArrayOrList
187188
public function __construct(File $phpcsFile, $stackPtr)
188189
{
189190
$tokens = $phpcsFile->getTokens();
190-
$openBrackets = Collections::shortArrayListOpenTokensBC();
191+
$openBrackets = StableCollections::$shortArrayListOpenTokensBC;
191192

192193
if (isset($tokens[$stackPtr]) === false
193194
|| isset($openBrackets[$tokens[$stackPtr]['code']]) === false

PHPCSUtils/Internal/IsShortArrayOrListWithCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use PHP_CodeSniffer\Files\File;
1414
use PHPCSUtils\Internal\Cache;
1515
use PHPCSUtils\Internal\IsShortArrayOrList;
16-
use PHPCSUtils\Tokens\Collections;
16+
use PHPCSUtils\Internal\StableCollections;
1717

1818
/**
1919
* Determination of short array vs short list vs square brackets.
@@ -215,7 +215,7 @@ private function process()
215215
private function isValidStackPtr()
216216
{
217217
return (isset($this->tokens[$this->stackPtr]) === true
218-
&& isset(Collections::shortArrayTokensBC()[$this->tokens[$this->stackPtr]['code']]) === true);
218+
&& isset(StableCollections::$shortArrayListTokensBC[$this->tokens[$this->stackPtr]['code']]) === true);
219219
}
220220

221221
/**
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers.
4+
*
5+
* @package PHPCSUtils
6+
* @copyright 2019-2020 PHPCSUtils Contributors
7+
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
8+
* @link https://github.com/PHPCSStandards/PHPCSUtils
9+
*/
10+
11+
namespace PHPCSUtils\Internal;
12+
13+
/**
14+
* Stable collections of related tokens.
15+
*
16+
* The {@see \PHPCSUtils\Tokens\Collections} class contains a range of token collections for use by sniffs,
17+
* some of which may change depending on the availability of a token in PHP/PHPCS.
18+
* The contents of token collections may also vary based on the PHPCS version to allow for optimized sniffing.
19+
*
20+
* The functionality _within_ PHPCSUtils, however, should be stable and reliably testable, so for internal
21+
* use, the most volatile token arrays are replicated here in stable versions to be used by the PHPCSUtils
22+
* functions (and tests) internally.
23+
*
24+
* ---------------------------------------------------------------------------------------------
25+
* This class is only intended for internal use by PHPCSUtils and is not part of the public API.
26+
* This also means that it has no promise of backward compatibility.
27+
*
28+
* End-users should use the methods in the {@see \PHPCSUtils\Tokens\Collections} class instead.
29+
* ---------------------------------------------------------------------------------------------
30+
*
31+
* @internal
32+
*
33+
* @since 1.0.0
34+
*/
35+
final class StableCollections
36+
{
37+
38+
/**
39+
* Tokens which can open a short array or short list (PHPCS cross-version compatible).
40+
*
41+
* This array will ALWAYS include the `T_OPEN_SQUARE_BRACKET` token to allow for handling
42+
* intermittent tokenizer issues related to the retokenization to `T_OPEN_SHORT_ARRAY`.
43+
*
44+
* @internal
45+
* @ignore This array is only for internal use by PHPCSUtils and is not part of the public API.
46+
*
47+
* @since 1.0.2
48+
*
49+
* @var array <int|string> => <int|string>
50+
*/
51+
public static $shortArrayListOpenTokensBC = [
52+
\T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY,
53+
\T_OPEN_SQUARE_BRACKET => \T_OPEN_SQUARE_BRACKET,
54+
];
55+
56+
/**
57+
* Tokens which are used for short lists.
58+
*
59+
* This array will ALWAYS include the `T_OPEN_SQUARE_BRACKET` and `T_CLOSE_SQUARE_BRACKET` tokens
60+
* to allow for handling intermittent tokenizer issues related to the retokenization to `T_OPEN_SHORT_ARRAY`.
61+
*
62+
* @internal
63+
* @ignore This array is only for internal use by PHPCSUtils and is not part of the public API.
64+
*
65+
* @since 1.0.2
66+
*
67+
* @var array <int|string> => <int|string>
68+
*/
69+
public static $shortArrayListTokensBC = [
70+
\T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY,
71+
\T_CLOSE_SHORT_ARRAY => \T_CLOSE_SHORT_ARRAY,
72+
\T_OPEN_SQUARE_BRACKET => \T_OPEN_SQUARE_BRACKET,
73+
\T_CLOSE_SQUARE_BRACKET => \T_CLOSE_SQUARE_BRACKET,
74+
];
75+
}

0 commit comments

Comments
 (0)