Skip to content

Commit

Permalink
[DeadCode] Skip union falsy mixed on trait on RecastingRemovalRector (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik authored Feb 5, 2025
1 parent a4c489e commit 95a145f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

trait SkipUnionFalsyMixedOnTrait
{
public function run(bool $param): bool
{
return (bool) ($this->config['allow_404'] ?? false);
}
}
11 changes: 11 additions & 0 deletions rules/DeadCode/Rector/Cast/RecastingRemovalRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
use Rector\NodeAnalyzer\ExprAnalyzer;
use Rector\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -142,6 +143,16 @@ private function shouldSkipCall(Expr $expr): bool

private function shouldSkip(Expr $expr): bool
{
$type = $this->getType($expr);

if ($type instanceof UnionType) {
foreach ($type->getTypes() as $unionedType) {
if ($unionedType instanceof MixedType) {
return true;
}
}
}

if (! $this->propertyFetchAnalyzer->isPropertyFetch($expr)) {
return $this->exprAnalyzer->isNonTypedFromParam($expr);
}
Expand Down

0 comments on commit 95a145f

Please sign in to comment.