diff --git a/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php b/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php index 31cf36c56ee..80e2ed12bee 100644 --- a/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php +++ b/rules/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector.php @@ -12,14 +12,12 @@ use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Return_; -use PHPStan\Analyser\Scope; -use PHPStan\Reflection\FunctionReflection; use PHPStan\Type\MixedType; use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Core\NodeAnalyzer\CallAnalyzer; use Rector\Core\NodeAnalyzer\VariableAnalyzer; use Rector\Core\PhpParser\Node\AssignAndBinaryMap; -use Rector\Core\Rector\AbstractScopeAwareRector; +use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -27,7 +25,7 @@ /** * @see \Rector\Tests\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector\SimplifyUselessVariableRectorTest */ -final class SimplifyUselessVariableRector extends AbstractScopeAwareRector +final class SimplifyUselessVariableRector extends AbstractRector { public function __construct( private readonly AssignAndBinaryMap $assignAndBinaryMap, @@ -67,7 +65,7 @@ public function getNodeTypes(): array /** * @param StmtsAwareInterface $node */ - public function refactorWithScope(Node $node, Scope $scope): ?Node + public function refactor(Node $node): ?Node { $stmts = $node->stmts; if ($stmts === null) { @@ -85,7 +83,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node } $previousStmt = $stmts[$key - 1]; - if ($this->shouldSkipStmt($stmt, $previousStmt, $scope)) { + if ($this->shouldSkipStmt($stmt, $previousStmt)) { return null; } @@ -127,17 +125,12 @@ private function processSimplifyUselessVariable( return $stmtsAware; } - private function shouldSkipStmt(Return_ $return, Stmt $previousStmt, Scope $scope): bool + private function shouldSkipStmt(Return_ $return, Stmt $previousStmt): bool { if (! $return->expr instanceof Variable) { return true; } - $functionReflection = $scope->getFunction(); - if ($functionReflection instanceof FunctionReflection && $functionReflection->returnsByReference()->yes()) { - return true; - } - if ($return->getAttribute(AttributeKey::IS_BYREF_RETURN) === true) { return true; }