8000 Fix false positive with anon class variables (#174) · djoos/Symfony-coding-standard@369b5f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 369b5f2

Browse files
mmolldjoos
authored andcommitted
Fix false positive with anon class variables (#174)
1 parent 245812d commit 369b5f2

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Symfony/Sniffs/Classes/PropertyDeclarationSniff.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ public function process(File $phpcsFile, $stackPtr)
9797
$end
9898
);
9999

100-
if ($scope && $tokens[$scope + 2]['code'] === T_VARIABLE) {
100+
if ($scope && $tokens[$scope + 2]['code'] === T_VARIABLE
101+
&& $tokens[$scope]['code'] !== T_ANON_CLASS
102+
) {
101103
$phpcsFile->addError(
102104
'Declare class properties before methods',
103105
$scope,

Symfony/Tests/Classes/PropertyDeclarationUnitTest.inc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,37 @@ class Factory
2626
};
2727
}
2828
}
29+
class Bar
30+
{
31+
public function doStuff()
32+
{
33+
$var1 = 'foo';
34+
$var2 = 'bar';
35+
36+
$anonClass = new class($var1, $var2)
37+
{
38+
private $property;
39+
40+
public function thisIsAfterTheProperty()
41+
{
42+
}
43+
};
44+
}
45+
}
46+
class MoreBar
47+
{
48+
public function doStuff()
49+
{
50+
$var1 = 'foo';
51+
$var2 = 'bar';
52+
53+
$anonClass = new class($var1, $var2)
54+
{
55+
public function thisShouldBeAfterTheProperty()
56+
{
57+
}
58+
59+
private $property;
60+
};
61+
}
62+
}

Symfony/Tests/Classes/PropertyDeclarationUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function getErrorList()
4545
return array(
4646
9 => 1,
4747
17 => 1,
48+
59 => 1,
4849
);
4950
}
5051

0 commit comments

Comments
 (0)
0