diff --git a/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php b/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php index 50705db5..57ca0b08 100644 --- a/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php +++ b/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php @@ -765,10 +765,10 @@ protected function checkForThisWithinClass( } foreach (array_reverse($token['conditions'], true) as $scopePtr => $scopeCode) { - // $this within a closure is invalid + // $this within a closure is valid // Note: have to fetch code from $tokens, T_CLOSURE isn't set for conditions codes. if ($tokens[$scopePtr]['code'] === T_CLOSURE) { - return false; + return true; } if ($scopeCode === T_CLASS) { return true; diff --git a/VariableAnalysis/Tests/CodeAnalysis/VariableAnalysisTest.php b/VariableAnalysis/Tests/CodeAnalysis/VariableAnalysisTest.php index c01f2850..5bea562d 100644 --- a/VariableAnalysis/Tests/CodeAnalysis/VariableAnalysisTest.php +++ b/VariableAnalysis/Tests/CodeAnalysis/VariableAnalysisTest.php @@ -194,8 +194,6 @@ public function testFunctionWithClosureWarnings() { 26, 27, 28, - 36, - 37, 35, ]; $this->assertEquals($expectedWarnings, $lines);