Skip to content

Commit e254aa2

Browse files
committed
More constants
1 parent 76a8d47 commit e254aa2

File tree

66 files changed

+199
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+199
-242
lines changed

SlevomatCodingStandard/Helpers/ArrayHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static function parse(File $phpcsFile, int $arrayPointer): array
4444
for ($i = $arrayKeyValueStartPointer; $i < $arrayCloserPointer; $i++) {
4545
$token = $tokens[$i];
4646

47-
if (in_array($token['code'], TokenHelper::$arrayTokenCodes, true)) {
47+
if (in_array($token['code'], TokenHelper::ARRAY_TOKEN_CODES, true)) {
4848
$i = self::openClosePointers($token)[1];
4949
continue;
5050
}
@@ -213,7 +213,7 @@ private static function getValueEndPointer(File $phpcsFile, int $endPointer, int
213213

214214
$nextNonWhitespacePointer = TokenHelper::findNextNonWhitespace($phpcsFile, $i);
215215

216-
if (!in_array($tokens[$nextNonWhitespacePointer]['code'], TokenHelper::$inlineCommentTokenCodes, true)) {
216+
if (!in_array($tokens[$nextNonWhitespacePointer]['code'], TokenHelper::INLINE_COMMENT_TOKEN_CODES, true)) {
217217
break;
218218
}
219219

SlevomatCodingStandard/Helpers/ArrayKeyValue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private function addValues(File $phpcsFile): void
116116
for ($i = $this->pointerStart; $i <= $this->pointerEnd; $i++) {
117117
$token = $tokens[$i];
118118

119-
if (in_array($token['code'], TokenHelper::$arrayTokenCodes, true)) {
119+
if (in_array($token['code'], TokenHelper::ARRAY_TOKEN_CODES, true)) {
120120
$i = ArrayHelper::openClosePointers($token)[1];
121121
continue;
122122
}
@@ -149,7 +149,7 @@ private function addValues(File $phpcsFile): void
149149
$firstNonWhitespace = $i;
150150
}
151151

152-
if (in_array($token['code'], TokenHelper::$inlineCommentTokenCodes, true) === false) {
152+
if (in_array($token['code'], TokenHelper::INLINE_COMMENT_TOKEN_CODES, true) === false) {
153153
$key .= $token['content'];
154154
}
155155
}

SlevomatCodingStandard/Helpers/AttributeHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static function getAttributes(File $phpcsFile, int $attributeOpenerPointe
6767

6868
$attributeNameEndPointer = TokenHelper::findNextExcluding(
6969
$phpcsFile,
70-
TokenHelper::getNameTokenCodes(),
70+
TokenHelper::NAME_TOKEN_CODES,
7171
$attributeNameStartPointer + 1,
7272
) - 1;
7373
$attributeName = TokenHelper::getContent($phpcsFile, $attributeNameStartPointer, $attributeNameEndPointer);

SlevomatCodingStandard/Helpers/CatchHelper.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ public static function findCaughtTypesInCatch(File $phpcsFile, array $catchToken
4646
/** @var int $catchParenthesisCloserPointer */
4747
$catchParenthesisCloserPointer = $catchToken['parenthesis_closer'];
4848

49-
$nameTokenCodes = TokenHelper::getNameTokenCodes();
50-
5149
$nameEndPointer = $catchParenthesisOpenerPointer;
5250
$tokens = $phpcsFile->getTokens();
5351
$caughtTypes = [];
5452
do {
5553
$nameStartPointer = TokenHelper::findNext(
5654
$phpcsFile,
57-
array_merge([T_BITWISE_OR], $nameTokenCodes),
55+
array_merge([T_BITWISE_OR], TokenHelper::NAME_TOKEN_CODES),
5856
$nameEndPointer + 1,
5957
$catchParenthesisCloserPointer,
6058
);
@@ -67,7 +65,7 @@ public static function findCaughtTypesInCatch(File $phpcsFile, array $catchToken
6765
$nameStartPointer = TokenHelper::findNextEffective($phpcsFile, $nameStartPointer + 1, $catchParenthesisCloserPointer);
6866
}
6967

70-
$pointerAfterNameEndPointer = TokenHelper::findNextExcluding($phpcsFile, $nameTokenCodes, $nameStartPointer + 1);
68+
$pointerAfterNameEndPointer = TokenHelper::findNextExcluding($phpcsFile, TokenHelper::NAME_TOKEN_CODES, $nameStartPointer + 1);
7169
$nameEndPointer = $pointerAfterNameEndPointer === null ? $nameStartPointer : $pointerAfterNameEndPointer - 1;
7270

7371
$caughtTypes[] = NamespaceHelper::resolveClassName(

SlevomatCodingStandard/Helpers/ClassHelper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ public static function getTraitUsePointers(File $phpcsFile, int $classPointer):
110110
*/
111111
private static function getAllClassPointers(File $phpcsFile): array
112112
{
113-
$lazyValue = static fn (): array => TokenHelper::findNextAll($phpcsFile, TokenHelper::$typeWithAnonymousClassKeywordTokenCodes, 0);
113+
$lazyValue = static fn (): array => TokenHelper::findNextAll(
114+
$phpcsFile,
115+
TokenHelper::CLASS_TYPE_WITH_ANONYMOUS_CLASS_TOKEN_CODES,
116+
0,
117+
);
114118

115119
return SniffLocalCache::getAndSetIfNotCached($phpcsFile, 'classPointers', $lazyValue);
116120
}

SlevomatCodingStandard/Helpers/CommentHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function getMultilineCommentStartPointer(File $phpcsFile, int $com
6363

6464
$commentStartPointer = $commentEndPointer;
6565
do {
66-
$commentBefore = TokenHelper::findPrevious($phpcsFile, TokenHelper::$inlineCommentTokenCodes, $commentStartPointer - 1);
66+
$commentBefore = TokenHelper::findPrevious($phpcsFile, TokenHelper::INLINE_COMMENT_TOKEN_CODES, $commentStartPointer - 1);
6767
if ($commentBefore === null) {
6868
break;
6969
}
@@ -84,7 +84,7 @@ public static function getMultilineCommentEndPointer(File $phpcsFile, int $comme
8484

8585
$commentEndPointer = $commentStartPointer;
8686
do {
87-
$commentAfter = TokenHelper::findNext($phpcsFile, TokenHelper::$inlineCommentTokenCodes, $commentEndPointer + 1);
87+
$commentAfter = TokenHelper::findNext($phpcsFile, TokenHelper::INLINE_COMMENT_TOKEN_CODES, $commentEndPointer + 1);
8888
if ($commentAfter === null) {
8989
break;
9090
}

SlevomatCodingStandard/Helpers/DocCommentHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public static function findDocCommentOwnerPointer(File $phpcsFile, int $docComme
208208

209209
if (in_array(
210210
$tokens[$i]['code'],
211-
array_merge([T_FUNCTION, T_VARIABLE, T_CONST], TokenHelper::$typeKeywordTokenCodes),
211+
array_merge([T_FUNCTION, T_VARIABLE, T_CONST], TokenHelper::CLASS_TYPE_TOKEN_CODES),
212212
true,
213213
)) {
214214
$docCommentOwnerPointer = $i;

SlevomatCodingStandard/Helpers/FunctionHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,11 @@ public static function getParametersTypeHints(File $phpcsFile, int $functionPoin
215215

216216
$pointerBeforeVariable = TokenHelper::findPreviousExcluding(
217217
$phpcsFile,
218-
array_merge(TokenHelper::$ineffectiveTokenCodes, [T_BITWISE_AND, T_ELLIPSIS]),
218+
array_merge(TokenHelper::INEFFECTIVE_TOKEN_CODES, [T_BITWISE_AND, T_ELLIPSIS]),
219219
$i - 1,
220220
);
221221

222-
if (!in_array($tokens[$pointerBeforeVariable]['code'], TokenHelper::getTypeHintTokenCodes(), true)) {
222+
if (!in_array($tokens[$pointerBeforeVariable]['code'], TokenHelper::TYPE_HINT_TOKEN_CODES, true)) {
223223
$parametersTypeHints[$parameterName] = null;
224224
continue;
225225
}

SlevomatCodingStandard/Helpers/IdentificatorHelper.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function getContent(File $phpcsFile, int $startPointer, int $endPo
3232

3333
$variableContent = '';
3434
for ($i = $startPointer; $i <= $endPointer; $i++) {
35-
if (in_array($tokens[$i]['code'], TokenHelper::$ineffectiveTokenCodes, true)) {
35+
if (in_array($tokens[$i]['code'], TokenHelper::INEFFECTIVE_TOKEN_CODES, true)) {
3636
continue;
3737
}
3838

@@ -46,7 +46,7 @@ public static function findStartPointer(File $phpcsFile, int $endPointer): ?int
4646
{
4747
$tokens = $phpcsFile->getTokens();
4848

49-
if (in_array($tokens[$endPointer]['code'], TokenHelper::getNameTokenCodes(), true)) {
49+
if (in_array($tokens[$endPointer]['code'], TokenHelper::NAME_TOKEN_CODES, true)) {
5050
/** @var int $previousPointer */
5151
$previousPointer = TokenHelper::findPreviousEffective($phpcsFile, $endPointer - 1);
5252
if (in_array($tokens[$previousPointer]['code'], [T_OBJECT_OPERATOR, T_NULLSAFE_OBJECT_OPERATOR, T_DOUBLE_COLON], true)) {
@@ -74,10 +74,8 @@ public static function findEndPointer(File $phpcsFile, int $startPointer): ?int
7474
{
7575
$tokens = $phpcsFile->getTokens();
7676

77-
$nameTokenCodes = TokenHelper::getNameTokenCodes();
78-
79-
if (in_array($tokens[$startPointer]['code'], $nameTokenCodes, true)) {
80-
$startPointer = TokenHelper::findNextExcluding($phpcsFile, $nameTokenCodes, $startPointer + 1) - 1;
77+
if (in_array($tokens[$startPointer]['code'], TokenHelper::NAME_TOKEN_CODES, true)) {
78+
$startPointer = TokenHelper::findNextExcluding($phpcsFile, TokenHelper::NAME_TOKEN_CODES, $startPointer + 1) - 1;
8179
} elseif ($tokens[$startPointer]['code'] === T_DOLLAR) {
8280
$startPointer = TokenHelper::findNextEffective($phpcsFile, $startPointer + 1);
8381
}
@@ -86,7 +84,7 @@ public static function findEndPointer(File $phpcsFile, int $startPointer): ?int
8684
$nextPointer = TokenHelper::findNextEffective($phpcsFile, $startPointer + 1);
8785

8886
if (
89-
in_array($tokens[$startPointer]['code'], array_merge([T_SELF, T_STATIC, T_PARENT], $nameTokenCodes), true)
87+
in_array($tokens[$startPointer]['code'], array_merge([T_SELF, T_STATIC, T_PARENT], TokenHelper::NAME_TOKEN_CODES), true)
9088
&& $tokens[$nextPointer]['code'] === T_DOUBLE_COLON
9189
) {
9290
return self::getEndPointerAfterOperator($phpcsFile, $nextPointer);
@@ -111,23 +109,21 @@ private static function getStartPointerBeforeOperator(File $phpcsFile, int $oper
111109
{
112110
$tokens = $phpcsFile->getTokens();
113111

114-
$nameTokenCodes = TokenHelper::getNameTokenCodes();
115-
116112
/** @var int $previousPointer */
117113
$previousPointer = TokenHelper::findPreviousEffective($phpcsFile, $operatorPointer - 1);
118114

119-
if (in_array($tokens[$previousPointer]['code'], $nameTokenCodes, true)) {
120-
$previousPointer = TokenHelper::findPreviousExcluding($phpcsFile, $nameTokenCodes, $previousPointer - 1) + 1;
115+
if (in_array($tokens[$previousPointer]['code'], TokenHelper::NAME_TOKEN_CODES, true)) {
116+
$previousPointer = TokenHelper::findPreviousExcluding($phpcsFile, TokenHelper::NAME_TOKEN_CODES, $previousPointer - 1) + 1;
121117
}
122118

123119
if (
124120
$tokens[$operatorPointer]['code'] === T_DOUBLE_COLON
125-
&& in_array($tokens[$previousPointer]['code'], array_merge([T_SELF, T_STATIC, T_PARENT], $nameTokenCodes), true)
121+
&& in_array($tokens[$previousPointer]['code'], array_merge([T_SELF, T_STATIC, T_PARENT], TokenHelper::NAME_TOKEN_CODES), true)
126122
) {
127123
return $previousPointer;
128124
}
129125

130-
if (in_array($tokens[$previousPointer]['code'], $nameTokenCodes, true)) {
126+
if (in_array($tokens[$previousPointer]['code'], TokenHelper::NAME_TOKEN_CODES, true)) {
131127
/** @var int $possibleOperatorPointer */
132128
$possibleOperatorPointer = TokenHelper::findPreviousEffective($phpcsFile, $previousPointer - 1);
133129
if (in_array($tokens[$possibleOperatorPointer]['code'], [T_OBJECT_OPERATOR, T_NULLSAFE_OBJECT_OPERATOR], true)) {
@@ -169,7 +165,7 @@ private static function getStartPointerBeforeVariablePart(File $phpcsFile, int $
169165
return self::getStartPointerBeforeVariablePart($phpcsFile, $tokens[$previousPointer]['bracket_opener']);
170166
}
171167

172-
if (in_array($tokens[$previousPointer]['code'], array_merge([T_VARIABLE], TokenHelper::getNameTokenCodes()), true)) {
168+
if (in_array($tokens[$previousPointer]['code'], array_merge([T_VARIABLE], TokenHelper::NAME_TOKEN_CODES), true)) {
173169
return self::getStartPointerBeforeVariablePart($phpcsFile, $previousPointer);
174170
}
175171

SlevomatCodingStandard/Helpers/NamespaceHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static function getName(File $phpcsFile, int $namespacePointer): string
101101
$namespaceNameStartPointer = TokenHelper::findNextEffective($phpcsFile, $namespacePointer + 1);
102102
$namespaceNameEndPointer = TokenHelper::findNextExcluding(
103103
$phpcsFile,
104-
TokenHelper::getNameTokenCodes(),
104+
TokenHelper::NAME_TOKEN_CODES,
105105
$namespaceNameStartPointer + 1,
106106
) - 1;
107107

0 commit comments

Comments
 (0)