Skip to content

Commit 0acd09f

Browse files
committed
skip in binary op
1 parent 7e86548 commit 0acd09f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeSubstrFalsyRector\Fixture;
4+
5+
class SkipInBinaryOp
6+
{
7+
public function run($a)
8+
{
9+
return substr("a", 2) && $a === true;
10+
}
11+
}

rules/DowngradePhp80/Rector/FuncCall/DowngradeSubstrFalsyRector.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpParser\Node\Expr;
1111
use PhpParser\Node\Expr\ArrayDimFetch;
1212
use PhpParser\Node\Expr\AssignOp;
13+
use PhpParser\Node\Expr\BinaryOp;
1314
use PhpParser\Node\Expr\BinaryOp\Concat;
1415
use PhpParser\Node\Expr\BinaryOp\Identical;
1516
use PhpParser\Node\Expr\BooleanNot;
@@ -81,12 +82,13 @@ public function getNodeTypes(): array
8182
Do_::class,
8283
ArrayItem::class,
8384
ArrayDimFetch::class,
85+
BinaryOp::class,
8486
FuncCall::class,
8587
];
8688
}
8789

8890
/**
89-
* @param Cast|Empty_|BooleanNot|Ternary|Identical|Concat|MethodCall|StaticCall|AssignOp|If_|While_|Do_|ArrayItem|ArrayDimFetch|FuncCall $node
91+
* @param Cast|Empty_|BooleanNot|Ternary|Identical|Concat|MethodCall|StaticCall|AssignOp|If_|While_|Do_|ArrayItem|ArrayDimFetch|BinaryOp|FuncCall $node
9092
*/
9193
public function refactor(Node $node): ?Node
9294
{
@@ -142,6 +144,12 @@ public function refactor(Node $node): ?Node
142144
return null;
143145
}
144146

147+
if ($node instanceof BinaryOp) {
148+
$node->left->setAttribute(self::IS_UNCASTABLE, true);
149+
$node->right->setAttribute(self::IS_UNCASTABLE, true);
150+
return null;
151+
}
152+
145153
if ($node instanceof CallLike) {
146154
if ($node->isFirstClassCallable()) {
147155
return null;

0 commit comments

Comments
 (0)