1919class ArbitraryParenthesesSpacingSniff implements Sniff
2020{
2121
22+ /**
23+ * Tokens which when they precede an open parenthesis indicate
24+ * that this is a type of structure this sniff should ignore.
25+ *
26+ * @var array<int|string, int|string>
27+ */
28+ private const IGNORE_TOKENS = (Tokens::FUNCTION_NAME_TOKENS + [
29+ T_VARIABLE => T_VARIABLE ,
30+ T_CLOSE_PARENTHESIS => T_CLOSE_PARENTHESIS ,
31+ T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET ,
32+ T_CLOSE_SQUARE_BRACKET => T_CLOSE_SQUARE_BRACKET ,
33+ T_CLOSE_SHORT_ARRAY => T_CLOSE_SHORT_ARRAY ,
34+ T_THROW => T_THROW ,
35+ T_YIELD => T_YIELD ,
36+ T_YIELD_FROM => T_YIELD_FROM ,
37+ T_CLONE => T_CLONE ,
38+ ]);
39+
2240 /**
2341 * The number of spaces desired on the inside of the parentheses.
2442 *
@@ -33,14 +51,6 @@ class ArbitraryParenthesesSpacingSniff implements Sniff
3351 */
3452 public $ ignoreNewlines = false ;
3553
36- /**
37- * Tokens which when they precede an open parenthesis indicate
38- * that this is a type of structure this sniff should ignore.
39- *
40- * @var array
41- */
42- private $ ignoreTokens = [];
43-
4454
4555 /**
4656 * Returns an array of tokens this test wants to listen for.
@@ -49,19 +59,6 @@ class ArbitraryParenthesesSpacingSniff implements Sniff
4959 */
5060 public function register ()
5161 {
52- $ this ->ignoreTokens = Tokens::FUNCTION_NAME_TOKENS ;
53-
54- $ this ->ignoreTokens [T_VARIABLE ] = T_VARIABLE ;
55- $ this ->ignoreTokens [T_CLOSE_PARENTHESIS ] = T_CLOSE_PARENTHESIS ;
56- $ this ->ignoreTokens [T_CLOSE_CURLY_BRACKET ] = T_CLOSE_CURLY_BRACKET ;
57- $ this ->ignoreTokens [T_CLOSE_SQUARE_BRACKET ] = T_CLOSE_SQUARE_BRACKET ;
58- $ this ->ignoreTokens [T_CLOSE_SHORT_ARRAY ] = T_CLOSE_SHORT_ARRAY ;
59-
60- $ this ->ignoreTokens [T_THROW ] = T_THROW ;
61- $ this ->ignoreTokens [T_YIELD ] = T_YIELD ;
62- $ this ->ignoreTokens [T_YIELD_FROM ] = T_YIELD_FROM ;
63- $ this ->ignoreTokens [T_CLONE ] = T_CLONE ;
64-
6562 return [
6663 T_OPEN_PARENTHESIS ,
6764 T_CLOSE_PARENTHESIS ,
@@ -101,7 +98,7 @@ public function process(File $phpcsFile, $stackPtr)
10198
10299 $ preOpener = $ phpcsFile ->findPrevious (Tokens::EMPTY_TOKENS , ($ opener - 1 ), null , true );
103100 if ($ preOpener !== false
104- && isset ($ this -> ignoreTokens [$ tokens [$ preOpener ]['code ' ]]) === true
101+ && isset (self :: IGNORE_TOKENS [$ tokens [$ preOpener ]['code ' ]]) === true
105102 && ($ tokens [$ preOpener ]['code ' ] !== T_CLOSE_CURLY_BRACKET
106103 || isset ($ tokens [$ preOpener ]['scope_condition ' ]) === false )
107104 ) {
0 commit comments