diff --git a/rules-tests/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_mixed_fallback_null_on_trait.php.inc b/rules-tests/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_mixed_fallback_null_on_trait.php.inc new file mode 100644 index 00000000000..a46f037c35f --- /dev/null +++ b/rules-tests/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_mixed_fallback_null_on_trait.php.inc @@ -0,0 +1,26 @@ + + */ + private $dispatchesEvents; + + protected function fireResourceEvent(string $event, Model $model, mixed ...$args): void + { + if ($this->silent) { + return; + } + + $event = $this->dispatchesEvents[$event] ?? null; + + if (is_null($event)) { + return; + } + + event(new $event($model, ...$args)); + } +} diff --git a/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php b/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php index f4b74f71ec6..4e0bae1fe97 100644 --- a/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php +++ b/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php @@ -22,6 +22,7 @@ use Rector\DeadCode\NodeAnalyzer\SafeLeftTypeBooleanAndOrAnalyzer; use Rector\NodeAnalyzer\ExprAnalyzer; use Rector\PhpParser\Node\BetterNodeFinder; +use Rector\PHPStan\ScopeFetcher; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -116,6 +117,11 @@ public function refactor(Node $node): int|null|array|If_ return null; } + $type = ScopeFetcher::fetch($node)->getNativeType($node->cond); + if (! $type->isTrue()->yes()) { + return null; + } + if ($node->stmts === []) { return NodeVisitor::REMOVE_NODE; }