@@ -57,9 +57,7 @@ public function process(File $phpcsFile, $stackPtr)
57
57
T_CONSTANT_ENCAPSED_STRING ,
58
58
];
59
59
60
- if ($ previousIndex === false
61
- || in_array ($ tokens [$ previousIndex ]['code ' ], $ relevantTokens , true ) === false
62
- ) {
60
+ if (in_array ($ tokens [$ previousIndex ]['code ' ], $ relevantTokens , true ) === false ) {
63
61
return ;
64
62
}
65
63
@@ -71,9 +69,6 @@ public function process(File $phpcsFile, $stackPtr)
71
69
}
72
70
73
71
$ prevIndex = $ phpcsFile ->findPrevious (Tokens::$ emptyTokens , ($ previousIndex - 1 ), null , true );
74
- if ($ prevIndex === false ) {
75
- return ;
76
- }
77
72
78
73
if (in_array ($ tokens [$ prevIndex ]['code ' ], Tokens::$ arithmeticTokens , true ) === true ) {
79
74
return ;
@@ -85,16 +80,15 @@ public function process(File $phpcsFile, $stackPtr)
85
80
86
81
// Is it a parenthesis.
87
82
if ($ tokens [$ previousIndex ]['code ' ] === T_CLOSE_PARENTHESIS ) {
88
- // Check what exists inside the parenthesis.
89
- $ closeParenthesisIndex = $ phpcsFile ->findPrevious (
83
+ $ beforeOpeningParenthesisIndex = $ phpcsFile ->findPrevious (
90
84
Tokens::$ emptyTokens ,
91
85
($ tokens [$ previousIndex ]['parenthesis_opener ' ] - 1 ),
92
86
null ,
93
87
true
94
88
);
95
89
96
- if ($ closeParenthesisIndex === false || $ tokens [$ closeParenthesisIndex ]['code ' ] !== T_ARRAY ) {
97
- if ($ tokens [$ closeParenthesisIndex ]['code ' ] === T_STRING ) {
90
+ if ($ beforeOpeningParenthesisIndex === false || $ tokens [$ beforeOpeningParenthesisIndex ]['code ' ] !== T_ARRAY ) {
91
+ if ($ tokens [$ beforeOpeningParenthesisIndex ]['code ' ] === T_STRING ) {
98
92
return ;
99
93
}
100
94
@@ -110,14 +104,14 @@ public function process(File $phpcsFile, $stackPtr)
110
104
return ;
111
105
}
112
106
113
- // If there is nothing inside the parenthesis, it it not a Yoda.
107
+ // If there is nothing inside the parenthesis, it is not a Yoda condition .
114
108
$ opener = $ tokens [$ previousIndex ]['parenthesis_opener ' ];
115
109
$ prev = $ phpcsFile ->findPrevious (Tokens::$ emptyTokens , ($ previousIndex - 1 ), ($ opener + 1 ), true );
116
110
if ($ prev === false ) {
117
111
return ;
118
112
}
119
- } else if ($ tokens [$ closeParenthesisIndex ]['code ' ] === T_ARRAY
120
- && $ this ->isArrayStatic ($ phpcsFile , $ closeParenthesisIndex ) === false
113
+ } else if ($ tokens [$ beforeOpeningParenthesisIndex ]['code ' ] === T_ARRAY
114
+ && $ this ->isArrayStatic ($ phpcsFile , $ beforeOpeningParenthesisIndex ) === false
121
115
) {
122
116
return ;
123
117
}//end if
@@ -144,14 +138,14 @@ public function isArrayStatic(File $phpcsFile, $arrayToken)
144
138
{
145
139
$ tokens = $ phpcsFile ->getTokens ();
146
140
147
- $ arrayEnd = null ;
148
141
if ($ tokens [$ arrayToken ]['code ' ] === T_OPEN_SHORT_ARRAY ) {
149
142
$ start = $ arrayToken ;
150
143
$ end = $ tokens [$ arrayToken ]['bracket_closer ' ];
151
144
} else if ($ tokens [$ arrayToken ]['code ' ] === T_ARRAY ) {
152
145
$ start = $ tokens [$ arrayToken ]['parenthesis_opener ' ];
153
146
$ end = $ tokens [$ arrayToken ]['parenthesis_closer ' ];
154
147
} else {
148
+ // Shouldn't be possible but may happen if external sniffs are using this method.
155
149
return true ;
156
150
}
157
151
0 commit comments