diff --git a/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php b/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php index 5dada4970d49..7bc87eb4ffbd 100644 --- a/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php +++ b/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php @@ -5,6 +5,7 @@ use PhpParser\Node; use PhpParser\Node\Expr; +use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\BinaryOp\BooleanAnd; use PhpParser\Node\Expr\PropertyFetch; @@ -14,13 +15,11 @@ use PhpParser\Node\Stmt\Else_; use PhpParser\Node\Stmt\If_; use PhpParser\NodeTraverser; -use PHPStan\Reflection\ClassReflection; use PHPStan\Type\Constant\ConstantBooleanType; use Rector\DeadCode\NodeAnalyzer\SafeLeftTypeBooleanAndOrAnalyzer; use Rector\NodeAnalyzer\ExprAnalyzer; use Rector\PhpParser\Node\BetterNodeFinder; use Rector\Rector\AbstractRector; -use Rector\Reflection\ReflectionResolver; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** @@ -28,11 +27,6 @@ */ final class RemoveAlwaysTrueIfConditionRector extends AbstractRector { - /** - * @readonly - * @var \Rector\Reflection\ReflectionResolver - */ - private $reflectionResolver; /** * @readonly * @var \Rector\NodeAnalyzer\ExprAnalyzer @@ -48,9 +42,8 @@ final class RemoveAlwaysTrueIfConditionRector extends AbstractRector * @var \Rector\DeadCode\NodeAnalyzer\SafeLeftTypeBooleanAndOrAnalyzer */ private $safeLeftTypeBooleanAndOrAnalyzer; - public function __construct(ReflectionResolver $reflectionResolver, ExprAnalyzer $exprAnalyzer, BetterNodeFinder $betterNodeFinder, SafeLeftTypeBooleanAndOrAnalyzer $safeLeftTypeBooleanAndOrAnalyzer) + public function __construct(ExprAnalyzer $exprAnalyzer, BetterNodeFinder $betterNodeFinder, SafeLeftTypeBooleanAndOrAnalyzer $safeLeftTypeBooleanAndOrAnalyzer) { - $this->reflectionResolver = $reflectionResolver; $this->exprAnalyzer = $exprAnalyzer; $this->betterNodeFinder = $betterNodeFinder; $this->safeLeftTypeBooleanAndOrAnalyzer = $safeLeftTypeBooleanAndOrAnalyzer; @@ -113,7 +106,7 @@ public function refactor(Node $node) if (!$conditionStaticType->getValue()) { return null; } - if ($this->shouldSkipPropertyFetch($node->cond)) { + if ($this->shouldSkipExpr($node->cond)) { return null; } if ($this->shouldSkipFromParam($node->cond)) { @@ -139,26 +132,9 @@ private function shouldSkipFromParam(Expr $expr) : bool } return \false; } - private function shouldSkipPropertyFetch(Expr $expr) : bool + private function shouldSkipExpr(Expr $expr) : bool { - /** @var PropertyFetch[]|StaticPropertyFetch[] $propertyFetches */ - $propertyFetches = $this->betterNodeFinder->findInstancesOf($expr, [PropertyFetch::class, StaticPropertyFetch::class]); - foreach ($propertyFetches as $propertyFetch) { - $classReflection = $this->reflectionResolver->resolveClassReflectionSourceObject($propertyFetch); - if (!$classReflection instanceof ClassReflection) { - // cannot get parent Trait_ from Property Fetch - return \true; - } - $propertyName = (string) $this->nodeNameResolver->getName($propertyFetch); - if (!$classReflection->hasNativeProperty($propertyName)) { - continue; - } - $nativeProperty = $classReflection->getNativeProperty($propertyName); - if (!$nativeProperty->hasNativeType()) { - return \true; - } - } - return \false; + return (bool) $this->betterNodeFinder->findInstancesOf($expr, [PropertyFetch::class, StaticPropertyFetch::class, ArrayDimFetch::class]); } private function refactorIfWithBooleanAnd(If_ $if) : ?If_ { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 2f2a90dad316..3540091fa738 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'e5037921c408b717756a3997e8111ae3729aef08'; + public const PACKAGE_VERSION = '91ed251a8c450a776ec4b739c735b4bd6f9bf8d5'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-04-03 19:03:00'; + public const RELEASE_DATE = '2024-04-03 19:11:18'; /** * @var int */