Skip to content

Commit 458d665

Browse files
committed
Fix properties detection in some sniffs
1 parent c628974 commit 458d665

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

SlevomatCodingStandard/Sniffs/Classes/ClassMemberSpacingSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private function findNextMember(File $phpcsFile, int $classPointer, int $previou
175175
continue;
176176
}
177177

178-
$propertyPointer = TokenHelper::findNext($phpcsFile, [T_VARIABLE, T_FUNCTION, T_CONST, T_ENUM_CASE], $memberPointer + 1);
178+
$propertyPointer = TokenHelper::findNext($phpcsFile, [T_VARIABLE, T_FUNCTION, T_CONST], $memberPointer + 1);
179179
if (
180180
$propertyPointer === null
181181
|| $tokens[$propertyPointer]['code'] !== T_VARIABLE

SlevomatCodingStandard/Sniffs/Classes/DisallowMultiPropertyDefinitionSniff.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
use function trim;
1616
use const T_ARRAY;
1717
use const T_AS;
18+
use const T_CLASS;
1819
use const T_COMMA;
20+
use const T_CONST;
1921
use const T_FUNCTION;
2022
use const T_OPEN_SHORT_ARRAY;
2123
use const T_SEMICOLON;
@@ -53,7 +55,8 @@ public function process(File $phpcsFile, $modifierPointer): void
5355
return;
5456
}
5557

56-
$propertyPointer = TokenHelper::findNext($phpcsFile, [T_VARIABLE, T_FUNCTION], $modifierPointer + 1);
58+
// Ignore other class members with same mofidiers
59+
$propertyPointer = TokenHelper::findNext($phpcsFile, [T_VARIABLE, T_CONST, T_FUNCTION, T_CLASS], $modifierPointer + 1);
5760
if (
5861
$propertyPointer === null
5962
|| $tokens[$propertyPointer]['code'] !== T_VARIABLE

SlevomatCodingStandard/Sniffs/Classes/ForbiddenPublicPropertySniff.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use function array_map;
1212
use function in_array;
1313
use const T_AS;
14+
use const T_CLASS;
15+
use const T_CONST;
1416
use const T_FUNCTION;
1517
use const T_PRIVATE;
1618
use const T_PRIVATE_SET;
@@ -57,7 +59,8 @@ public function process(File $phpcsFile, $pointer): void
5759
return;
5860
}
5961

60-
$propertyPointer = TokenHelper::findNext($phpcsFile, [T_VARIABLE, T_FUNCTION], $pointer + 1);
62+
// Ignore other class members with same mofidiers
63+
$propertyPointer = TokenHelper::findNext($phpcsFile, [T_VARIABLE, T_CONST, T_FUNCTION, T_CLASS], $pointer + 1);
6164
if (
6265
$propertyPointer === null
6366
|| $tokens[$propertyPointer]['code'] !== T_VARIABLE

SlevomatCodingStandard/Sniffs/Classes/PropertyDeclarationSniff.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use function strtolower;
2424
use const T_ABSTRACT;
2525
use const T_AS;
26+
use const T_CLASS;
2627
use const T_CONST;
2728
use const T_DOUBLE_COLON;
2829
use const T_FINAL;
@@ -117,7 +118,8 @@ public function process(File $phpcsFile, $modifierPointer): void
117118
}
118119
}
119120

120-
$propertyPointer = TokenHelper::findNext($phpcsFile, [T_FUNCTION, T_CONST, T_VARIABLE], $modifierPointer + 1);
121+
// Ignore other class members with same mofidiers
122+
$propertyPointer = TokenHelper::findNext($phpcsFile, [T_CLASS, T_FUNCTION, T_CONST, T_VARIABLE], $modifierPointer + 1);
121123

122124
if ($propertyPointer === null || $tokens[$propertyPointer]['code'] !== T_VARIABLE) {
123125
return;

SlevomatCodingStandard/Sniffs/Classes/PropertySpacingSniff.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
use function in_array;
99
use function sprintf;
1010
use const T_AS;
11+
use const T_CLASS;
1112
use const T_CONST;
1213
use const T_FUNCTION;
13-
use const T_USE;
1414
use const T_VARIABLE;
1515

1616
class PropertySpacingSniff extends AbstractPropertyConstantAndEnumCaseSpacing
@@ -45,7 +45,8 @@ public function process(File $phpcsFile, $pointer): int
4545
return $nextPointer;
4646
}
4747

48-
$propertyPointer = TokenHelper::findNext($phpcsFile, [T_VARIABLE, T_FUNCTION, T_CONST, T_USE], $pointer + 1);
48+
// Ignore other class members with same mofidiers
49+
$propertyPointer = TokenHelper::findNext($phpcsFile, [T_VARIABLE, T_FUNCTION, T_CONST, T_CLASS], $pointer + 1);
4950
if (
5051
$propertyPointer === null
5152
|| $tokens[$propertyPointer]['code'] !== T_VARIABLE

0 commit comments

Comments
 (0)