diff --git a/composer.json b/composer.json index 3236c8e5..592d71be 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "phpstan/phpstan": "^1.10", "phpstan/phpstan-webmozart-assert": "^1.2", "phpunit/phpunit": "^10.5", - "rector/rector-src": "dev-main", + "rector/rector-src": "dev-main#e30c7af", "rector/type-perfect": "^1.0", "symplify/easy-coding-standard": "^12.3", "symplify/phpstan-extensions": "^11.4", diff --git a/rules/DowngradePhp72/Rector/FuncCall/DowngradeStreamIsattyRector.php b/rules/DowngradePhp72/Rector/FuncCall/DowngradeStreamIsattyRector.php index 9583890a..f5b6c40b 100644 --- a/rules/DowngradePhp72/Rector/FuncCall/DowngradeStreamIsattyRector.php +++ b/rules/DowngradePhp72/Rector/FuncCall/DowngradeStreamIsattyRector.php @@ -20,7 +20,8 @@ use Rector\NodeAnalyzer\ExprInTopStmtMatcher; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PhpParser\Parser\InlineCodeParser; -use Rector\Rector\AbstractScopeAwareRector; +use Rector\PHPStan\ScopeFetcher; +use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -29,7 +30,7 @@ * * @see \Rector\Tests\DowngradePhp72\Rector\FuncCall\DowngradeStreamIsattyRector\DowngradeStreamIsattyRectorTest */ -final class DowngradeStreamIsattyRector extends AbstractScopeAwareRector +final class DowngradeStreamIsattyRector extends AbstractRector { private ?Closure $cachedClosure = null; @@ -99,7 +100,7 @@ public function getNodeTypes(): array * @param StmtsAwareInterface|Switch_|Return_|Expression|Echo_ $node * @return Node[]|null */ - public function refactorWithScope(Node $node, Scope $scope): ?array + public function refactor(Node $node): ?array { $expr = $this->exprInTopStmtMatcher->match( $node, @@ -128,6 +129,8 @@ function (Node $subNode): bool { $function = $this->createClosure(); + $scope = ScopeFetcher::fetch($node); + $variable = new Variable($this->variableNaming->createCountedValueName('streamIsatty', $scope)); $assign = new Assign($variable, $function); diff --git a/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php b/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php index 9c65074d..2e08c378 100644 --- a/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php +++ b/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php @@ -13,13 +13,13 @@ use PhpParser\Node\Stmt\ClassConst; use PhpParser\Node\Stmt\ClassLike; use PHPStan\Analyser\MutatingScope; -use PHPStan\Analyser\Scope; use PHPStan\Type\Type; use Rector\DowngradePhp81\NodeAnalyzer\ArraySpreadAnalyzer; use Rector\DowngradePhp81\NodeFactory\ArrayMergeFromArraySpreadFactory; use Rector\PhpParser\AstResolver; use Rector\PhpParser\Node\BetterNodeFinder; -use Rector\Rector\AbstractScopeAwareRector; +use Rector\PHPStan\ScopeFetcher; +use Rector\Rector\AbstractRector; use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -29,7 +29,7 @@ * * @see \Rector\Tests\DowngradePhp74\Rector\Array_\DowngradeArraySpreadRector\DowngradeArraySpreadRectorTest */ -final class DowngradeArraySpreadRector extends AbstractScopeAwareRector +final class DowngradeArraySpreadRector extends AbstractRector { public function __construct( private readonly ArrayMergeFromArraySpreadFactory $arrayMergeFromArraySpreadFactory, @@ -98,7 +98,7 @@ public function getNodeTypes(): array /** * @param Array_|ClassConst $node */ - public function refactorWithScope(Node $node, Scope $scope): ?Node + public function refactor(Node $node): ?Node { if ($node instanceof ClassConst) { return $this->refactorUnderClassConst($node); @@ -109,6 +109,8 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node } /** @var MutatingScope $scope */ + $scope = ScopeFetcher::fetch($node); + return $this->arrayMergeFromArraySpreadFactory->createFromArray($node, $scope); } diff --git a/rules/DowngradePhp80/Rector/Catch_/DowngradeNonCapturingCatchesRector.php b/rules/DowngradePhp80/Rector/Catch_/DowngradeNonCapturingCatchesRector.php index 7dcb61b8..10bfd2f8 100644 --- a/rules/DowngradePhp80/Rector/Catch_/DowngradeNonCapturingCatchesRector.php +++ b/rules/DowngradePhp80/Rector/Catch_/DowngradeNonCapturingCatchesRector.php @@ -7,9 +7,9 @@ use PhpParser\Node; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\Catch_; -use PHPStan\Analyser\Scope; use Rector\Naming\Naming\VariableNaming; -use Rector\Rector\AbstractScopeAwareRector; +use Rector\PHPStan\ScopeFetcher; +use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -18,7 +18,7 @@ * * @see \Rector\Tests\DowngradePhp80\Rector\Catch_\DowngradeNonCapturingCatchesRector\DowngradeNonCapturingCatchesRectorTest */ -final class DowngradeNonCapturingCatchesRector extends AbstractScopeAwareRector +final class DowngradeNonCapturingCatchesRector extends AbstractRector { public function __construct( private readonly VariableNaming $variableNaming @@ -72,12 +72,14 @@ public function getNodeTypes(): array /** * @param Catch_ $node */ - public function refactorWithScope(Node $node, Scope $scope): ?Node + public function refactor(Node $node): ?Node { if ($node->var instanceof Variable) { return null; } + $scope = ScopeFetcher::fetch($node); + $exceptionVarName = $this->variableNaming->createCountedValueName('exception', $scope); $node->var = new Variable($exceptionVarName); diff --git a/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php b/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php index af81636f..9fe7b01e 100644 --- a/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php +++ b/rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php @@ -29,7 +29,8 @@ use PHPStan\Analyser\Scope; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Php72\NodeFactory\AnonymousFunctionFactory; -use Rector\Rector\AbstractScopeAwareRector; +use Rector\PHPStan\ScopeFetcher; +use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -38,7 +39,7 @@ * * @see \Rector\Tests\DowngradePhp80\Rector\Expression\DowngradeMatchToSwitchRector\DowngradeMatchToSwitchRectorTest */ -final class DowngradeMatchToSwitchRector extends AbstractScopeAwareRector +final class DowngradeMatchToSwitchRector extends AbstractRector { public function __construct( private readonly AnonymousFunctionFactory $anonymousFunctionFactory @@ -99,12 +100,14 @@ public function getNodeTypes(): array /** * @param Echo_|Expression|Return_ $node */ - public function refactorWithScope(Node $node, Scope $scope): ?Node + public function refactor(Node $node): ?Node { /** @var Match_|null $match */ $match = null; $hasChanged = false; + $scope = ScopeFetcher::fetch($node); + $this->traverseNodesWithCallable( $node, function (Node $subNode) use ($node, &$match, &$hasChanged, $scope) { @@ -180,6 +183,7 @@ function (Node $subNode) use ($node, &$match, &$hasChanged, $scope) { return null; } + $scope = ScopeFetcher::fetch($node); if (! $this->isEqualScope($match, $scope)) { return null; } @@ -191,6 +195,7 @@ function (Node $subNode) use ($node, &$match, &$hasChanged, $scope) { private function isEqualScope(Match_ $match, ?Scope $containerScope): bool { + $matchScope = $match->getAttribute(AttributeKey::SCOPE); if (! $matchScope instanceof Scope) { return false; diff --git a/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php b/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php index 367bc894..f6c590c9 100644 --- a/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php +++ b/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php @@ -8,12 +8,12 @@ use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayItem; use PHPStan\Analyser\MutatingScope; -use PHPStan\Analyser\Scope; use PHPStan\Type\ArrayType; use PHPStan\Type\IntegerType; use Rector\DowngradePhp81\NodeAnalyzer\ArraySpreadAnalyzer; use Rector\DowngradePhp81\NodeFactory\ArrayMergeFromArraySpreadFactory; -use Rector\Rector\AbstractScopeAwareRector; +use Rector\PHPStan\ScopeFetcher; +use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -22,7 +22,7 @@ * * @see \Rector\Tests\DowngradePhp81\Rector\Array_\DowngradeArraySpreadStringKeyRector\DowngradeArraySpreadStringKeyRectorTest */ -final class DowngradeArraySpreadStringKeyRector extends AbstractScopeAwareRector +final class DowngradeArraySpreadStringKeyRector extends AbstractRector { public function __construct( private readonly ArrayMergeFromArraySpreadFactory $arrayMergeFromArraySpreadFactory, @@ -65,7 +65,7 @@ public function getNodeTypes(): array /** * @param Array_ $node */ - public function refactorWithScope(Node $node, Scope $scope): ?Node + public function refactor(Node $node): ?Node { if (! $this->arraySpreadAnalyzer->isArrayWithUnpack($node)) { return null; @@ -76,6 +76,8 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node } /** @var MutatingScope $scope */ + $scope = ScopeFetcher::fetch($node); + return $this->arrayMergeFromArraySpreadFactory->createFromArray($node, $scope); }