Skip to content

Commit 2d8958e

Browse files
[DeadCode] Skip pipe operator on RemoveDeadStmtRector (#7941)
* [patch-3] Create void-return-functions-with-side-effects.php.inc the examples assert and passthru are void return functions with side effects and should not be removed * [DeadCode] Skip pipe operator on RemoveDeadStmtRector --------- Co-authored-by: Anna Damm <anna.damm@check24.de>
1 parent badcffc commit 2d8958e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-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\DeadCode\Rector\Expression\RemoveDeadStmtRector\Fixture;
4+
5+
is_string('foo')
6+
|> assert(...);
7+
8+
sprintf('echo "%s"', 'foo')
9+
|> passthru(...);
10+
11+
?>

rules-tests/DeadCode/Rector/Expression/RemoveDeadStmtRector/RemoveDeadStmtRectorTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ final class RemoveDeadStmtRectorTest extends AbstractRectorTestCase
1313
#[DataProvider('provideData')]
1414
public function test(string $filePath): void
1515
{
16+
if (str_ends_with($filePath, 'skip_pipe_operator.php.inc') && PHP_VERSION_ID < 80500) {
17+
$this->markTestSkipped('test contains php 8.5 syntax early before transformation');
18+
}
19+
1620
$this->doTestFile($filePath);
1721
}
1822

rules/DeadCode/NodeManipulator/LivingCodeManipulator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PhpParser\Node\Expr\BinaryOp\Coalesce;
1414
use PhpParser\Node\Expr\BinaryOp\LogicalAnd;
1515
use PhpParser\Node\Expr\BinaryOp\LogicalOr;
16+
use PhpParser\Node\Expr\BinaryOp\Pipe;
1617
use PhpParser\Node\Expr\BitwiseNot;
1718
use PhpParser\Node\Expr\BooleanNot;
1819
use PhpParser\Node\Expr\Cast;
@@ -120,7 +121,8 @@ private function isBinaryOpWithoutChange(Expr $expr): bool
120121
$expr instanceof BooleanAnd ||
121122
$expr instanceof LogicalOr ||
122123
$expr instanceof BooleanOr ||
123-
$expr instanceof Coalesce
124+
$expr instanceof Coalesce ||
125+
$expr instanceof Pipe
124126
);
125127
}
126128

0 commit comments

Comments
 (0)