Skip to content

Commit 1d7a05f

Browse files
authored
[code-quality] Add VariableConstFetchToClassConstFetchRector (#7457)
* remove deprecated ConvertStaticPrivateConstantToSelfRector * [code-quality] Add VariableConstFetchToClassConstFetchRector * include override in cild class
1 parent 33bb8a6 commit 1d7a05f

File tree

18 files changed

+344
-98
lines changed

18 files changed

+344
-98
lines changed

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
"composer/pcre": "^3.3.0",
1818
"composer/semver": "^3.4",
1919
"composer/xdebug-handler": "^3.0.5",
20-
"doctrine/inflector": "^2.0.10",
21-
"illuminate/container": "^11.45",
20+
"doctrine/inflector": "^2.1",
21+
"illuminate/container": "^11.46",
2222
"nette/utils": "^4.0",
2323
"nikic/php-parser": "^5.6.1",
2424
"ocramius/package-versions": "^2.10",
2525
"ondram/ci-detector": "^4.2",
26-
"phpstan/phpdoc-parser": "^2.2",
26+
"phpstan/phpdoc-parser": "^2.3",
2727
"phpstan/phpstan": "^2.1.26",
2828
"react/event-loop": "^1.5",
29-
"react/promise": "^3.2",
29+
"react/promise": "^3.3",
3030
"react/socket": "^1.16",
3131
"rector/extension-installer": "^0.11.2",
3232
"rector/rector-doctrine": "dev-main",
@@ -44,7 +44,7 @@
4444
},
4545
"require-dev": {
4646
"php-parallel-lint/php-parallel-lint": "^1.4",
47-
"phpecs/phpecs": "^2.1",
47+
"phpecs/phpecs": "^2.2",
4848
"phpstan/extension-installer": "^1.4",
4949
"phpstan/phpstan-deprecation-rules": "^2.0",
5050
"phpstan/phpstan-phpunit": "^2.0",
@@ -56,8 +56,8 @@
5656
"rector/type-perfect": "^2.1",
5757
"shipmonk/composer-dependency-analyser": "^1.8",
5858
"symplify/phpstan-extensions": "^12.0",
59-
"symplify/phpstan-rules": "^14.6.11",
60-
"symplify/vendor-patches": "^11.4",
59+
"symplify/phpstan-rules": "^14.8",
60+
"symplify/vendor-patches": "^11.5",
6161
"tomasvotruba/class-leak": "^2.0",
6262
"tracy/tracy": "^2.10"
6363
},

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,8 @@ parameters:
345345
-
346346
identifier: symplify.noReference
347347
message: '#Use explicit return value over magic &reference#'
348+
349+
# false positive
350+
-
351+
identifier: offsetAccess.invalidOffset
352+
path: src/CustomRules/SimpleNodeDumper.php
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Fixture;
6+
7+
use Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ChildClassNotWithConstant;
8+
9+
final class AllowOverride
10+
{
11+
public function run(ChildClassNotWithConstant $classWithConstants)
12+
{
13+
return $classWithConstants::ORIGINAL_VALUE;
14+
}
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
declare(strict_types=1);
22+
23+
namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Fixture;
24+
25+
use Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ChildClassNotWithConstant;
26+
27+
final class AllowOverride
28+
{
29+
public function run(ChildClassNotWithConstant $classWithConstants)
30+
{
31+
return \Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ChildClassNotWithConstant::ORIGINAL_VALUE;
32+
}
33+
}
34+
35+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Fixture;
6+
7+
use Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ChildClassNotWithConstant;
8+
9+
final class ParentHopFetch
10+
{
11+
public function run(ChildClassNotWithConstant $classWithConstants)
12+
{
13+
return $classWithConstants::NAME;
14+
}
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
declare(strict_types=1);
22+
23+
namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Fixture;
24+
25+
use Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ChildClassNotWithConstant;
26+
27+
final class ParentHopFetch
28+
{
29+
public function run(ChildClassNotWithConstant $classWithConstants)
30+
{
31+
return \Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ChildClassNotWithConstant::NAME;
32+
}
33+
}
34+
35+
?>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Fixture;
6+
7+
use Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ChildClassNotWithConstant;
8+
9+
final class SkipDocType
10+
{
11+
/**
12+
* @param ChildClassNotWithConstant $classWithConstants
13+
*/
14+
public function run($classWithConstants)
15+
{
16+
return $classWithConstants::ORIGINAL_VALUE;
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Fixture;
6+
7+
use Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ClassWithConstants;
8+
9+
final class SkipDynamicName
10+
{
11+
public function run(ClassWithConstants $classWithConstants, $dynamic)
12+
{
13+
return $classWithConstants::$dynamic;
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Fixture;
6+
7+
use Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ClassWithConstants;
8+
9+
final class SkipKnownClass
10+
{
11+
public function run()
12+
{
13+
return ClassWithConstants::NAME;
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Fixture;
6+
7+
final class SkipUnknownClass
8+
{
9+
public function run($classWithConstants)
10+
{
11+
return $classWithConstants::ORIGINAL_VALUE;
12+
}
13+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Fixture;
6+
7+
use Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ClassWithConstants;
8+
9+
final class SomeClass
10+
{
11+
public function run(ClassWithConstants $classWithConstants)
12+
{
13+
return $classWithConstants::NAME;
14+
}
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
declare(strict_types=1);
22+
23+
namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Fixture;
24+
25+
use Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ClassWithConstants;
26+
27+
final class SomeClass
28+
{
29+
public function run(ClassWithConstants $classWithConstants)
30+
{
31+
return \Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ClassWithConstants::NAME;
32+
}
33+
}
34+
35+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source;
6+
7+
final class ChildClassNotWithConstant extends ClassWithConstants
8+
{
9+
public const ORIGINAL_VALUE = 456;
10+
}

0 commit comments

Comments
 (0)