Skip to content

Commit c6de4a5

Browse files
committed
include override in cild class
1 parent 886ae80 commit c6de4a5

6 files changed

Lines changed: 103 additions & 1 deletion

File tree

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+
?>
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\ChildClassNotWithConstant;
8+
9+
final class SkipUnknownClass
10+
{
11+
public function run($classWithConstants)
12+
{
13+
return $classWithConstants::ORIGINAL_VALUE;
14+
}
15+
}
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+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace 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
}

rules/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)