Skip to content

Commit 5812672

Browse files
committed
Fixed bug #1776 : Squiz.Scope.StaticThisUsage incorrectly looking inside anon classes
1 parent 5f4c9cc commit 5812672

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
140140
- Fixed bug #1762 : Generic.WhiteSpace.Disallow[Space/Tab]Indent not inspecting content before open tag
141141
-- Thanks to Juliette Reinders Folmer for the patch
142142
- Fixed bug #1769 : Custom "define" function triggers a warning about declaring new symbols
143+
- Fixed bug #1776 : Squiz.Scope.StaticThisUsage incorrectly looking inside anon classes
143144
</notes>
144145
<contents>
145146
<dir name="/">

src/Standards/Squiz/Sniffs/Scope/StaticThisUsageSniff.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ public function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
6161
$end = $tokens[$stackPtr]['scope_closer'];
6262

6363
do {
64-
$next = $phpcsFile->findNext([T_VARIABLE, T_CLOSURE], ($next + 1), $end);
64+
$next = $phpcsFile->findNext([T_VARIABLE, T_CLOSURE, T_ANON_CLASS], ($next + 1), $end);
6565
if ($next === false) {
6666
continue;
67-
} else if ($tokens[$next]['code'] === T_CLOSURE) {
67+
} else if ($tokens[$next]['code'] === T_CLOSURE
68+
|| $tokens[$next]['code'] === T_ANON_CLASS
69+
) {
6870
$next = $tokens[$next]['scope_closer'];
6971
continue;
7072
} else if (strtolower($tokens[$next]['content']) !== '$this') {

src/Standards/Squiz/Tests/Scope/StaticThisUsageUnitTest.inc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,17 @@ class MyClass
4141
echo $this->name;
4242
};
4343
}
44+
45+
private static function func1(array $data)
46+
{
47+
return new class()
48+
{
49+
private $data;
50+
51+
public function __construct(array $data)
52+
{
53+
$this->data = $data;
54+
}
55+
};
56+
}
4457
}
45-
?>

0 commit comments

Comments
 (0)