Rector version: 2.3.x
PHP version: 8.3.13
Problem
Rector crashes while processing a method that contains an if / elseif chain with empty branches.
Error:
PhpParser\Node\Expr\BinaryOp::__construct(): Argument #2 ($right) must be of type PhpParser\Node\Expr, null given
The stack trace points to:
vendor/rector/rector/rules/DeadCode/Rector/If_/RemoveDeadIfBlockRector.php:121
Expected behavior
Rector should safely skip the node or produce a valid transformation. It should not crash while constructing a BinaryOp.
Minimal reproduction
<?php
final class Demo
{
public function run(): void
{
$value = 1;
$flag = true;
if ($flag) {
} elseif ($value === 2) {
} elseif ($value === 3 || $value === 4) {
echo "matched";
}
}
}
Run Rector with dead code rules enabled:
vendor/bin/rector process demo.php --dry-run --debug
Notes
The crash happens during dead-code analysis of the if / elseif structure, specifically when Rector tries to remove dead branches.
Rector version:
2.3.xPHP version:
8.3.13Problem
Rector crashes while processing a method that contains an
if / elseifchain with empty branches.Error:
The stack trace points to:
Expected behavior
Rector should safely skip the node or produce a valid transformation. It should not crash while constructing a
BinaryOp.Minimal reproduction
Run Rector with dead code rules enabled:
Notes
The crash happens during dead-code analysis of the
if / elseifstructure, specifically when Rector tries to remove dead branches.