Skip to content

Commit 0e706a1

Browse files
committed
Cleanup
1 parent b224198 commit 0e706a1

File tree

7 files changed

+18
-26
lines changed

7 files changed

+18
-26
lines changed

SlevomatCodingStandard/Helpers/ConditionHelper.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
use const T_LOGICAL_OR;
3333
use const T_LOGICAL_XOR;
3434
use const T_OPEN_PARENTHESIS;
35-
use const T_PARENT;
36-
use const T_SELF;
37-
use const T_STATIC;
3835
use const T_STRING;
3936
use const T_VARIABLE;
4037

@@ -211,7 +208,7 @@ private static function getNegativeConditionPart(
211208
}
212209
}
213210

214-
if (in_array($tokens[$pointerAfterConditionStart]['code'], [T_VARIABLE, T_SELF, T_STATIC, T_PARENT], true)) {
211+
if (in_array($tokens[$pointerAfterConditionStart]['code'], [T_VARIABLE, ...TokenHelper::CLASS_KEYWORD_CODES], true)) {
215212
$identificatorEndPointer = IdentificatorHelper::findEndPointer($phpcsFile, $pointerAfterConditionStart);
216213
$pointerAfterIdentificatorEnd = TokenHelper::findNextEffective($phpcsFile, $identificatorEndPointer + 1);
217214
if (

SlevomatCodingStandard/Helpers/IdentificatorHelper.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
use const T_OBJECT_OPERATOR;
1515
use const T_OPEN_CURLY_BRACKET;
1616
use const T_OPEN_SQUARE_BRACKET;
17-
use const T_PARENT;
18-
use const T_SELF;
19-
use const T_STATIC;
2017
use const T_VARIABLE;
2118

2219
/**
@@ -83,7 +80,7 @@ public static function findEndPointer(File $phpcsFile, int $startPointer): ?int
8380
$nextPointer = TokenHelper::findNextEffective($phpcsFile, $startPointer + 1);
8481

8582
if (
86-
in_array($tokens[$startPointer]['code'], [T_SELF, T_STATIC, T_PARENT, ...TokenHelper::NAME_TOKEN_CODES], true)
83+
in_array($tokens[$startPointer]['code'], [...TokenHelper::CLASS_KEYWORD_CODES, ...TokenHelper::NAME_TOKEN_CODES], true)
8784
&& $tokens[$nextPointer]['code'] === T_DOUBLE_COLON
8885
) {
8986
return self::getEndPointerAfterOperator($phpcsFile, $nextPointer);
@@ -117,7 +114,7 @@ private static function getStartPointerBeforeOperator(File $phpcsFile, int $oper
117114

118115
if (
119116
$tokens[$operatorPointer]['code'] === T_DOUBLE_COLON
120-
&& in_array($tokens[$previousPointer]['code'], [T_SELF, T_STATIC, T_PARENT, ...TokenHelper::NAME_TOKEN_CODES], true)
117+
&& in_array($tokens[$previousPointer]['code'], [...TokenHelper::CLASS_KEYWORD_CODES, ...TokenHelper::NAME_TOKEN_CODES], true)
121118
) {
122119
return $previousPointer;
123120
}

SlevomatCodingStandard/Helpers/TokenHelper.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ class TokenHelper
7373
T_NAME_RELATIVE,
7474
];
7575

76+
public const CLASS_KEYWORD_CODES = [
77+
T_PARENT,
78+
T_SELF,
79+
T_STATIC,
80+
];
81+
7682
public const ONLY_TYPE_HINT_TOKEN_CODES = [
7783
...self::NAME_TOKEN_CODES,
7884
T_SELF,

SlevomatCodingStandard/Sniffs/Functions/AbstractLineCall.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
use const T_COMMA;
1212
use const T_FUNCTION;
1313
use const T_OPEN_PARENTHESIS;
14-
use const T_PARENT;
15-
use const T_SELF;
16-
use const T_STATIC;
1714
use const T_WHITESPACE;
1815

1916
abstract class AbstractLineCall implements Sniff
@@ -24,7 +21,7 @@ abstract class AbstractLineCall implements Sniff
2421
*/
2522
public function register(): array
2623
{
27-
return [...TokenHelper::NAME_TOKEN_CODES, T_SELF, T_STATIC, T_PARENT];
24+
return [...TokenHelper::NAME_TOKEN_CODES, ...TokenHelper::CLASS_KEYWORD_CODES];
2825
}
2926

3027
protected function isCall(File $phpcsFile, int $stringPointer): bool

SlevomatCodingStandard/Sniffs/Functions/DisallowTrailingCommaInCallSniff.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
use const T_COMMA;
1212
use const T_ISSET;
1313
use const T_OPEN_PARENTHESIS;
14-
use const T_PARENT;
15-
use const T_SELF;
16-
use const T_STATIC;
1714
use const T_STRING;
1815
use const T_UNSET;
1916
use const T_VARIABLE;
@@ -42,7 +39,7 @@ public function process(File $phpcsFile, int $parenthesisOpenerPointer): void
4239
$pointerBeforeParenthesisOpener = TokenHelper::findPreviousEffective($phpcsFile, $parenthesisOpenerPointer - 1);
4340
if (!in_array(
4441
$tokens[$pointerBeforeParenthesisOpener]['code'],
45-
[...TokenHelper::NAME_TOKEN_CODES, T_STRING, T_VARIABLE, T_ISSET, T_UNSET, T_CLOSE_PARENTHESIS, T_SELF, T_STATIC, T_PARENT],
42+
[...TokenHelper::NAME_TOKEN_CODES, T_STRING, T_VARIABLE, T_ISSET, T_UNSET, T_CLOSE_PARENTHESIS, ...TokenHelper::CLASS_KEYWORD_CODES],
4643
true,
4744
)) {
4845
return;

SlevomatCodingStandard/Sniffs/Functions/RequireTrailingCommaInCallSniff.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
use const T_COMMA;
1313
use const T_ISSET;
1414
use const T_OPEN_PARENTHESIS;
15-
use const T_PARENT;
16-
use const T_SELF;
17-
use const T_STATIC;
1815
use const T_STRING;
1916
use const T_UNSET;
2017
use const T_VARIABLE;
@@ -50,7 +47,7 @@ public function process(File $phpcsFile, int $parenthesisOpenerPointer): void
5047

5148
if (!in_array(
5249
$tokens[$pointerBeforeParenthesisOpener]['code'],
53-
[...TokenHelper::NAME_TOKEN_CODES, T_STRING, T_VARIABLE, T_ISSET, T_UNSET, T_CLOSE_PARENTHESIS, T_SELF, T_STATIC, T_PARENT],
50+
[...TokenHelper::NAME_TOKEN_CODES, T_STRING, T_VARIABLE, T_ISSET, T_UNSET, T_CLOSE_PARENTHESIS, ...TokenHelper::CLASS_KEYWORD_CODES],
5451
true,
5552
)) {
5653
return;

SlevomatCodingStandard/Sniffs/PHP/ForbiddenClassesSniff.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
use const T_IMPLEMENTS;
2222
use const T_NEW;
2323
use const T_OPEN_CURLY_BRACKET;
24-
use const T_PARENT;
25-
use const T_SELF;
2624
use const T_SEMICOLON;
27-
use const T_STATIC;
2825
use const T_USE;
2926

3027
class ForbiddenClassesSniff implements Sniff
@@ -221,8 +218,12 @@ private function getAllReferences(File $phpcsFile, int $startPointer, int $endPo
221218
$references = [];
222219

223220
while ($startPointer < $endPointer) {
224-
$referencePointer = TokenHelper::findNext($phpcsFile, [T_SELF, T_STATIC, T_PARENT, ...TokenHelper::NAME_TOKEN_CODES], $startPointer);
225-
if (in_array($tokens[$referencePointer]['code'], [T_SELF, T_STATIC, T_PARENT], true)) {
221+
$referencePointer = TokenHelper::findNext(
222+
$phpcsFile,
223+
[...TokenHelper::CLASS_KEYWORD_CODES, ...TokenHelper::NAME_TOKEN_CODES],
224+
$startPointer,
225+
);
226+
if (in_array($tokens[$referencePointer]['code'], TokenHelper::CLASS_KEYWORD_CODES, true)) {
226227
$startPointer = $referencePointer + 1;
227228
continue;
228229
}

0 commit comments

Comments
 (0)