mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit 9793540e79b87bb08e2203b761c2c5b361ac8e27
9793540e79
[DX] Remove Attribute support on ChangedNodeScopeRefresher (#5090)
This commit is contained in:
parent
fb1a354817
commit
342f3dce55
|
@ -4,8 +4,16 @@ declare (strict_types=1);
|
|||
namespace Rector\Transform\Rector\Attribute;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Attribute;
|
||||
use PhpParser\Node\AttributeGroup;
|
||||
use PhpParser\Node\Expr\ArrowFunction;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\PhpParser\Node\Value\ValueResolver;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
|
@ -62,18 +70,45 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Attribute::class];
|
||||
return [Class_::class, Property::class, Param::class, ClassMethod::class, Function_::class, Closure::class, ArrowFunction::class, Interface_::class];
|
||||
}
|
||||
/**
|
||||
* @param Attribute $node
|
||||
* @param Class_|Property|Param|ClassMethod|Function_|Closure|ArrowFunction|Interface_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if ($node->attrGroups === []) {
|
||||
return null;
|
||||
}
|
||||
$hasChanged = \false;
|
||||
foreach ($this->attributeKeysToClassConstFetches as $attributeKeyToClassConstFetch) {
|
||||
if (!$this->isName($node->name, $attributeKeyToClassConstFetch->getAttributeClass())) {
|
||||
foreach ($node->attrGroups as $attrGroup) {
|
||||
if ($this->processToClassConstFetch($attrGroup, $attributeKeyToClassConstFetch)) {
|
||||
$hasChanged = \true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
Assert::allIsAOf($configuration, AttributeKeyToClassConstFetch::class);
|
||||
$this->attributeKeysToClassConstFetches = $configuration;
|
||||
}
|
||||
private function processToClassConstFetch(AttributeGroup $attributeGroup, AttributeKeyToClassConstFetch $attributeKeyToClassConstFetch) : bool
|
||||
{
|
||||
$hasChanged = \false;
|
||||
foreach ($attributeGroup->attrs as $attribute) {
|
||||
if (!$this->isName($attribute->name, $attributeKeyToClassConstFetch->getAttributeClass())) {
|
||||
continue;
|
||||
}
|
||||
foreach ($node->args as $arg) {
|
||||
foreach ($attribute->args as $arg) {
|
||||
$argName = $arg->name;
|
||||
if (!$argName instanceof Identifier) {
|
||||
continue;
|
||||
|
@ -87,17 +122,10 @@ CODE_SAMPLE
|
|||
continue;
|
||||
}
|
||||
$arg->value = $this->nodeFactory->createClassConstFetch($attributeKeyToClassConstFetch->getConstantClass(), $constName);
|
||||
return $node;
|
||||
$hasChanged = \true;
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
Assert::allIsAOf($configuration, AttributeKeyToClassConstFetch::class);
|
||||
$this->attributeKeysToClassConstFetches = $configuration;
|
||||
return $hasChanged;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ declare (strict_types=1);
|
|||
namespace Rector\Core\Application;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Attribute;
|
||||
use PhpParser\Node\AttributeGroup;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\CallLike;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
|
@ -20,7 +18,6 @@ use PhpParser\Node\Stmt\ClassMethod;
|
|||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\Switch_;
|
||||
use PhpParser\Node\Stmt\TryCatch;
|
||||
use PHPStan\Analyser\MutatingScope;
|
||||
|
@ -58,13 +55,6 @@ final class ChangedNodeScopeRefresher
|
|||
$errorMessage = \sprintf('Node "%s" with is missing scope required for scope refresh', \get_class($node));
|
||||
throw new ShouldNotHappenException($errorMessage);
|
||||
}
|
||||
// note from flight: when we traverse ClassMethod, the scope must be already in Class_, otherwise it crashes
|
||||
// so we need to somehow get a parent scope that is already in the same place the $node is
|
||||
if ($node instanceof Attribute) {
|
||||
// we'll have to fake-traverse 2 layers up, as PHPStan skips Scope for AttributeGroups and consequently Attributes
|
||||
$attributeGroup = new AttributeGroup([$node]);
|
||||
$node = new Property(0, [], [], null, [$attributeGroup]);
|
||||
}
|
||||
$stmts = $this->resolveStmts($node);
|
||||
$this->phpStanNodeScopeResolver->processNodes($stmts, $filePath, $mutatingScope);
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '8e67265bbebb84e6b4dc8f3249ea191710980988';
|
||||
public const PACKAGE_VERSION = '9793540e79b87bb08e2203b761c2c5b361ac8e27';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-09-28 20:08:06';
|
||||
public const RELEASE_DATE = '2023-09-28 19:00:37';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit8c37f5e0f04231c4e1aae334f588abec::getLoader();
|
||||
return ComposerAutoloaderInit1ca6237ac0ea5035763433f0ca548289::getLoader();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit8c37f5e0f04231c4e1aae334f588abec
|
||||
class ComposerAutoloaderInit1ca6237ac0ea5035763433f0ca548289
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit8c37f5e0f04231c4e1aae334f588abec
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit8c37f5e0f04231c4e1aae334f588abec', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit1ca6237ac0ea5035763433f0ca548289', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit8c37f5e0f04231c4e1aae334f588abec', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit1ca6237ac0ea5035763433f0ca548289', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit8c37f5e0f04231c4e1aae334f588abec::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit1ca6237ac0ea5035763433f0ca548289::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit8c37f5e0f04231c4e1aae334f588abec::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit1ca6237ac0ea5035763433f0ca548289::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit8c37f5e0f04231c4e1aae334f588abec
|
||||
class ComposerStaticInit1ca6237ac0ea5035763433f0ca548289
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -2600,9 +2600,9 @@ class ComposerStaticInit8c37f5e0f04231c4e1aae334f588abec
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit8c37f5e0f04231c4e1aae334f588abec::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit8c37f5e0f04231c4e1aae334f588abec::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit8c37f5e0f04231c4e1aae334f588abec::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit1ca6237ac0ea5035763433f0ca548289::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit1ca6237ac0ea5035763433f0ca548289::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit1ca6237ac0ea5035763433f0ca548289::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
|
@ -504,8 +504,8 @@
|
|||
},
|
||||
{
|
||||
"name": "illuminate\/container",
|
||||
"version": "v10.25.1",
|
||||
"version_normalized": "10.25.1.0",
|
||||
"version": "v10.25.2",
|
||||
"version_normalized": "10.25.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/illuminate\/container.git",
|
||||
|
@ -561,8 +561,8 @@
|
|||
},
|
||||
{
|
||||
"name": "illuminate\/contracts",
|
||||
"version": "v10.25.1",
|
||||
"version_normalized": "10.25.1.0",
|
||||
"version": "v10.25.2",
|
||||
"version_normalized": "10.25.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/illuminate\/contracts.git",
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue