Skip to content

Commit 2f1cf6d

Browse files
authored
Upgrade deprecated ScopeAware to AbstractRector (#680)
1 parent e82886f commit 2f1cf6d

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

rules/CodeQuality/Rector/ClassMethod/RemoveUnusedRequestParamRector.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
use PhpParser\Node\Expr\Variable;
99
use PhpParser\Node\Stmt\Class_;
1010
use PhpParser\Node\Stmt\ClassMethod;
11-
use PHPStan\Analyser\Scope;
1211
use PHPStan\Reflection\ClassReflection;
1312
use PHPStan\Type\ObjectType;
1413
use Rector\DeadCode\NodeAnalyzer\IsClassMethodUsedAnalyzer;
1514
use Rector\FamilyTree\NodeAnalyzer\ClassChildAnalyzer;
1615
use Rector\PhpParser\Node\BetterNodeFinder;
17-
use Rector\Rector\AbstractScopeAwareRector;
16+
use Rector\PHPStan\ScopeFetcher;
17+
use Rector\Rector\AbstractRector;
1818
use Rector\Reflection\ReflectionResolver;
1919
use Rector\Symfony\TypeAnalyzer\ControllerAnalyzer;
2020
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -23,7 +23,7 @@
2323
/**
2424
* @see \Rector\Symfony\Tests\CodeQuality\Rector\ClassMethod\RemoveUnusedRequestParamRector\RemoveUnusedRequestParamRectorTest
2525
*/
26-
final class RemoveUnusedRequestParamRector extends AbstractScopeAwareRector
26+
final class RemoveUnusedRequestParamRector extends AbstractRector
2727
{
2828
public function __construct(
2929
private readonly ControllerAnalyzer $controllerAnalyzer,
@@ -79,7 +79,7 @@ public function getNodeTypes(): array
7979
/**
8080
* @param Class_ $node
8181
*/
82-
public function refactorWithScope(Node $node, Scope $scope): ?Node
82+
public function refactor(Node $node): ?Node
8383
{
8484
if (! $this->controllerAnalyzer->isInsideController($node)) {
8585
return null;
@@ -125,6 +125,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
125125
continue 2;
126126
}
127127

128+
$scope = ScopeFetcher::fetch($node);
128129
if ($this->isClassMethodUsedAnalyzer->isClassMethodUsed($node, $classMethod, $scope)) {
129130
continue 2;
130131
}

rules/Symfony43/Rector/ClassMethod/EventDispatcherParentConstructRector.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
use PhpParser\Node\Expr\StaticCall;
99
use PhpParser\Node\Stmt\ClassMethod;
1010
use PhpParser\Node\Stmt\Expression;
11-
use PHPStan\Analyser\Scope;
1211
use PHPStan\Reflection\ClassReflection;
1312
use Rector\Enum\ObjectReference;
1413
use Rector\PhpParser\Node\BetterNodeFinder;
15-
use Rector\Rector\AbstractScopeAwareRector;
14+
use Rector\PHPStan\ScopeFetcher;
15+
use Rector\Rector\AbstractRector;
1616
use Rector\ValueObject\MethodName;
1717
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1818
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1919

2020
/**
2121
* @see \Rector\Symfony\Tests\Symfony43\Rector\ClassMethod\EventDispatcherParentConstructRector\EventDispatcherParentConstructRectorTest
2222
*/
23-
final class EventDispatcherParentConstructRector extends AbstractScopeAwareRector
23+
final class EventDispatcherParentConstructRector extends AbstractRector
2424
{
2525
public function __construct(
2626
private readonly BetterNodeFinder $betterNodeFinder
@@ -74,8 +74,9 @@ public function getNodeTypes(): array
7474
/**
7575
* @param ClassMethod $node
7676
*/
77-
public function refactorWithScope(Node $node, Scope $scope): ?Node
77+
public function refactor(Node $node): ?Node
7878
{
79+
$scope = ScopeFetcher::fetch($node);
7980
if (! $scope->isInClass()) {
8081
return null;
8182
}

rules/Symfony61/Rector/Class_/MagicClosureTwigExtensionToNativeMethodsRector.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
use PHPStan\Type\ObjectType;
1515
use Rector\NodeCollector\NodeAnalyzer\ArrayCallableMethodMatcher;
1616
use Rector\NodeCollector\ValueObject\ArrayCallable;
17-
use Rector\Rector\AbstractScopeAwareRector;
17+
use Rector\PHPStan\ScopeFetcher;
18+
use Rector\Rector\AbstractRector;
1819
use Rector\ValueObject\PhpVersion;
1920
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
2021
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -25,7 +26,7 @@
2526
*
2627
* @see PHP 8.1 way to handle functions/filters https://github.com/symfony/symfony/blob/e0ad2eead3513a558c09d8aa3ae9e867fb10b419/src/Symfony/Bridge/Twig/Extension/CodeExtension.php#L41-L52
2728
*/
28-
final class MagicClosureTwigExtensionToNativeMethodsRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
29+
final class MagicClosureTwigExtensionToNativeMethodsRector extends AbstractRector implements MinPhpVersionInterface
2930
{
3031
public function __construct(
3132
private readonly ArrayCallableMethodMatcher $arrayCallableMethodMatcher,
@@ -95,7 +96,7 @@ public function getNodeTypes(): array
9596
/**
9697
* @param Class_ $node
9798
*/
98-
public function refactorWithScope(Node $node, Scope $scope): ?Node
99+
public function refactor(Node $node): ?Node
99100
{
100101
if (! $this->nodeTypeResolver->isObjectTypes($node, [
101102
new ObjectType('Twig_ExtensionInterface'),
@@ -106,6 +107,8 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
106107

107108
$hasFunctionsChanged = false;
108109

110+
$scope = ScopeFetcher::fetch($node);
111+
109112
$getFunctionsClassMethod = $node->getMethod('getFunctions');
110113
if ($getFunctionsClassMethod instanceof ClassMethod) {
111114
$hasFunctionsChanged = $this->refactorClassMethod($getFunctionsClassMethod, $scope);

0 commit comments

Comments
 (0)