File tree Expand file tree Collapse file tree
rules-tests/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector
rules/CodeQuality/Rector/ClassConstFetch Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 number Diff line number Diff line change 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+ ?>
Original file line number Diff line number Diff line change 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 SkipUnknownClass
10+ {
11+ public function run ($ classWithConstants )
12+ {
13+ return $ classWithConstants ::ORIGINAL_VALUE ;
14+ }
15+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 11<?php
22
3+ declare (strict_types=1 );
4+
35namespace Rector \Tests \CodeQuality \Rector \ClassConstFetch \VariableConstFetchToClassConstFetchRector \Source ;
46
5- final class ClassWithConstants
7+ class ClassWithConstants
68{
79 public const NAME = 'SomeName ' ;
10+
11+ public const ORIGINAL_VALUE = 123 ;
812}
Original file line number Diff line number Diff line change @@ -69,6 +69,9 @@ public function refactor(Node $node): ?ClassConstFetch
6969 }
7070
7171 $ constantName = $ this ->getName ($ node ->name );
72+ if (! is_string ($ constantName )) {
73+ return null ;
74+ }
7275
7376 $ classObjectType = $ this ->getType ($ node ->class );
7477 if (! $ classObjectType instanceof ObjectType) {
You can’t perform that action at this time.
0 commit comments