Skip to content

Commit 8fb1dfd

Browse files
committed
PHPCS 4.0
1 parent 1dd80bf commit 8fb1dfd

File tree

185 files changed

+255
-1026
lines changed

Some content is hidden

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

185 files changed

+255
-1026
lines changed

SlevomatCodingStandard/Helpers/CommentHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static function getCommentEndPointer(File $phpcsFile, int $commentStartPo
4646
continue;
4747
}
4848

49-
if (in_array($tokens[$i]['code'], Tokens::$phpcsCommentTokens, true)) {
49+
if (in_array($tokens[$i]['code'], Tokens::PHPCS_ANNOTATION_TOKENS, true)) {
5050
$commentEndPointer = $i;
5151
continue;
5252
}

SlevomatCodingStandard/Helpers/ConditionHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public static function conditionReturnsBoolean(
6767
$phpcsFile,
6868
array_merge(
6969
[T_OPEN_PARENTHESIS, T_LESS_THAN, T_GREATER_THAN],
70-
Tokens::$booleanOperators,
71-
Tokens::$equalityTokens,
70+
Tokens::BOOLEAN_OPERATORS,
71+
Tokens::EQUALITY_TOKENS,
7272
),
7373
$actualPointer,
7474
$conditionBoundaryEndPointer + 1,
@@ -154,7 +154,7 @@ private static function getNegativeConditionPart(
154154
$pointerAfterConditionStart = TokenHelper::findNextEffective($phpcsFile, $conditionBoundaryStartPointer);
155155
$booleanPointers = TokenHelper::findNextAll(
156156
$phpcsFile,
157-
Tokens::$booleanOperators,
157+
Tokens::BOOLEAN_OPERATORS,
158158
$conditionBoundaryStartPointer,
159159
$conditionBoundaryEndPointer + 1,
160160
);
@@ -295,7 +295,7 @@ private static function getNegativeLogicalCondition(
295295
do {
296296
$actualPointer = TokenHelper::findNext(
297297
$phpcsFile,
298-
array_merge([T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS], Tokens::$booleanOperators),
298+
array_merge([T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS], Tokens::BOOLEAN_OPERATORS),
299299
$actualPointer,
300300
$conditionBoundaryEndPointer + 1,
301301
);

SlevomatCodingStandard/Helpers/NamespaceHelper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use function defined;
1212
use function explode;
1313
use function implode;
14-
use function in_array;
1514
use function ltrim;
1615
use function sprintf;
1716
use function strpos;
@@ -61,7 +60,7 @@ public static function isFullyQualifiedName(string $typeName): bool
6160

6261
public static function isFullyQualifiedPointer(File $phpcsFile, int $pointer): bool
6362
{
64-
return in_array($phpcsFile->getTokens()[$pointer]['code'], [T_NS_SEPARATOR, T_NAME_FULLY_QUALIFIED], true);
63+
return $phpcsFile->getTokens()[$pointer]['code'] === T_NAME_FULLY_QUALIFIED;
6564
}
6665

6766
public static function getFullyQualifiedTypeName(string $typeName): string

SlevomatCodingStandard/Helpers/ReferencedNameHelper.php

Lines changed: 22 additions & 72 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 PHP_CodeSniffer\Util\Tokens;
76
use function array_key_exists;
87
use function array_reverse;
98
use function array_values;
@@ -35,9 +34,6 @@
3534
use const T_HEREDOC;
3635
use const T_IMPLEMENTS;
3736
use const T_INSTANCEOF;
38-
use const T_NAME_FULLY_QUALIFIED;
39-
use const T_NAME_QUALIFIED;
40-
use const T_NAME_RELATIVE;
4137
use const T_NAMESPACE;
4238
use const T_NEW;
4339
use const T_NS_SEPARATOR;
@@ -82,44 +78,6 @@ public static function getAllReferencedNamesInAttributes(File $phpcsFile, int $o
8278
return SniffLocalCache::getAndSetIfNotCached($phpcsFile, 'referencesFromAttributes', $lazyValue);
8379
}
8480

85-
public static function getReferenceName(File $phpcsFile, int $nameStartPointer, int $nameEndPointer): string
86-
{
87-
$tokens = $phpcsFile->getTokens();
88-
89-
$referencedName = '';
90-
for ($i = $nameStartPointer; $i <= $nameEndPointer; $i++) {
91-
if (in_array($tokens[$i]['code'], Tokens::$emptyTokens, true)) {
92-
continue;
93-
}
94-
95-
$referencedName .= $tokens[$i]['content'];
96-
}
97-
98-
return $referencedName;
99-
}
100-
101-
public static function getReferencedNameEndPointer(File $phpcsFile, int $startPointer): int
102-
{
103-
$tokens = $phpcsFile->getTokens();
104-
105-
$nameTokenCodesWithWhitespace = [...TokenHelper::NAME_TOKEN_CODES, ...TokenHelper::INEFFECTIVE_TOKEN_CODES];
106-
107-
$lastNamePointer = $startPointer;
108-
for ($i = $startPointer + 1; $i < count($tokens); $i++) {
109-
if (!in_array($tokens[$i]['code'], $nameTokenCodesWithWhitespace, true)) {
110-
break;
111-
}
112-
113-
if (!in_array($tokens[$i]['code'], TokenHelper::NAME_TOKEN_CODES, true)) {
114-
continue;
115-
}
116-
117-
$lastNamePointer = $i;
118-
}
119-
120-
return $lastNamePointer;
121-
}
122-
12381
/**
12482
* @return list<ReferencedName>
12583
*/
@@ -134,57 +92,55 @@ private static function createAllReferencedNames(File $phpcsFile, int $openTagPo
13492

13593
$tokens = $phpcsFile->getTokens();
13694
while (true) {
137-
$nameStartPointer = TokenHelper::findNext($phpcsFile, $nameTokenCodes, $beginSearchAtPointer);
138-
if ($nameStartPointer === null) {
95+
$namePointer = TokenHelper::findNext($phpcsFile, $nameTokenCodes, $beginSearchAtPointer);
96+
if ($namePointer === null) {
13997
break;
14098
}
14199

142100
// Find referenced names inside double quotes string
143-
if (self::isNeedParsedContent($tokens[$nameStartPointer]['code'])) {
144-
$content = $tokens[$nameStartPointer]['content'];
145-
$currentPointer = $nameStartPointer + 1;
101+
if (self::isNeedParsedContent($tokens[$namePointer]['code'])) {
102+
$content = $tokens[$namePointer]['content'];
103+
$currentPointer = $namePointer + 1;
146104
while (self::isNeedParsedContent($tokens[$currentPointer]['code'])) {
147105
$content .= $tokens[$currentPointer]['content'];
148106
$currentPointer++;
149107
}
150108

151109
$names = self::getReferencedNamesFromString($content);
152110
foreach ($names as $name) {
153-
$referencedNames[] = new ReferencedName($name, $nameStartPointer, $nameStartPointer, ReferencedName::TYPE_CLASS);
111+
$referencedNames[] = new ReferencedName($name, $namePointer, $namePointer, ReferencedName::TYPE_CLASS);
154112
}
155113

156114
$beginSearchAtPointer = $currentPointer;
157115
continue;
158116
}
159117

160118
// Attributes are parsed in specific method
161-
$attributeStartPointerBefore = TokenHelper::findPrevious($phpcsFile, T_ATTRIBUTE, $nameStartPointer - 1, $beginSearchAtPointer);
119+
$attributeStartPointerBefore = TokenHelper::findPrevious($phpcsFile, T_ATTRIBUTE, $namePointer - 1, $beginSearchAtPointer);
162120
if ($attributeStartPointerBefore !== null) {
163-
if ($tokens[$attributeStartPointerBefore]['attribute_closer'] > $nameStartPointer) {
121+
if ($tokens[$attributeStartPointerBefore]['attribute_closer'] > $namePointer) {
164122
$beginSearchAtPointer = $tokens[$attributeStartPointerBefore]['attribute_closer'] + 1;
165123
continue;
166124
}
167125
}
168126

169-
if (!self::isReferencedName($phpcsFile, $nameStartPointer)) {
127+
if (!self::isReferencedName($phpcsFile, $namePointer)) {
170128
/** @var int $beginSearchAtPointer */
171129
$beginSearchAtPointer = TokenHelper::findNextExcluding(
172130
$phpcsFile,
173131
[...TokenHelper::INEFFECTIVE_TOKEN_CODES, ...$nameTokenCodes],
174-
$nameStartPointer + 1,
132+
$namePointer + 1,
175133
);
176134
continue;
177135
}
178136

179-
$nameEndPointer = self::getReferencedNameEndPointer($phpcsFile, $nameStartPointer);
180-
181137
$referencedNames[] = new ReferencedName(
182-
self::getReferenceName($phpcsFile, $nameStartPointer, $nameEndPointer),
183-
$nameStartPointer,
184-
$nameEndPointer,
185-
self::getReferenceType($phpcsFile, $nameStartPointer, $nameEndPointer),
138+
$tokens[$namePointer]['content'],
139+
$namePointer,
140+
$namePointer,
141+
self::getReferenceType($phpcsFile, $namePointer, $namePointer),
186142
);
187-
$beginSearchAtPointer = $nameEndPointer + 1;
143+
$beginSearchAtPointer = $namePointer + 1;
188144
}
189145
return $referencedNames;
190146
}
@@ -385,8 +341,7 @@ private static function isReferencedName(File $phpcsFile, int $startPointer): bo
385341
return false;
386342
}
387343

388-
$endPointer = self::getReferencedNameEndPointer($phpcsFile, $startPointer);
389-
$referencedName = self::getReferenceName($phpcsFile, $startPointer, $endPointer);
344+
$referencedName = $tokens[$startPointer]['content'];
390345

391346
if (TypeHintHelper::isSimpleTypeHint($referencedName) || $referencedName === 'object') {
392347
return $tokens[$nextPointer]['code'] === T_OPEN_PARENTHESIS;
@@ -432,22 +387,20 @@ private static function createAllReferencedNamesInAttributes(File $phpcsFile, in
432387
continue;
433388
}
434389

435-
$referencedNameEndPointer = self::getReferencedNameEndPointer($phpcsFile, $pointer);
436-
437390
$pointerBefore = TokenHelper::findPreviousEffective($phpcsFile, $pointer - 1);
438391

439392
if (in_array($tokens[$pointerBefore]['code'], [T_OPEN_TAG, T_ATTRIBUTE], true)) {
440393
$referenceType = ReferencedName::TYPE_CLASS;
441394
} elseif ($tokens[$pointerBefore]['code'] === T_COMMA && $level === 0) {
442395
$referenceType = ReferencedName::TYPE_CLASS;
443396
} elseif (self::isReferencedName($phpcsFile, $pointer)) {
444-
$referenceType = self::getReferenceType($phpcsFile, $pointer, $referencedNameEndPointer);
397+
$referenceType = self::getReferenceType($phpcsFile, $pointer, $pointer);
445398
} else {
446399
$searchPointer = $pointer + 1;
447400
continue;
448401
}
449402

450-
$referencedName = self::getReferenceName($phpcsFile, $pointer, $referencedNameEndPointer);
403+
$referencedName = $tokens[$pointer]['content'];
451404

452405
$referencedNames[] = new ReferencedName(
453406
$referencedName,
@@ -456,7 +409,7 @@ private static function createAllReferencedNamesInAttributes(File $phpcsFile, in
456409
$referenceType,
457410
);
458411

459-
$searchPointer = $referencedNameEndPointer + 1;
412+
$searchPointer = $pointer + 1;
460413

461414
} while (true);
462415
}
@@ -485,7 +438,7 @@ private static function getReferencedNamesFromString(string $content): array
485438
$referencedName = '';
486439
$tmpPosition = $position - 1;
487440
while (true) {
488-
if (!is_array($subTokens[$tmpPosition]) || !in_array($subTokens[$tmpPosition][0], [T_NS_SEPARATOR, T_STRING], true)) {
441+
if (!is_array($subTokens[$tmpPosition]) || $subTokens[$tmpPosition][0] !== T_STRING) {
489442
break;
490443
}
491444

@@ -505,11 +458,8 @@ private static function getReferencedNamesFromString(string $content): array
505458
$tmpPosition++;
506459
continue;
507460
}
508-
if (!in_array(
509-
$subTokens[$tmpPosition][0],
510-
[T_STRING, T_NS_SEPARATOR, T_NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED, T_NAME_RELATIVE],
511-
true,
512-
)) {
461+
// We need to check namespace separator because of support for PHP 7.4
462+
if (!in_array($subTokens[$tmpPosition][0], [T_NS_SEPARATOR, ...TokenHelper::NAME_TOKEN_CODES], true)) {
513463
break;
514464
}
515465

SlevomatCodingStandard/Helpers/TokenHelper.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
use const T_NAME_FULLY_QUALIFIED;
3232
use const T_NAME_QUALIFIED;
3333
use const T_NAME_RELATIVE;
34-
use const T_NS_SEPARATOR;
3534
use const T_NULL;
3635
use const T_OPEN_SHORT_ARRAY;
3736
use const T_PARENT;
@@ -67,18 +66,13 @@
6766
class TokenHelper
6867
{
6968

70-
public const ONLY_NAME_TOKEN_CODES = [
69+
public const NAME_TOKEN_CODES = [
7170
T_STRING,
7271
T_NAME_FULLY_QUALIFIED,
7372
T_NAME_QUALIFIED,
7473
T_NAME_RELATIVE,
7574
];
7675

77-
public const NAME_TOKEN_CODES = [
78-
...self::ONLY_NAME_TOKEN_CODES,
79-
T_NS_SEPARATOR,
80-
];
81-
8276
public const ONLY_TYPE_HINT_TOKEN_CODES = [
8377
...self::NAME_TOKEN_CODES,
8478
T_SELF,
@@ -462,9 +456,6 @@ public static function findFirstNonWhitespaceOnPreviousLine(File $phpcsFile, int
462456
$phpcsFile->eolChar,
463457
$newLinePointerOnPreviousLine - 1,
464458
);
465-
if ($newLinePointerBeforePreviousLine === null) {
466-
return null;
467-
}
468459

469460
$nextPointer = self::findNextExcluding($phpcsFile, [T_WHITESPACE, T_DOC_COMMENT_WHITESPACE], $newLinePointerBeforePreviousLine + 1);
470461

SlevomatCodingStandard/Helpers/YodaHelper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
use const T_LOGICAL_XOR;
4646
use const T_MATCH_ARROW;
4747
use const T_MINUS;
48-
use const T_NS_SEPARATOR;
4948
use const T_NULL;
5049
use const T_OBJECT_CAST;
5150
use const T_OPEN_PARENTHESIS;
@@ -185,7 +184,7 @@ public static function getDynamismForTokens(array $tokens, array $sideTokens): ?
185184
{
186185
$sideTokens = array_values(array_filter($sideTokens, static fn (array $token): bool => !in_array(
187186
$token['code'],
188-
[T_WHITESPACE, T_COMMENT, T_DOC_COMMENT, T_NS_SEPARATOR, T_PLUS, T_MINUS, T_INT_CAST, T_DOUBLE_CAST, T_STRING_CAST, T_ARRAY_CAST, T_OBJECT_CAST, T_BOOL_CAST, T_UNSET_CAST],
187+
[T_WHITESPACE, T_COMMENT, T_DOC_COMMENT, T_PLUS, T_MINUS, T_INT_CAST, T_DOUBLE_CAST, T_STRING_CAST, T_ARRAY_CAST, T_OBJECT_CAST, T_BOOL_CAST, T_UNSET_CAST],
189188
true,
190189
)));
191190

SlevomatCodingStandard/Sniffs/Arrays/AlphabeticallySortedByKeysSniff.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ public function register(): array
2727
return TokenHelper::ARRAY_TOKEN_CODES;
2828
}
2929

30-
/**
31-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
32-
* @param int $stackPointer
33-
*/
34-
public function process(File $phpcsFile, $stackPointer): void
30+
public function process(File $phpcsFile, int $stackPointer): void
3531
{
3632
if (ArrayHelper::isMultiLine($phpcsFile, $stackPointer) === false) {
3733
return;

SlevomatCodingStandard/Sniffs/Arrays/ArrayAccessSniff.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ public function register(): array
2424
return [T_OPEN_SQUARE_BRACKET];
2525
}
2626

27-
/**
28-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
29-
* @param int $stackPointer
30-
*/
31-
public function process(File $phpcsFile, $stackPointer): void
27+
public function process(File $phpcsFile, int $stackPointer): void
3228
{
3329
$tokens = $phpcsFile->getTokens();
3430

SlevomatCodingStandard/Sniffs/Arrays/DisallowImplicitArrayCreationSniff.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ public function register(): array
4343
];
4444
}
4545

46-
/**
47-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
48-
* @param int $bracketOpenerPointer
49-
*/
50-
public function process(File $phpcsFile, $bracketOpenerPointer): void
46+
public function process(File $phpcsFile, int $bracketOpenerPointer): void
5147
{
5248
$tokens = $phpcsFile->getTokens();
5349

SlevomatCodingStandard/Sniffs/Arrays/DisallowPartiallyKeyedSniff.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ public function register(): array
2020
return TokenHelper::ARRAY_TOKEN_CODES;
2121
}
2222

23-
/**
24-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
25-
* @param int $stackPointer
26-
*/
27-
public function process(File $phpcsFile, $stackPointer): void
23+
public function process(File $phpcsFile, int $stackPointer): void
2824
{
2925
$keyValues = ArrayHelper::parse($phpcsFile, $stackPointer);
3026

0 commit comments

Comments
 (0)