Skip to content

Commit 9cc5050

Browse files
committed
Less array_merge()
1 parent e254aa2 commit 9cc5050

27 files changed

+103
-139
lines changed

SlevomatCodingStandard/Helpers/CatchHelper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace SlevomatCodingStandard\Helpers;
44

55
use PHP_CodeSniffer\Files\File;
6-
use function array_merge;
76
use function in_array;
87
use const T_BITWISE_OR;
98
use const T_CATCH;
@@ -52,7 +51,7 @@ public static function findCaughtTypesInCatch(File $phpcsFile, array $catchToken
5251
do {
5352
$nameStartPointer = TokenHelper::findNext(
5453
$phpcsFile,
55-
array_merge([T_BITWISE_OR], TokenHelper::NAME_TOKEN_CODES),
54+
[T_BITWISE_OR, ...TokenHelper::NAME_TOKEN_CODES],
5655
$nameEndPointer + 1,
5756
$catchParenthesisCloserPointer,
5857
);

SlevomatCodingStandard/Helpers/DocCommentHelper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
88
use PHPStan\PhpDocParser\Parser\ParserException;
99
use PHPStan\PhpDocParser\Parser\TokenIterator;
10-
use function array_merge;
1110
use function count;
1211
use function in_array;
1312
use function preg_match;
@@ -208,7 +207,7 @@ public static function findDocCommentOwnerPointer(File $phpcsFile, int $docComme
208207

209208
if (in_array(
210209
$tokens[$i]['code'],
211-
array_merge([T_FUNCTION, T_VARIABLE, T_CONST], TokenHelper::CLASS_TYPE_TOKEN_CODES),
210+
[T_FUNCTION, T_VARIABLE, T_CONST, ...TokenHelper::CLASS_TYPE_TOKEN_CODES],
212211
true,
213212
)) {
214213
$docCommentOwnerPointer = $i;

SlevomatCodingStandard/Helpers/FunctionHelper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
1212
use function array_filter;
1313
use function array_map;
14-
use function array_merge;
1514
use function array_pop;
1615
use function array_reverse;
1716
use function array_values;
@@ -215,7 +214,7 @@ public static function getParametersTypeHints(File $phpcsFile, int $functionPoin
215214

216215
$pointerBeforeVariable = TokenHelper::findPreviousExcluding(
217216
$phpcsFile,
218-
array_merge(TokenHelper::INEFFECTIVE_TOKEN_CODES, [T_BITWISE_AND, T_ELLIPSIS]),
217+
[...TokenHelper::INEFFECTIVE_TOKEN_CODES, T_BITWISE_AND, T_ELLIPSIS],
219218
$i - 1,
220219
);
221220

SlevomatCodingStandard/Helpers/IdentificatorHelper.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHP_CodeSniffer\Files\File;
66
use function array_key_exists;
7-
use function array_merge;
87
use function in_array;
98
use const T_CLOSE_CURLY_BRACKET;
109
use const T_CLOSE_PARENTHESIS;
@@ -84,7 +83,7 @@ public static function findEndPointer(File $phpcsFile, int $startPointer): ?int
8483
$nextPointer = TokenHelper::findNextEffective($phpcsFile, $startPointer + 1);
8584

8685
if (
87-
in_array($tokens[$startPointer]['code'], array_merge([T_SELF, T_STATIC, T_PARENT], TokenHelper::NAME_TOKEN_CODES), true)
86+
in_array($tokens[$startPointer]['code'], [T_SELF, T_STATIC, T_PARENT, ...TokenHelper::NAME_TOKEN_CODES], true)
8887
&& $tokens[$nextPointer]['code'] === T_DOUBLE_COLON
8988
) {
9089
return self::getEndPointerAfterOperator($phpcsFile, $nextPointer);
@@ -118,7 +117,7 @@ private static function getStartPointerBeforeOperator(File $phpcsFile, int $oper
118117

119118
if (
120119
$tokens[$operatorPointer]['code'] === T_DOUBLE_COLON
121-
&& in_array($tokens[$previousPointer]['code'], array_merge([T_SELF, T_STATIC, T_PARENT], TokenHelper::NAME_TOKEN_CODES), true)
120+
&& in_array($tokens[$previousPointer]['code'], [T_SELF, T_STATIC, T_PARENT, ...TokenHelper::NAME_TOKEN_CODES], true)
122121
) {
123122
return $previousPointer;
124123
}
@@ -165,7 +164,7 @@ private static function getStartPointerBeforeVariablePart(File $phpcsFile, int $
165164
return self::getStartPointerBeforeVariablePart($phpcsFile, $tokens[$previousPointer]['bracket_opener']);
166165
}
167166

168-
if (in_array($tokens[$previousPointer]['code'], array_merge([T_VARIABLE], TokenHelper::NAME_TOKEN_CODES), true)) {
167+
if (in_array($tokens[$previousPointer]['code'], [T_VARIABLE, ...TokenHelper::NAME_TOKEN_CODES], true)) {
169168
return self::getStartPointerBeforeVariablePart($phpcsFile, $previousPointer);
170169
}
171170

SlevomatCodingStandard/Helpers/ParsedDocComment.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PHPStan\PhpDocParser\Ast\Node;
88
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
99
use PHPStan\PhpDocParser\Parser\TokenIterator;
10-
use function array_merge;
1110
use function count;
1211
use function strlen;
1312
use function trim;
@@ -69,7 +68,7 @@ public function getNodeStartPointer(File $phpcsFile, Node $node): int
6968
}
7069
}
7170

72-
return TokenHelper::findNext($phpcsFile, array_merge(TokenHelper::ANNOTATION_TOKEN_CODES, [T_DOC_COMMENT_STRING]), $searchPointer);
71+
return TokenHelper::findNext($phpcsFile, [...TokenHelper::ANNOTATION_TOKEN_CODES, T_DOC_COMMENT_STRING], $searchPointer);
7372
}
7473

7574
public function getNodeEndPointer(File $phpcsFile, Node $node, int $nodeStartPointer): int
@@ -96,7 +95,7 @@ public function getNodeEndPointer(File $phpcsFile, Node $node, int $nodeStartPoi
9695

9796
return TokenHelper::findPrevious(
9897
$phpcsFile,
99-
array_merge(TokenHelper::ANNOTATION_TOKEN_CODES, [T_DOC_COMMENT_STRING]),
98+
[...TokenHelper::ANNOTATION_TOKEN_CODES, T_DOC_COMMENT_STRING],
10099
$searchPointer,
101100
);
102101
}

SlevomatCodingStandard/Helpers/PropertyHelper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHP_CodeSniffer\Util\Tokens;
77
use function array_key_exists;
88
use function array_keys;
9-
use function array_merge;
109
use function array_reverse;
1110
use function array_values;
1211
use function count;
@@ -39,7 +38,7 @@ public static function isProperty(File $phpcsFile, int $variablePointer, bool $p
3938

4039
$previousPointer = TokenHelper::findPreviousExcluding(
4140
$phpcsFile,
42-
array_merge(TokenHelper::INEFFECTIVE_TOKEN_CODES, TokenHelper::TYPE_HINT_TOKEN_CODES, [T_NULLABLE]),
41+
[...TokenHelper::INEFFECTIVE_TOKEN_CODES, ...TokenHelper::TYPE_HINT_TOKEN_CODES, T_NULLABLE],
4342
$variablePointer - 1,
4443
);
4544

@@ -74,7 +73,7 @@ public static function isProperty(File $phpcsFile, int $variablePointer, bool $p
7473

7574
$functionPointer = TokenHelper::findPrevious(
7675
$phpcsFile,
77-
array_merge(TokenHelper::FUNCTION_TOKEN_CODES, [T_SEMICOLON, T_CLOSE_CURLY_BRACKET, T_OPEN_CURLY_BRACKET]),
76+
[...TokenHelper::FUNCTION_TOKEN_CODES, T_SEMICOLON, T_CLOSE_CURLY_BRACKET, T_OPEN_CURLY_BRACKET],
7877
$variablePointer - 1,
7978
);
8079
if (

SlevomatCodingStandard/Helpers/ReferencedNameHelper.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PHP_CodeSniffer\Files\File;
66
use PHP_CodeSniffer\Util\Tokens;
77
use function array_key_exists;
8-
use function array_merge;
98
use function array_reverse;
109
use function array_values;
1110
use function count;
@@ -103,7 +102,7 @@ public static function getReferencedNameEndPointer(File $phpcsFile, int $startPo
103102
{
104103
$tokens = $phpcsFile->getTokens();
105104

106-
$nameTokenCodesWithWhitespace = array_merge(TokenHelper::NAME_TOKEN_CODES, Tokens::$emptyTokens);
105+
$nameTokenCodesWithWhitespace = [...TokenHelper::NAME_TOKEN_CODES, ...TokenHelper::INEFFECTIVE_TOKEN_CODES];
107106

108107
$lastNamePointer = $startPointer;
109108
for ($i = $startPointer + 1; $i < count($tokens); $i++) {
@@ -171,7 +170,7 @@ private static function createAllReferencedNames(File $phpcsFile, int $openTagPo
171170
/** @var int $beginSearchAtPointer */
172171
$beginSearchAtPointer = TokenHelper::findNextExcluding(
173172
$phpcsFile,
174-
array_merge(TokenHelper::INEFFECTIVE_TOKEN_CODES, $nameTokenCodes),
173+
[...TokenHelper::INEFFECTIVE_TOKEN_CODES, ...$nameTokenCodes],
175174
$nameStartPointer + 1,
176175
);
177176
continue;
@@ -268,7 +267,7 @@ private static function getReferenceType(File $phpcsFile, int $nameStartPointer,
268267
if ($tokens[$previousTokenBeforeStartPointer]['code'] === T_COMMA) {
269268
$previousTokenPointer = TokenHelper::findPreviousExcluding(
270269
$phpcsFile,
271-
array_merge([T_COMMA], TokenHelper::NAME_TOKEN_CODES, TokenHelper::INEFFECTIVE_TOKEN_CODES),
270+
[T_COMMA, ...TokenHelper::NAME_TOKEN_CODES, ...TokenHelper::INEFFECTIVE_TOKEN_CODES],
272271
$previousTokenBeforeStartPointer - 1,
273272
);
274273

@@ -284,7 +283,7 @@ private static function getReferenceType(File $phpcsFile, int $nameStartPointer,
284283
if (in_array($tokens[$previousTokenBeforeStartPointer]['code'], [T_BITWISE_OR, T_OPEN_PARENTHESIS], true)) {
285284
$catchPointer = TokenHelper::findPreviousExcluding(
286285
$phpcsFile,
287-
array_merge([T_BITWISE_OR, T_OPEN_PARENTHESIS], TokenHelper::NAME_TOKEN_CODES, TokenHelper::INEFFECTIVE_TOKEN_CODES),
286+
[T_BITWISE_OR, T_OPEN_PARENTHESIS, ...TokenHelper::NAME_TOKEN_CODES, ...TokenHelper::INEFFECTIVE_TOKEN_CODES],
288287
$previousTokenBeforeStartPointer - 1,
289288
);
290289

@@ -373,7 +372,7 @@ private static function isReferencedName(File $phpcsFile, int $startPointer): bo
373372

374373
$isProbablyReferencedName = !in_array(
375374
$previousToken['code'],
376-
array_merge($skipTokenCodes, TokenHelper::CLASS_TYPE_TOKEN_CODES),
375+
[...$skipTokenCodes, ...TokenHelper::CLASS_TYPE_TOKEN_CODES],
377376
true,
378377
);
379378

@@ -412,7 +411,7 @@ private static function createAllReferencedNamesInAttributes(File $phpcsFile, in
412411
$searchEndPointer = $tokens[$attributeStartPointer]['attribute_closer'];
413412

414413
$searchPointer = $searchStartPointer;
415-
$searchTokens = array_merge(TokenHelper::NAME_TOKEN_CODES, [T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS]);
414+
$searchTokens = [...TokenHelper::NAME_TOKEN_CODES, T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS];
416415
$level = 0;
417416
do {
418417
$pointer = TokenHelper::findNext($phpcsFile, $searchTokens, $searchPointer, $searchEndPointer);

SlevomatCodingStandard/Helpers/TypeHintHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public static function getStartPointer(File $phpcsFile, int $endPointer): int
251251
{
252252
$previousPointer = TokenHelper::findPreviousExcluding(
253253
$phpcsFile,
254-
array_merge([T_WHITESPACE], TokenHelper::TYPE_HINT_TOKEN_CODES),
254+
[T_WHITESPACE, ...TokenHelper::TYPE_HINT_TOKEN_CODES],
255255
$endPointer - 1,
256256
);
257257
return TokenHelper::findNextNonWhitespace($phpcsFile, $previousPointer + 1);

SlevomatCodingStandard/Helpers/UseStatementHelper.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHP_CodeSniffer\Files\File;
66
use function array_key_exists;
7-
use function array_merge;
87
use function array_reverse;
98
use function count;
109
use function current;
@@ -227,8 +226,7 @@ private static function getUseStatementPointers(File $phpcsFile, int $openTagPoi
227226
$pointer = $openTagPointer + 1;
228227
$pointers = [];
229228
while (true) {
230-
$typesToFind = array_merge([T_USE], TokenHelper::CLASS_TYPE_TOKEN_CODES);
231-
$pointer = TokenHelper::findNext($phpcsFile, $typesToFind, $pointer);
229+
$pointer = TokenHelper::findNext($phpcsFile, [T_USE, ...TokenHelper::CLASS_TYPE_TOKEN_CODES], $pointer);
232230
if ($pointer === null) {
233231
break;
234232
}

SlevomatCodingStandard/Sniffs/Commenting/AnnotationNameSniff.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use function array_combine;
1313
use function array_key_exists;
1414
use function array_map;
15-
use function array_merge;
1615
use function array_unique;
1716
use function implode;
1817
use function ltrim;
@@ -273,7 +272,7 @@ private function getNormalizedAnnotationNames(): array
273272
SniffSettingsHelper::normalizeArray($this->annotations),
274273
);
275274
} else {
276-
$annotationNames = array_merge(self::STANDARD_ANNOTATIONS, self::PHPUNIT_ANNOTATIONS, self::STATIC_ANALYSIS_ANNOTATIONS);
275+
$annotationNames = [...self::STANDARD_ANNOTATIONS, ...self::PHPUNIT_ANNOTATIONS, ...self::STATIC_ANALYSIS_ANNOTATIONS];
277276

278277
foreach (self::STATIC_ANALYSIS_ANNOTATIONS as $annotationName) {
279278
if (strpos($annotationName, 'psalm') === 0) {

0 commit comments

Comments
 (0)