Skip to content

Commit 3d85d22

Browse files
authored
[DeadCode] Skip with HTML on RemoveAlwaysTrueIfConditionRector (#8896)
1 parent d5fb89f commit 3d85d22

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$alwaysTrue = true;
6+
7+
if ($alwaysTrue): ?>
8+
<span>Always visible</span>
9+
<?php endif;

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,23 @@ public function getNodeTypes(): array
109109
*/
110110
public function refactor(Node $node): int|null|array|If_
111111
{
112-
if ($node->cond instanceof BooleanAnd) {
113-
return $this->refactorIfWithBooleanAnd($node);
114-
}
115-
116112
if ($node->else instanceof Else_) {
117113
return null;
118114
}
119115

120-
// just one if
116+
// not just one if
121117
if ($node->elseifs !== []) {
122118
return null;
123119
}
124120

121+
if ($this->getFile()->containsHTML()) {
122+
return null;
123+
}
124+
125+
if ($node->cond instanceof BooleanAnd) {
126+
return $this->refactorIfWithBooleanAnd($node);
127+
}
128+
125129
if ($this->shouldSkipExpr($node->cond)) {
126130
return null;
127131
}

0 commit comments

Comments
 (0)