Skip to content

Commit

Permalink
Allow $this within closures (#20)
Browse files Browse the repository at this point in the history
* Update tests to allow this inside closures

* Allow `$this` within closures
  • Loading branch information
sirbrillig authored Dec 19, 2017
1 parent 43713f0 commit 457183f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions VariableAnalysis/Tests/CodeAnalysis/VariableAnalysisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ public function testFunctionWithClosureWarnings() {
26,
27,
28,
36,
37,
35,
];
$this->assertEquals($expectedWarnings, $lines);
Expand Down

0 comments on commit 457183f

Please sign in to comment.