Skip to content

Commit 81ade36

Browse files
committed
Modernize code thanks to PHP 7.4+
1 parent 9801fc0 commit 81ade36

File tree

266 files changed

+2049
-2299
lines changed

Some content is hidden

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

266 files changed

+2049
-2299
lines changed

SlevomatCodingStandard/Helpers/Annotation.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@
1313
class Annotation
1414
{
1515

16-
/** @var PhpDocTagNode */
17-
private $node;
16+
private PhpDocTagNode $node;
1817

19-
/** @var int */
20-
private $startPointer;
18+
private int $startPointer;
2119

22-
/** @var int */
23-
private $endPointer;
20+
private int $endPointer;
2421

2522
public function __construct(PhpDocTagNode $node, int $startPointer, int $endPointer)
2623
{

SlevomatCodingStandard/Helpers/AnnotationHelper.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ static function () use ($phpcsFile, $docCommentOpenPointer, $name): array {
6868
$annotations[] = new Annotation(
6969
$node,
7070
$annotationStartPointer,
71-
$parsedDocComment->getNodeEndPointer($phpcsFile, $node, $annotationStartPointer)
71+
$parsedDocComment->getNodeEndPointer($phpcsFile, $node, $annotationStartPointer),
7272
);
7373
}
7474
}
7575
}
7676

7777
return $annotations;
78-
}
78+
},
7979
);
8080
}
8181

@@ -92,13 +92,13 @@ public static function getAnnotationNodesByType(Node $node, string $type): array
9292
$visitor = new class extends AbstractNodeVisitor {
9393

9494
/** @var class-string */
95-
private $type;
95+
private string $type;
9696

9797
/** @var list<Node> */
98-
private $nodes = [];
98+
private array $nodes = [];
9999

100100
/** @var list<Node> */
101-
private $nodesToIgnore = [];
101+
private array $nodesToIgnore = [];
102102

103103
/**
104104
* @return Node|list<Node>|NodeTraverser::*|null
@@ -179,7 +179,7 @@ public static function fixAnnotation(
179179
return PhpDocParserHelper::getPrinter()->printFormatPreserving(
180180
$newPhpDocNode,
181181
$parsedDocComment->getNode(),
182-
$parsedDocComment->getTokens()
182+
$parsedDocComment->getTokens(),
183183
);
184184
}
185185

@@ -221,7 +221,7 @@ public static function isAnnotationUseless(
221221
if (
222222
TypeHintHelper::isTraversableType(
223223
TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $typeHint->getTypeHintWithoutNullabilitySymbol()),
224-
$traversableTypeHints
224+
$traversableTypeHints,
225225
)
226226
&& !(
227227
$annotationType instanceof IdentifierTypeNode
@@ -257,7 +257,7 @@ public static function isAnnotationUseless(
257257
$phpcsFile,
258258
$functionPointer,
259259
$typeHint->getTypeHint(),
260-
$annotationTypeHint
260+
$annotationTypeHint,
261261
);
262262
}
263263

@@ -289,15 +289,15 @@ public static function isAnnotationUseless(
289289
if (in_array(
290290
strtolower($annotationType->name),
291291
['true', 'false', 'null'],
292-
true
292+
true,
293293
)) {
294294
return $enableStandaloneNullTrueFalseTypeHints;
295295
}
296296

297297
if (in_array(
298298
strtolower($annotationType->name),
299299
['class-string', 'trait-string', 'callable-string', 'numeric-string', 'non-empty-string', 'non-falsy-string', 'literal-string', 'positive-int', 'negative-int'],
300-
true
300+
true,
301301
)) {
302302
return false;
303303
}
@@ -308,7 +308,7 @@ public static function isAnnotationUseless(
308308
$phpcsFile,
309309
$functionPointer,
310310
$typeHint->getTypeHintWithoutNullabilitySymbol(),
311-
$annotationTypeHint
311+
$annotationTypeHint,
312312
);
313313
}
314314

@@ -320,11 +320,9 @@ private static function changeAnnotationNode(PhpDocTagNode $tagNode, Node $nodeT
320320
if ($visitor === null) {
321321
$visitor = new class extends AbstractNodeVisitor {
322322

323-
/** @var Node */
324-
private $nodeToChange;
323+
private Node $nodeToChange;
325324

326-
/** @var Node */
327-
private $changedNode;
325+
private Node $changedNode;
328326

329327
public function enterNode(Node $node): ?Node
330328
{

SlevomatCodingStandard/Helpers/AnnotationTypeHelper.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public static function containsItemsSpecificationForTraversable(
197197
$phpcsFile,
198198
$pointer,
199199
$traversableTypeHints,
200-
true
200+
true,
201201
)) {
202202
return false;
203203
}
@@ -222,7 +222,7 @@ public static function containsItemsSpecificationForTraversable(
222222

223223
return !TypeHintHelper::isTraversableType(
224224
TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $pointer, $typeNode->name),
225-
$traversableTypeHints
225+
$traversableTypeHints,
226226
);
227227
}
228228

@@ -256,7 +256,7 @@ public static function containsItemsSpecificationForTraversable(
256256
$phpcsFile,
257257
$pointer,
258258
$traversableTypeHints,
259-
$inTraversable
259+
$inTraversable,
260260
)) {
261261
return true;
262262
}
@@ -271,7 +271,7 @@ public static function containsItemsSpecificationForTraversable(
271271
$phpcsFile,
272272
$pointer,
273273
$traversableTypeHints,
274-
$inTraversable
274+
$inTraversable,
275275
);
276276
}
277277

@@ -310,7 +310,7 @@ public static function getTypeHintFromOneType(
310310
if (in_array(
311311
strtolower($typeNode->name),
312312
['class-string', 'trait-string', 'callable-string', 'numeric-string', 'non-empty-string', 'non-falsy-string', 'literal-string'],
313-
true
313+
true,
314314
)) {
315315
return 'string';
316316
}
@@ -383,7 +383,7 @@ public static function getTraversableTypeHintsFromType(
383383
foreach ($typeHints as $typeHint) {
384384
if (!TypeHintHelper::isTraversableType(
385385
TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $pointer, $typeHint),
386-
$traversableTypeHints
386+
$traversableTypeHints,
387387
)) {
388388
return [];
389389
}

SlevomatCodingStandard/Helpers/ArrayKeyValue.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,19 @@
1919
class ArrayKeyValue
2020
{
2121

22-
/** @var int */
23-
private $pointerStart;
22+
private int $pointerStart;
2423

25-
/** @var int */
26-
private $pointerEnd;
24+
private int $pointerEnd;
2725

28-
/** @var ?string */
29-
private $indent = null;
26+
private ?string $indent = null;
3027

31-
/** @var ?string */
32-
private $key = null;
28+
private ?string $key = null;
3329

34-
/** @var ?int */
35-
private $pointerArrow = null;
30+
private ?int $pointerArrow = null;
3631

37-
/** @var ?int */
38-
private $pointerComma = null;
32+
private ?int $pointerComma = null;
3933

40-
/** @var bool */
41-
private $unpacking = false;
34+
private bool $unpacking = false;
4235

4336
public function __construct(File $phpcsFile, int $pointerStart, int $pointerEnd)
4437
{
@@ -155,13 +148,13 @@ private function addValues(File $phpcsFile): void
155148
}
156149
$haveIndent = $firstNonWhitespace !== null && TokenHelper::findFirstNonWhitespaceOnLine(
157150
$phpcsFile,
158-
$firstNonWhitespace
151+
$firstNonWhitespace,
159152
) === $firstNonWhitespace;
160153
$this->indent = $haveIndent
161154
? TokenHelper::getContent(
162155
$phpcsFile,
163156
TokenHelper::findFirstTokenOnLine($phpcsFile, $firstNonWhitespace),
164-
$firstNonWhitespace - 1
157+
$firstNonWhitespace - 1,
165158
)
166159
: null;
167160
$this->key = $this->pointerArrow !== null

SlevomatCodingStandard/Helpers/Attribute.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@
88
class Attribute
99
{
1010

11-
/** @var int */
12-
private $attributePointer;
11+
private int $attributePointer;
1312

14-
/** @var string */
15-
private $name;
13+
private string $name;
1614

17-
/** @var int */
18-
private $startPointer;
15+
private int $startPointer;
1916

20-
/** @var int */
21-
private $endPointer;
17+
private int $endPointer;
2218

23-
/** @var string|null */
24-
private $content;
19+
private ?string $content = null;
2520

2621
public function __construct(int $attributePointer, string $name, int $startPointer, int $endPointer, ?string $content = null)
2722
{

SlevomatCodingStandard/Helpers/AttributeHelper.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static function getAttributes(File $phpcsFile, int $attributeOpenerPointe
4949

5050
if ($tokens[$attributeOpenerPointer]['code'] !== T_ATTRIBUTE) {
5151
throw new InvalidArgumentException(
52-
sprintf('Token %d must be attribute, %s given.', $attributeOpenerPointer, $tokens[$attributeOpenerPointer]['type'])
52+
sprintf('Token %d must be attribute, %s given.', $attributeOpenerPointer, $tokens[$attributeOpenerPointer]['type']),
5353
);
5454
}
5555

@@ -68,7 +68,7 @@ public static function getAttributes(File $phpcsFile, int $attributeOpenerPointe
6868
$attributeNameEndPointer = TokenHelper::findNextExcluding(
6969
$phpcsFile,
7070
TokenHelper::getNameTokenCodes(),
71-
$attributeNameStartPointer + 1
71+
$attributeNameStartPointer + 1,
7272
) - 1;
7373
$attributeName = TokenHelper::getContent($phpcsFile, $attributeNameStartPointer, $attributeNameEndPointer);
7474

@@ -79,7 +79,7 @@ public static function getAttributes(File $phpcsFile, int $attributeOpenerPointe
7979
$attributeOpenerPointer,
8080
$attributeName,
8181
$attributeNameStartPointer,
82-
$attributeNameEndPointer
82+
$attributeNameEndPointer,
8383
);
8484
break;
8585
}
@@ -89,7 +89,7 @@ public static function getAttributes(File $phpcsFile, int $attributeOpenerPointe
8989
$attributeOpenerPointer,
9090
$attributeName,
9191
$attributeNameStartPointer,
92-
$attributeNameEndPointer
92+
$attributeNameEndPointer,
9393
);
9494

9595
$actualPointer = $pointerAfterAttributeName;
@@ -104,14 +104,14 @@ public static function getAttributes(File $phpcsFile, int $attributeOpenerPointe
104104
TokenHelper::getContent(
105105
$phpcsFile,
106106
$pointerAfterAttributeName,
107-
$tokens[$pointerAfterAttributeName]['parenthesis_closer']
108-
)
107+
$tokens[$pointerAfterAttributeName]['parenthesis_closer'],
108+
),
109109
);
110110

111111
$actualPointer = TokenHelper::findNextEffective(
112112
$phpcsFile,
113113
$tokens[$pointerAfterAttributeName]['parenthesis_closer'] + 1,
114-
$attributeCloserPointer
114+
$attributeCloserPointer,
115115
);
116116

117117
continue;

SlevomatCodingStandard/Helpers/CatchHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function findCaughtTypesInCatch(File $phpcsFile, array $catchToken
5656
$phpcsFile,
5757
array_merge([T_BITWISE_OR], $nameTokenCodes),
5858
$nameEndPointer + 1,
59-
$catchParenthesisCloserPointer
59+
$catchParenthesisCloserPointer,
6060
);
6161
if ($nameStartPointer === null) {
6262
break;
@@ -73,7 +73,7 @@ public static function findCaughtTypesInCatch(File $phpcsFile, array $catchToken
7373
$caughtTypes[] = NamespaceHelper::resolveClassName(
7474
$phpcsFile,
7575
TokenHelper::getContent($phpcsFile, $nameStartPointer, $nameEndPointer),
76-
$catchParenthesisOpenerPointer
76+
$catchParenthesisOpenerPointer,
7777
);
7878
} while (true);
7979

SlevomatCodingStandard/Helpers/ClassHelper.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ public static function getTraitUsePointers(File $phpcsFile, int $classPointer):
110110
*/
111111
private static function getAllClassPointers(File $phpcsFile): array
112112
{
113-
$lazyValue = static function () use ($phpcsFile): array {
114-
return TokenHelper::findNextAll($phpcsFile, TokenHelper::$typeWithAnonymousClassKeywordTokenCodes, 0);
115-
};
113+
$lazyValue = static fn (): array => TokenHelper::findNextAll($phpcsFile, TokenHelper::$typeWithAnonymousClassKeywordTokenCodes, 0);
116114

117115
return SniffLocalCache::getAndSetIfNotCached($phpcsFile, 'classPointers', $lazyValue);
118116
}

SlevomatCodingStandard/Helpers/Comment.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
class Comment
99
{
1010

11-
/** @var int */
12-
private $pointer;
11+
private int $pointer;
1312

14-
/** @var string */
15-
private $content;
13+
private string $content;
1614

1715
public function __construct(int $pointer, string $content)
1816
{

0 commit comments

Comments
 (0)