Skip to content

Commit 457183f

Browse files
authored
Allow $this within closures (#20)
* Update tests to allow this inside closures * Allow `$this` within closures
1 parent 43713f0 commit 457183f

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,10 @@ protected function checkForThisWithinClass(
765765
}
766766

767767
foreach (array_reverse($token['conditions'], true) as $scopePtr => $scopeCode) {
768-
// $this within a closure is invalid
768+
// $this within a closure is valid
769769
// Note: have to fetch code from $tokens, T_CLOSURE isn't set for conditions codes.
770770
if ($tokens[$scopePtr]['code'] === T_CLOSURE) {
771-
return false;
771+
return true;
772772
}
773773
if ($scopeCode === T_CLASS) {
774774
return true;

VariableAnalysis/Tests/CodeAnalysis/VariableAnalysisTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,6 @@ public function testFunctionWithClosureWarnings() {
194194
26,
195195
27,
196196
28,
197-
36,
198-
37,
199197
35,
200198
];
201199
$this->assertEquals($expectedWarnings, $lines);

0 commit comments

Comments
 (0)