19
19
class ArbitraryParenthesesSpacingSniff implements Sniff
20
20
{
21
21
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
+
22
40
/**
23
41
* The number of spaces desired on the inside of the parentheses.
24
42
*
@@ -33,14 +51,6 @@ class ArbitraryParenthesesSpacingSniff implements Sniff
33
51
*/
34
52
public $ ignoreNewlines = false ;
35
53
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
-
44
54
45
55
/**
46
56
* Returns an array of tokens this test wants to listen for.
@@ -49,19 +59,6 @@ class ArbitraryParenthesesSpacingSniff implements Sniff
49
59
*/
50
60
public function register ()
51
61
{
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
-
65
62
return [
66
63
T_OPEN_PARENTHESIS ,
67
64
T_CLOSE_PARENTHESIS ,
@@ -101,7 +98,7 @@ public function process(File $phpcsFile, $stackPtr)
101
98
102
99
$ preOpener = $ phpcsFile ->findPrevious (Tokens::EMPTY_TOKENS , ($ opener - 1 ), null , true );
103
100
if ($ preOpener !== false
104
- && isset ($ this -> ignoreTokens [$ tokens [$ preOpener ]['code ' ]]) === true
101
+ && isset (self :: IGNORE_TOKENS [$ tokens [$ preOpener ]['code ' ]]) === true
105
102
&& ($ tokens [$ preOpener ]['code ' ] !== T_CLOSE_CURLY_BRACKET
106
103
|| isset ($ tokens [$ preOpener ]['scope_condition ' ]) === false )
107
104
) {
0 commit comments