Skip to content

Commit 0e8e070

Browse files
authored
[CodeQuality] Skip non-variable fetch on VariableConstFetchToClassConstFetchRector as may cause side effect (#7464)
* [CodeQuality] Skip non-variable fetch on VariableConstFetchToClassConstFetchRector as may cause side effect * Fix
1 parent cc7b45e commit 0e8e070

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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\ClassWithSideEffect;
8+
9+
final class SkipNonVariable
10+
{
11+
function sideEffect(): ClassWithSideEffect
12+
{
13+
return new ClassWithSideEffect();
14+
}
15+
16+
public function run()
17+
{
18+
echo $this->sideEffect()::SOME_VALUE;
19+
}
20+
}
Lines changed: 15 additions & 0 deletions
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\Source;
6+
7+
class ClassWithSideEffect
8+
{
9+
public const SOME_VALUE = 'value';
10+
11+
public function __construct()
12+
{
13+
echo 'side effect ';
14+
}
15+
}

rules/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace Rector\CodeQuality\Rector\ClassConstFetch;
66

77
use PhpParser\Node;
8-
use PhpParser\Node\Expr;
98
use PhpParser\Node\Expr\ClassConstFetch;
9+
use PhpParser\Node\Expr\Variable;
1010
use PhpParser\Node\Identifier;
1111
use PhpParser\Node\Name\FullyQualified;
1212
use PHPStan\Type\ObjectType;
@@ -62,7 +62,7 @@ public function getNodeTypes(): array
6262
*/
6363
public function refactor(Node $node): ?ClassConstFetch
6464
{
65-
if (! $node->class instanceof Expr) {
65+
if (! $node->class instanceof Variable) {
6666
return null;
6767
}
6868

0 commit comments

Comments
 (0)