mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 12:29:43 +01:00
Updated Rector to commit 3fa4bec792258ae18bf56c665d5ec3fa4938d475
3fa4bec792
[Renaming] Remove Scope filling from Name node on PHPStanNodeScopeResolver for RenameClassRector (#4422)
This commit is contained in:
parent
e534d832ec
commit
67e1d2d61c
@ -184,6 +184,10 @@ final class AttributeKey
|
||||
* @var string
|
||||
*/
|
||||
public const STATEMENT_DEPTH = 'statementDepth';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const EXPRESSION_DEPTH = 'expressionDepth';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -5,7 +5,6 @@ namespace Rector\NodeTypeResolver\PHPStan\Scope;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Attribute;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
@ -17,7 +16,6 @@ use PhpParser\Node\Expr\Cast;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Instanceof_;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\NullsafeMethodCall;
|
||||
@ -29,7 +27,6 @@ use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\IntersectionType;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\NullableType;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
@ -38,17 +35,12 @@ use PhpParser\Node\Stmt\EnumCase;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Finally_;
|
||||
use PhpParser\Node\Stmt\Foreach_;
|
||||
use PhpParser\Node\Stmt\GroupUse;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PhpParser\Node\Stmt\Switch_;
|
||||
use PhpParser\Node\Stmt\Trait_;
|
||||
use PhpParser\Node\Stmt\TraitUse;
|
||||
use PhpParser\Node\Stmt\TraitUseAdaptation\Precedence;
|
||||
use PhpParser\Node\Stmt\TryCatch;
|
||||
use PhpParser\Node\Stmt\UseUse;
|
||||
use PhpParser\Node\UnionType;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PHPStan\AnalysedCodeException;
|
||||
@ -168,40 +160,6 @@ final class PHPStanNodeScopeResolver
|
||||
$this->nodeScopeResolver->processNodes($node->stmts, $mutatingScope, $nodeCallback);
|
||||
return;
|
||||
}
|
||||
if ($node instanceof Namespace_ && $node->name instanceof Name) {
|
||||
$node->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if ($node instanceof Instanceof_) {
|
||||
$node->expr->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
$node->class->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if ($node instanceof UseUse) {
|
||||
$node->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if ($node instanceof GroupUse) {
|
||||
$node->prefix->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
foreach ($node->uses as $use) {
|
||||
$use->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
}
|
||||
if ($node instanceof TraitUse) {
|
||||
foreach ($node->traits as $traitName) {
|
||||
$traitName->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
foreach ($node->adaptations as $precedence) {
|
||||
if ($precedence instanceof Precedence) {
|
||||
foreach ($precedence->insteadof as $insteadof) {
|
||||
$insteadof->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if ($precedence->trait instanceof Name) {
|
||||
$precedence->trait->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($node instanceof Attribute) {
|
||||
$node->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if (($node instanceof Expression || $node instanceof Return_ || $node instanceof EnumCase || $node instanceof Cast) && $node->expr instanceof Expr) {
|
||||
$node->expr->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
@ -287,19 +245,6 @@ final class PHPStanNodeScopeResolver
|
||||
if ($node instanceof Class_ || $node instanceof Interface_ || $node instanceof Enum_) {
|
||||
/** @var MutatingScope $mutatingScope */
|
||||
$mutatingScope = $this->resolveClassOrInterfaceScope($node, $mutatingScope, $isScopeRefreshing);
|
||||
if ($node instanceof Class_ && $node->extends instanceof FullyQualified) {
|
||||
$node->extends->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if ($node instanceof Interface_) {
|
||||
foreach ($node->extends as $extend) {
|
||||
$extend->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
}
|
||||
if ($node instanceof Class_ || $node instanceof Enum_) {
|
||||
foreach ($node->implements as $implement) {
|
||||
$implement->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
}
|
||||
}
|
||||
// special case for unreachable nodes
|
||||
if ($node instanceof UnreachableStatementNode) {
|
||||
@ -312,7 +257,6 @@ final class PHPStanNodeScopeResolver
|
||||
}
|
||||
private function processCallike(CallLike $callLike, MutatingScope $mutatingScope) : void
|
||||
{
|
||||
$this->processArgsForCallike($callLike, $mutatingScope);
|
||||
if ($callLike instanceof StaticCall) {
|
||||
$callLike->class->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
$callLike->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
@ -332,40 +276,13 @@ final class PHPStanNodeScopeResolver
|
||||
$callLike->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
}
|
||||
private function processArgsForCallike(Expr $expr, MutatingScope $mutatingScope) : void
|
||||
{
|
||||
if (!$expr instanceof CallLike) {
|
||||
return;
|
||||
}
|
||||
if (!$expr->isFirstClassCallable()) {
|
||||
foreach ($expr->getArgs() as $arg) {
|
||||
$arg->value->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
if ($arg->value instanceof PropertyFetch) {
|
||||
$arg->value->var->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\Assign|\PhpParser\Node\Expr\AssignOp $assign
|
||||
*/
|
||||
private function processAssign($assign, MutatingScope $mutatingScope) : void
|
||||
{
|
||||
$assign->var->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
if ($assign->var instanceof Variable && $assign->var->name instanceof Expr) {
|
||||
$assign->var->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
$assign->expr->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
$expr = $assign;
|
||||
while ($expr instanceof Assign || $expr instanceof AssignOp) {
|
||||
$this->processArgsForCallike($expr->expr, $mutatingScope);
|
||||
$expr->var->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
if ($expr->var instanceof Variable && $expr->var->name instanceof Expr) {
|
||||
$expr->var->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
$expr->expr->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
$expr = $expr->expr;
|
||||
}
|
||||
}
|
||||
private function processArray(Array_ $array, MutatingScope $mutatingScope) : void
|
||||
{
|
||||
|
@ -10,11 +10,11 @@ use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Core\Configuration\RenamedClassesDataCollector;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Renaming\Helper\RenameClassCallbackHandler;
|
||||
use Rector\Renaming\NodeManipulator\ClassRenamer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
@ -23,7 +23,7 @@ use RectorPrefix202307\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\Renaming\Rector\Name\RenameClassRector\RenameClassRectorTest
|
||||
*/
|
||||
final class RenameClassRector extends AbstractScopeAwareRector implements ConfigurableRectorInterface
|
||||
final class RenameClassRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
@ -88,13 +88,15 @@ CODE_SAMPLE
|
||||
/**
|
||||
* @param FunctionLike|Name|ClassLike|Expression|Namespace_|Property $node
|
||||
*/
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$oldToNewClasses = $this->renamedClassesDataCollector->getOldToNewClasses();
|
||||
if ($oldToNewClasses !== []) {
|
||||
$scope = $node->getAttribute(AttributeKey::SCOPE);
|
||||
return $this->classRenamer->renameNode($node, $oldToNewClasses, $scope);
|
||||
}
|
||||
if ($this->renameClassCallbackHandler->hasOldToNewClassCallbacks()) {
|
||||
$scope = $node->getAttribute(AttributeKey::SCOPE);
|
||||
return $this->classRenamer->renameNode($node, $oldToNewClasses, $scope);
|
||||
}
|
||||
return null;
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'b4ff32ef246fe2c36351701995759ee4fc21f370';
|
||||
public const PACKAGE_VERSION = '3fa4bec792258ae18bf56c665d5ec3fa4938d475';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-07-05 16:20:36';
|
||||
public const RELEASE_DATE = '2023-07-05 19:14:04';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -43,6 +43,9 @@ final class ScopeAnalyzer
|
||||
if ($node->getAttribute(AttributeKey::STATEMENT_DEPTH) === 0) {
|
||||
return $this->scopeFactory->createFromFile($filePath);
|
||||
}
|
||||
if ($node->getAttribute(AttributeKey::EXPRESSION_DEPTH) >= 2) {
|
||||
return $this->scopeFactory->createFromFile($filePath);
|
||||
}
|
||||
/**
|
||||
* Node and parent Node doesn't has Scope, and Node Start token pos is < 0,
|
||||
* it means the node and parent node just re-printed, the Scope need to be resolved from file
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInita801eb3cf592c5df0af2284c9cc776c4::getLoader();
|
||||
return ComposerAutoloaderInit9b569095a3c44e6aef6e72fcdfdd2db3::getLoader();
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInita801eb3cf592c5df0af2284c9cc776c4
|
||||
class ComposerAutoloaderInit9b569095a3c44e6aef6e72fcdfdd2db3
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInita801eb3cf592c5df0af2284c9cc776c4
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInita801eb3cf592c5df0af2284c9cc776c4', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit9b569095a3c44e6aef6e72fcdfdd2db3', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInita801eb3cf592c5df0af2284c9cc776c4', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit9b569095a3c44e6aef6e72fcdfdd2db3', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInita801eb3cf592c5df0af2284c9cc776c4::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit9b569095a3c44e6aef6e72fcdfdd2db3::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInita801eb3cf592c5df0af2284c9cc776c4::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit9b569095a3c44e6aef6e72fcdfdd2db3::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInita801eb3cf592c5df0af2284c9cc776c4
|
||||
class ComposerStaticInit9b569095a3c44e6aef6e72fcdfdd2db3
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3100,9 +3100,9 @@ class ComposerStaticInita801eb3cf592c5df0af2284c9cc776c4
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInita801eb3cf592c5df0af2284c9cc776c4::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInita801eb3cf592c5df0af2284c9cc776c4::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInita801eb3cf592c5df0af2284c9cc776c4::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit9b569095a3c44e6aef6e72fcdfdd2db3::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit9b569095a3c44e6aef6e72fcdfdd2db3::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit9b569095a3c44e6aef6e72fcdfdd2db3::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user