@@ -118,7 +118,7 @@ class VariableAnalysisSniff implements Sniff {
118
118
* @return (int|string)[]
119
119
*/
120
120
public function register () {
121
- return [
121
+ $ types = [
122
122
T_VARIABLE ,
123
123
T_DOUBLE_QUOTED_STRING ,
124
124
T_HEREDOC ,
@@ -129,8 +129,11 @@ public function register() {
129
129
T_COMMA ,
130
130
T_SEMICOLON ,
131
131
T_CLOSE_PARENTHESIS ,
132
- T_FN , // TODO: we can't use this before php 7.4 so we need to replace it somehow
133
132
];
133
+ if (defined ('T_FN ' )) {
134
+ $ types [] = T_FN ;
135
+ }
136
+ return $ types ;
134
137
}
135
138
136
139
/**
@@ -165,8 +168,10 @@ public function process(File $phpcsFile, $stackPtr) {
165
168
$ scopeStartTokenTypes = [
166
169
T_FUNCTION ,
167
170
T_CLOSURE ,
168
- T_FN , // TODO: we cannot use this before PHP 7.4
169
171
];
172
+ if (defined ('T_FN ' )) {
173
+ $ scopeStartTokenTypes [] = T_FN ;
174
+ }
170
175
171
176
$ scopeIndexThisCloses = array_reduce ($ this ->scopeStartIndices , function ($ found , $ index ) use ($ stackPtr , $ tokens ) {
172
177
if ($ stackPtr === $ tokens [$ index ]['scope_closer ' ]) {
@@ -279,7 +284,6 @@ protected function getVariableInfo($varName, $currScope) {
279
284
* @return VariableInfo
280
285
*/
281
286
protected function getOrCreateVariableInfo ($ varName , $ currScope ) {
282
- // TODO: this needs to find the scope of an arrow function if we are inside one, which must also include the scope of its parent!
283
287
$ scopeInfo = $ this ->getOrCreateScopeInfo ($ currScope );
284
288
if (!isset ($ scopeInfo ->variables [$ varName ])) {
285
289
Helpers::debug ("creating a new variable for ' {$ varName }' in scope " , $ scopeInfo );
@@ -460,7 +464,6 @@ protected function isVariableUndefined($varName, $stackPtr, $currScope) {
460
464
if (isset ($ varInfo ->firstInitialized ) && $ varInfo ->firstInitialized <= $ stackPtr ) {
461
465
return false ;
462
466
}
463
- // TODO: if the variable is in an arrow function body, also check the enclosing scope
464
467
return true ;
465
468
}
466
469
0 commit comments