Skip to content

Commit 531d57e

Browse files
committed
cover class constants in StringClassNameToClassConstantRector, as no reason to skip them
1 parent 229a5f9 commit 531d57e

5 files changed

Lines changed: 38 additions & 35 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\Fixture;
4+
5+
final class IncludeClassConst
6+
{
7+
const SKIP_TYPES = [
8+
'Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\Source\SomeUser'
9+
];
10+
}
11+
12+
?>
13+
-----
14+
<?php
15+
16+
namespace Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\Fixture;
17+
18+
final class IncludeClassConst
19+
{
20+
const SKIP_TYPES = [
21+
\Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\Source\SomeUser::class
22+
];
23+
}
24+
25+
?>

rules-tests/Php55/Rector/String_/StringClassNameToClassConstantRector/Fixture/skip_dynamic_variable.php.inc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\Fixture;
44

5-
class SkipDynamicVariable
5+
final class SkipDynamicVariable
66
{
77
public function bar()
88
{
@@ -12,4 +12,13 @@ class SkipDynamicVariable
1212
${'field'.$i} = $employee->data['dd'.$i];
1313
}
1414
}
15-
}
15+
16+
public function foo()
17+
{
18+
$dd1 = 1;
19+
20+
for ($i=1; $i <= 2; $i++) {
21+
${'field'.$i} = ${'dd'.$i};
22+
}
23+
}
24+
}

rules-tests/Php55/Rector/String_/StringClassNameToClassConstantRector/Fixture/skip_dynamic_variable2.php.inc

Lines changed: 0 additions & 15 deletions
This file was deleted.

rules-tests/Php55/Rector/String_/StringClassNameToClassConstantRector/Fixture/skip_in_array_constant.php.inc

Lines changed: 0 additions & 10 deletions
This file was deleted.

rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PhpParser\Node\Expr\FuncCall;
1111
use PhpParser\Node\Name\FullyQualified;
1212
use PhpParser\Node\Scalar\String_;
13-
use PhpParser\Node\Stmt\ClassConst;
1413
use PhpParser\NodeVisitor;
1514
use PHPStan\Reflection\ReflectionProvider;
1615
use Rector\Contract\Rector\ConfigurableRectorInterface;
@@ -89,20 +88,15 @@ public function run()
8988
*/
9089
public function getNodeTypes(): array
9190
{
92-
return [String_::class, FuncCall::class, ClassConst::class];
91+
return [String_::class, FuncCall::class];
9392
}
9493

9594
/**
96-
* @param String_|FuncCall|ClassConst $node
95+
* @param String_|FuncCall $node
9796
* @return Concat|ClassConstFetch|null|NodeVisitor::DONT_TRAVERSE_CHILDREN
9897
*/
9998
public function refactor(Node $node): Concat|ClassConstFetch|null|int
10099
{
101-
// allow class strings to be part of class const arrays, as probably on purpose
102-
if ($node instanceof ClassConst) {
103-
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
104-
}
105-
106100
// keep allowed string as condition
107101
if ($node instanceof FuncCall) {
108102
if ($this->isName($node, 'is_a')) {

0 commit comments

Comments
 (0)