Skip to content

Commit 79ff8a6

Browse files
committed
[DeadCode] Skip RemoveAlwaysTrueIfConditionRector on inline HTML stmts
Unwrapping an always-true if whose body is inline HTML drops the close-tag transition and prints invalid PHP (inline HTML emitted inside PHP mode).
1 parent 545452a commit 79ff8a6

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php if (true) { ?>
2+
<div>always</div>
3+
<?php }

‎rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PhpParser\Node\Stmt;
1919
use PhpParser\Node\Stmt\Else_;
2020
use PhpParser\Node\Stmt\If_;
21+
use PhpParser\Node\Stmt\InlineHTML;
2122
use PhpParser\NodeVisitor;
2223
use PHPStan\Analyser\Scope;
2324
use PHPStan\Reflection\ClassReflection;
@@ -122,6 +123,13 @@ public function refactor(Node $node): int|null|array|If_
122123
return null;
123124
}
124125

126+
// unwrapping inline HTML stmts would drop the close-tag transition and break the file
127+
foreach ($node->stmts as $stmt) {
128+
if ($stmt instanceof InlineHTML) {
129+
return null;
130+
}
131+
}
132+
125133
if ($this->shouldSkipExpr($node->cond)) {
126134
return null;
127135
}

0 commit comments

Comments
 (0)