Skip to content

Commit b45ad85

Browse files
committed
skip with concat
1 parent 221a2b9 commit b45ad85

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeSubstrFalsyRector\Fixture;
4+
5+
/**
6+
* falsy concat become empty string
7+
*/
8+
class SkipWithConcat
9+
{
10+
public function run()
11+
{
12+
return substr('a', 2) . substr('b', 2);
13+
}
14+
}

rules/DowngradePhp80/Rector/FuncCall/DowngradeSubstrFalsyRector.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Arg;
99
use PhpParser\Node\Expr;
10+
use PhpParser\Node\Expr\BinaryOp\Concat;
1011
use PhpParser\Node\Expr\BinaryOp\Identical;
1112
use PhpParser\Node\Expr\BooleanNot;
1213
use PhpParser\Node\Expr\Cast;
@@ -50,11 +51,11 @@ public function getRuleDefinition(): RuleDefinition
5051
*/
5152
public function getNodeTypes(): array
5253
{
53-
return [Cast::class, Empty_::class, BooleanNot::class, Ternary::class, Identical::class, FuncCall::class];
54+
return [Cast::class, Empty_::class, BooleanNot::class, Ternary::class, Identical::class, Concat::class, FuncCall::class];
5455
}
5556

5657
/**
57-
* @param Cast|Empty_|BooleanNot|Ternary|Identical|FuncCall $node
58+
* @param Cast|Empty_|BooleanNot|Ternary|Identical|Concat|FuncCall $node
5859
*/
5960
public function refactor(Node $node): ?Node
6061
{
@@ -71,6 +72,12 @@ public function refactor(Node $node): ?Node
7172
return null;
7273
}
7374

75+
if ($node instanceof Concat) {
76+
$node->left->setAttribute(self::IS_UNCASTABLE, true);
77+
$node->right->setAttribute(self::IS_UNCASTABLE, true);
78+
return null;
79+
}
80+
7481
if ($node instanceof Identical) {
7582
if ($this->valueResolver->isFalse($node->left)) {
7683
$node->right->setAttribute(self::IS_UNCASTABLE, true);

0 commit comments

Comments
 (0)