Skip to content

Commit bc675f0

Browse files
authored
[PHP 8.3] Make use of typed constants (#7839)
* [PHP 8.3] Remove docblock if useless in AddTypeToConstRector to avoid duplicated leftovers" * fixup! [PHP 8.3] Remove docblock if useless in AddTypeToConstRector to avoid duplicated leftovers" * [PHP 8.3] Make use of typed constants
1 parent a8bb550 commit bc675f0

File tree

187 files changed

+790
-1978
lines changed

Some content is hidden

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

187 files changed

+790
-1978
lines changed

build/build-preload.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@
4343

4444
final class PreloadBuilder
4545
{
46-
/**
47-
* @var string
48-
*/
49-
private const PRELOAD_FILE_TEMPLATE = <<<'CODE_SAMPLE'
46+
private const string PRELOAD_FILE_TEMPLATE = <<<'CODE_SAMPLE'
5047
<?php
5148
5249
declare(strict_types=1);
@@ -75,18 +72,15 @@ function isPHPStanTestPreloaded(): bool
7572
}
7673
CODE_SAMPLE;
7774

78-
/**
79-
* @var int
80-
*/
81-
private const PRIORITY_LESS_FILE_POSITION = -1;
75+
private const int PRIORITY_LESS_FILE_POSITION = -1;
8276

8377
/**
8478
* These files are parent to another files, so they have to be included first
8579
* See https://github.com/rectorphp/rector/issues/6709 for more
8680
*
8781
* @var string[]
8882
*/
89-
private const HIGH_PRIORITY_FILES = [
83+
private const array HIGH_PRIORITY_FILES = [
9084
// nikic/php-parser
9185
'Node.php',
9286
'NodeAbstract.php',
@@ -131,7 +125,7 @@ function isPHPStanTestPreloaded(): bool
131125
*
132126
* @var string[]
133127
*/
134-
private const IN_USE_CLASS_FILES = [
128+
private const array IN_USE_CLASS_FILES = [
135129
'Node/Expr/ArrayItem.php',
136130
'Node/Expr/ClosureUse.php',
137131
'Node/Scalar/EncapsedStringPart.php',

rector.php

Lines changed: 5 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,10 @@
3940
])
4041
->withRootFiles()
4142
->withImportNames(removeUnusedImports: true)
42-
->withRules([RemoveRefactorDuplicatedNodeInstanceCheckRector::class, AddSeeTestAnnotationRector::class])
43+
->withRules([
44+
RemoveRefactorDuplicatedNodeInstanceCheckRector::class, AddSeeTestAnnotationRector::class,
45+
AddTypeToConstRector::class,
46+
])
4347
->withSkip([
4448
StringClassNameToClassConstantRector::class,
4549
// tests
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php83\Rector\ClassConst\AddTypeToConstRector\Fixture;
4+
5+
final class RemoveDocBlockAsUseless
6+
{
7+
/**
8+
* @var int
9+
*/
10+
private const A = 1000;
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\Php83\Rector\ClassConst\AddTypeToConstRector\Fixture;
18+
19+
final class RemoveDocBlockAsUseless
20+
{
21+
private const int A = 1000;
22+
}
23+
24+
?>

rules/Arguments/NodeAnalyzer/ArgumentAddingScope.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,18 @@
1616
{
1717
/**
1818
* @api
19-
* @var string
2019
*/
21-
public const SCOPE_PARENT_CALL = 'parent_call';
20+
public const string SCOPE_PARENT_CALL = 'parent_call';
2221

2322
/**
2423
* @api
25-
* @var string
2624
*/
27-
public const SCOPE_METHOD_CALL = 'method_call';
25+
public const string SCOPE_METHOD_CALL = 'method_call';
2826

2927
/**
3028
* @api
31-
* @var string
3229
*/
33-
public const SCOPE_CLASS_METHOD = 'class_method';
30+
public const string SCOPE_CLASS_METHOD = 'class_method';
3431

3532
public function __construct(
3633
private NodeNameResolver $nodeNameResolver

rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
final readonly class ReplaceArgumentDefaultValue implements ReplaceArgumentDefaultValueInterface
1212
{
13-
/**
14-
* @var string
15-
*/
16-
public const ANY_VALUE_BEFORE = '*ANY_VALUE_BEFORE*';
13+
public const string ANY_VALUE_BEFORE = '*ANY_VALUE_BEFORE*';
1714

1815
/**
1916
* @param int<0, max> $position

rules/Assert/Enum/AssertClassName.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@
66

77
final class AssertClassName
88
{
9-
/**
10-
* @var string
11-
*/
12-
public const WEBMOZART = 'Webmozart\Assert\Assert';
9+
public const string WEBMOZART = 'Webmozart\Assert\Assert';
1310

14-
/**
15-
* @var string
16-
*/
17-
public const BEBERLEI = 'Assert\Assertion';
11+
public const string BEBERLEI = 'Assert\Assertion';
1812
}

rules/Carbon/NodeFactory/CarbonCallFactory.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@
1616
final class CarbonCallFactory
1717
{
1818
/**
19-
* @var string
2019
* @see https://regex101.com/r/LLMrFw/1
2120
*/
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)#';
21+
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)#';
2322

2423
/**
25-
* @var string
2624
* @see https://regex101.com/r/IhxHTO/1
2725
*/
28-
private const STATIC_DATE_REGEX = '#now|yesterday|today|tomorrow#';
26+
private const string STATIC_DATE_REGEX = '#now|yesterday|today|tomorrow#';
2927

3028
public function createFromDateTimeString(
3129
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828

2929
final readonly class LocalPropertyAnalyzer
3030
{
31-
/**
32-
* @var string
33-
*/
34-
private const LARAVEL_COLLECTION_CLASS = 'Illuminate\Support\Collection';
31+
private const string LARAVEL_COLLECTION_CLASS = 'Illuminate\Support\Collection';
3532

3633
public function __construct(
3734
private SimpleCallableNodeTraverser $simpleCallableNodeTraverser,

rules/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929
*/
3030
final class ThrowWithPreviousExceptionRector extends AbstractRector
3131
{
32-
/**
33-
* @var int
34-
*/
35-
private const DEFAULT_EXCEPTION_ARGUMENT_POSITION = 2;
32+
private const int DEFAULT_EXCEPTION_ARGUMENT_POSITION = 2;
3633

3734
public function __construct(
3835
private readonly ReflectionProvider $reflectionProvider

0 commit comments

Comments
 (0)