Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType;
use Rector\DeadCode\NodeAnalyzer\IsClassMethodUsedAnalyzer;
use Rector\FamilyTree\NodeAnalyzer\ClassChildAnalyzer;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\Rector\AbstractScopeAwareRector;
use Rector\PHPStan\ScopeFetcher;
use Rector\Rector\AbstractRector;
use Rector\Reflection\ReflectionResolver;
use Rector\Symfony\TypeAnalyzer\ControllerAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -23,7 +23,7 @@
/**
* @see \Rector\Symfony\Tests\CodeQuality\Rector\ClassMethod\RemoveUnusedRequestParamRector\RemoveUnusedRequestParamRectorTest
*/
final class RemoveUnusedRequestParamRector extends AbstractScopeAwareRector
final class RemoveUnusedRequestParamRector extends AbstractRector
{
public function __construct(
private readonly ControllerAnalyzer $controllerAnalyzer,
Expand Down Expand Up @@ -79,7 +79,7 @@ public function getNodeTypes(): array
/**
* @param Class_ $node
*/
public function refactorWithScope(Node $node, Scope $scope): ?Node
public function refactor(Node $node): ?Node
{
if (! $this->controllerAnalyzer->isInsideController($node)) {
return null;
Expand Down Expand Up @@ -125,6 +125,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
continue 2;
}

$scope = ScopeFetcher::fetch($node);
if ($this->isClassMethodUsedAnalyzer->isClassMethodUsed($node, $classMethod, $scope)) {
continue 2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use Rector\Enum\ObjectReference;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\Rector\AbstractScopeAwareRector;
use Rector\PHPStan\ScopeFetcher;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\MethodName;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @see \Rector\Symfony\Tests\Symfony43\Rector\ClassMethod\EventDispatcherParentConstructRector\EventDispatcherParentConstructRectorTest
*/
final class EventDispatcherParentConstructRector extends AbstractScopeAwareRector
final class EventDispatcherParentConstructRector extends AbstractRector
{
public function __construct(
private readonly BetterNodeFinder $betterNodeFinder
Expand Down Expand Up @@ -74,8 +74,9 @@ public function getNodeTypes(): array
/**
* @param ClassMethod $node
*/
public function refactorWithScope(Node $node, Scope $scope): ?Node
public function refactor(Node $node): ?Node
{
$scope = ScopeFetcher::fetch($node);
if (! $scope->isInClass()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
use PHPStan\Type\ObjectType;
use Rector\NodeCollector\NodeAnalyzer\ArrayCallableMethodMatcher;
use Rector\NodeCollector\ValueObject\ArrayCallable;
use Rector\Rector\AbstractScopeAwareRector;
use Rector\PHPStan\ScopeFetcher;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\PhpVersion;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -25,7 +26,7 @@
*
* @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
*/
final class MagicClosureTwigExtensionToNativeMethodsRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
final class MagicClosureTwigExtensionToNativeMethodsRector extends AbstractRector implements MinPhpVersionInterface
{
public function __construct(
private readonly ArrayCallableMethodMatcher $arrayCallableMethodMatcher,
Expand Down Expand Up @@ -95,7 +96,7 @@ public function getNodeTypes(): array
/**
* @param Class_ $node
*/
public function refactorWithScope(Node $node, Scope $scope): ?Node
public function refactor(Node $node): ?Node
{
if (! $this->nodeTypeResolver->isObjectTypes($node, [
new ObjectType('Twig_ExtensionInterface'),
Expand All @@ -106,6 +107,8 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node

$hasFunctionsChanged = false;

$scope = ScopeFetcher::fetch($node);

$getFunctionsClassMethod = $node->getMethod('getFunctions');
if ($getFunctionsClassMethod instanceof ClassMethod) {
$hasFunctionsChanged = $this->refactorClassMethod($getFunctionsClassMethod, $scope);
Expand Down
Loading