Skip to content

Commit 7992126

Browse files
committed
[PHP 8.3] Make use of typed constants
1 parent a8bb550 commit 7992126

186 files changed

Lines changed: 736 additions & 1205 deletions

File tree

Some content is hidden

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

build/build-preload.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final class PreloadBuilder
4646
/**
4747
* @var string
4848
*/
49-
private const PRELOAD_FILE_TEMPLATE = <<<'CODE_SAMPLE'
49+
private const string PRELOAD_FILE_TEMPLATE = <<<'CODE_SAMPLE'
5050
<?php
5151
5252
declare(strict_types=1);
@@ -78,15 +78,15 @@ function isPHPStanTestPreloaded(): bool
7878
/**
7979
* @var int
8080
*/
81-
private const PRIORITY_LESS_FILE_POSITION = -1;
81+
private const int PRIORITY_LESS_FILE_POSITION = -1;
8282

8383
/**
8484
* These files are parent to another files, so they have to be included first
8585
* See https://github.com/rectorphp/rector/issues/6709 for more
8686
*
8787
* @var string[]
8888
*/
89-
private const HIGH_PRIORITY_FILES = [
89+
private const array HIGH_PRIORITY_FILES = [
9090
// nikic/php-parser
9191
'Node.php',
9292
'NodeAbstract.php',
@@ -131,7 +131,7 @@ function isPHPStanTestPreloaded(): bool
131131
*
132132
* @var string[]
133133
*/
134-
private const IN_USE_CLASS_FILES = [
134+
private const array IN_USE_CLASS_FILES = [
135135
'Node/Expr/ArrayItem.php',
136136
'Node/Expr/ClosureUse.php',
137137
'Node/Scalar/EncapsedStringPart.php',

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"phpstan/phpstan-phpunit": "^2.0",
5151
"phpstan/phpstan-webmozart-assert": "^2.0",
5252
"phpunit/phpunit": "^11.5|^12.0",
53-
"rector/jack": "^0.4",
53+
"rector/jack": "^0.5",
5454
"rector/release-notes-generator": "^0.5.1",
5555
"rector/swiss-knife": "^2.3",
5656
"rector/type-perfect": "^2.1.2",

rector.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Rector\Config\RectorConfig;
77
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
88
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
9+
use Rector\Php83\Rector\ClassConst\AddTypeToConstRector;
910
use Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector;
1011
use Rector\Utils\Rector\RemoveRefactorDuplicatedNodeInstanceCheckRector;
1112

@@ -39,7 +40,13 @@
3940
])
4041
->withRootFiles()
4142
->withImportNames(removeUnusedImports: true)
42-
->withRules([RemoveRefactorDuplicatedNodeInstanceCheckRector::class, AddSeeTestAnnotationRector::class])
43+
->withRules(
44+
[
45+
RemoveRefactorDuplicatedNodeInstanceCheckRector::class,
46+
AddSeeTestAnnotationRector::class,
47+
AddTypeToConstRector::class,
48+
]
49+
)
4350
->withSkip([
4451
StringClassNameToClassConstantRector::class,
4552
// tests

rules/Arguments/NodeAnalyzer/ArgumentAddingScope.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
* @api
1919
* @var string
2020
*/
21-
public const SCOPE_PARENT_CALL = 'parent_call';
21+
public const string SCOPE_PARENT_CALL = 'parent_call';
2222

2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const SCOPE_METHOD_CALL = 'method_call';
27+
public const string SCOPE_METHOD_CALL = 'method_call';
2828

2929
/**
3030
* @api
3131
* @var string
3232
*/
33-
public const SCOPE_CLASS_METHOD = 'class_method';
33+
public const string SCOPE_CLASS_METHOD = 'class_method';
3434

3535
public function __construct(
3636
private NodeNameResolver $nodeNameResolver

rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* @var string
1515
*/
16-
public const ANY_VALUE_BEFORE = '*ANY_VALUE_BEFORE*';
16+
public const string ANY_VALUE_BEFORE = '*ANY_VALUE_BEFORE*';
1717

1818
/**
1919
* @param int<0, max> $position

rules/Assert/Enum/AssertClassName.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ final class AssertClassName
99
/**
1010
* @var string
1111
*/
12-
public const WEBMOZART = 'Webmozart\Assert\Assert';
12+
public const string WEBMOZART = 'Webmozart\Assert\Assert';
1313

1414
/**
1515
* @var string
1616
*/
17-
public const BEBERLEI = 'Assert\Assertion';
17+
public const string BEBERLEI = 'Assert\Assertion';
1818
}

rules/Carbon/NodeFactory/CarbonCallFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ final class CarbonCallFactory
1919
* @var string
2020
* @see https://regex101.com/r/LLMrFw/1
2121
*/
22-
private const PLUS_MINUS_COUNT_REGEX = '#(?<operator>\+|-)(\\s+)?(?<count>\\d+)(\s+)?(?<unit>seconds|second|sec|minutes|minute|min|hours|hour|days|day|weeks|week|months|month|years|year)#';
22+
private const string PLUS_MINUS_COUNT_REGEX = '#(?<operator>\+|-)(\\s+)?(?<count>\\d+)(\s+)?(?<unit>seconds|second|sec|minutes|minute|min|hours|hour|days|day|weeks|week|months|month|years|year)#';
2323

2424
/**
2525
* @var string
2626
* @see https://regex101.com/r/IhxHTO/1
2727
*/
28-
private const STATIC_DATE_REGEX = '#now|yesterday|today|tomorrow#';
28+
private const string STATIC_DATE_REGEX = '#now|yesterday|today|tomorrow#';
2929

3030
public function createFromDateTimeString(
3131
FullyQualified $carbonFullyQualified,

rules/Carbon/Rector/FuncCall/DateFuncCallToCarbonRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
final class DateFuncCallToCarbonRector extends AbstractRector
2626
{
27-
private const TIME_UNITS = [
27+
private const array TIME_UNITS = [
2828
['weeks', 604800],
2929
['days', 86400],
3030
['hours', 3600],

rules/CodeQuality/NodeAnalyzer/LocalPropertyAnalyzer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/**
3232
* @var string
3333
*/
34-
private const LARAVEL_COLLECTION_CLASS = 'Illuminate\Support\Collection';
34+
private const string LARAVEL_COLLECTION_CLASS = 'Illuminate\Support\Collection';
3535

3636
public function __construct(
3737
private SimpleCallableNodeTraverser $simpleCallableNodeTraverser,

rules/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class ThrowWithPreviousExceptionRector extends AbstractRector
3232
/**
3333
* @var int
3434
*/
35-
private const DEFAULT_EXCEPTION_ARGUMENT_POSITION = 2;
35+
private const int DEFAULT_EXCEPTION_ARGUMENT_POSITION = 2;
3636

3737
public function __construct(
3838
private readonly ReflectionProvider $reflectionProvider

0 commit comments

Comments
 (0)