diff --git a/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php b/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php index 5be6f7bf070..31cf36c56ee 100644 --- a/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php +++ b/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php @@ -14,7 +14,6 @@ use PhpParser\Node\Stmt\Return_; use PHPStan\Analyser\Scope; use PHPStan\Reflection\FunctionReflection; -use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\MixedType; use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Core\NodeAnalyzer\CallAnalyzer; @@ -33,8 +32,7 @@ final class SimplifyUselessVariableRector extends AbstractScopeAwareRector public function __construct( private readonly AssignAndBinaryMap $assignAndBinaryMap, private readonly VariableAnalyzer $variableAnalyzer, - private readonly CallAnalyzer $callAnalyzer, - private readonly ReflectionProvider $reflectionProvider + private readonly CallAnalyzer $callAnalyzer ) { } @@ -167,7 +165,7 @@ private function shouldSkipStmt(Return_ $return, Stmt $previousStmt, Scope $scop /** @var Variable $previousVar */ $previousVar = $previousNode->var; - if ($this->callAnalyzer->isNewInstance($previousVar, $this->reflectionProvider)) { + if ($this->callAnalyzer->isNewInstance($previousVar)) { return true; } diff --git a/src/NodeAnalyzer/CallAnalyzer.php b/src/NodeAnalyzer/CallAnalyzer.php index 305b0fe790e..92733ad700b 100644 --- a/src/NodeAnalyzer/CallAnalyzer.php +++ b/src/NodeAnalyzer/CallAnalyzer.php @@ -24,6 +24,10 @@ final class CallAnalyzer */ private const OBJECT_CALL_TYPES = [MethodCall::class, NullsafeMethodCall::class, StaticCall::class]; + public function __construct(private readonly ReflectionProvider $reflectionProvider) + { + } + public function isObjectCall(Expr $expr): bool { if ($expr instanceof BooleanNot) { @@ -60,7 +64,7 @@ public function doesIfHasObjectCall(array $ifs): bool return false; } - public function isNewInstance(Variable $variable, ReflectionProvider $reflectionProvider): bool + public function isNewInstance(Variable $variable): bool { $scope = $variable->getAttribute(AttributeKey::SCOPE); if (! $scope instanceof Scope) { @@ -73,11 +77,11 @@ public function isNewInstance(Variable $variable, ReflectionProvider $reflection } $className = $type->getClassName(); - if (! $reflectionProvider->hasClass($className)) { + if (! $this->reflectionProvider->hasClass($className)) { return false; } - $classReflection = $reflectionProvider->getClass($className); + $classReflection = $this->reflectionProvider->getClass($className); return $classReflection->getNativeReflection() ->isInstantiable(); }