diff --git a/packages/NodeTypeResolver/Node/AttributeKey.php b/packages/NodeTypeResolver/Node/AttributeKey.php index 4caca4f2a75..fdfae971c46 100644 --- a/packages/NodeTypeResolver/Node/AttributeKey.php +++ b/packages/NodeTypeResolver/Node/AttributeKey.php @@ -248,6 +248,14 @@ final class AttributeKey * @var string */ public const IS_PARAM_VAR = 'IS_PARAM_VAR'; + /** + * @var string + */ + public const IS_CLASS_EXTENDS = 'is_class_extends'; + /** + * @var string + */ + public const IS_CLASS_IMPLEMENT = 'is_class_implement'; /** * @var string */ diff --git a/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ContextNodeVisitor.php b/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ContextNodeVisitor.php index 4479c01d259..4e4fdbd620e 100644 --- a/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ContextNodeVisitor.php +++ b/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ContextNodeVisitor.php @@ -12,6 +12,7 @@ use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Isset_; use PhpParser\Node\Expr\Variable; +use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Param; use PhpParser\Node\Stmt\Break_; use PhpParser\Node\Stmt\Class_; @@ -71,8 +72,20 @@ final class ContextNodeVisitor extends NodeVisitorAbstract implements ScopeResol if ($node instanceof Param) { $node->var->setAttribute(AttributeKey::IS_PARAM_VAR, \true); } + $this->processContextInClass($node); return null; } + private function processContextInClass(Node $node) : void + { + if ($node instanceof Class_) { + if ($node->extends instanceof FullyQualified) { + $node->extends->setAttribute(AttributeKey::IS_CLASS_EXTENDS, \true); + } + foreach ($node->implements as $implement) { + $implement->setAttribute(AttributeKey::IS_CLASS_IMPLEMENT, \true); + } + } + } private function processContextInAttribute(Attribute $attribute) : void { $this->simpleCallableNodeTraverser->traverseNodesWithCallable($attribute->args, static function (Node $subNode) { diff --git a/rules/Renaming/NodeManipulator/ClassRenamer.php b/rules/Renaming/NodeManipulator/ClassRenamer.php index 6d449063cbd..b0ee1005a51 100644 --- a/rules/Renaming/NodeManipulator/ClassRenamer.php +++ b/rules/Renaming/NodeManipulator/ClassRenamer.php @@ -253,14 +253,13 @@ final class ClassRenamer } $classReflection = $this->reflectionProvider->getClass($newClassName); // ensure new is not with interface - if ($name->getAttribute(AttributeKey::IS_NEW_INSTANCE_NAME) === \true && $classReflection->isInterface()) { - return \false; + if ($name->getAttribute(AttributeKey::IS_NEW_INSTANCE_NAME) !== \true) { + return $this->isValidClassNameChange($name, $classReflection); } - $parentNode = $name->getAttribute(AttributeKey::PARENT_NODE); - if ($parentNode instanceof Class_) { - return $this->isValidClassNameChange($name, $parentNode, $classReflection); + if (!$classReflection->isInterface()) { + return $this->isValidClassNameChange($name, $classReflection); } - return \true; + return \false; } /** * @param array $oldToNewClasses @@ -313,9 +312,9 @@ final class ClassRenamer $node->setAttribute(AttributeKey::ORIGINAL_NODE, null); }); } - private function isValidClassNameChange(Name $name, Class_ $class, ClassReflection $classReflection) : bool + private function isValidClassNameChange(Name $name, ClassReflection $classReflection) : bool { - if ($class->extends === $name) { + if ($name->getAttribute(AttributeKey::IS_CLASS_EXTENDS) === \true) { // is class to interface? if ($classReflection->isInterface()) { return \false; @@ -324,8 +323,11 @@ final class ClassRenamer return \false; } } - // is interface to class? - return !(\in_array($name, $class->implements, \true) && $classReflection->isClass()); + if ($name->getAttribute(AttributeKey::IS_CLASS_IMPLEMENT) === \true) { + // is interface to class? + return !$classReflection->isClass(); + } + return \true; } /** * @param array $oldToNewClasses diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index f720737c623..fa2671d56d9 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'c8da7a564d3d5719b475e93e8c7d30b5db73aa75'; + public const PACKAGE_VERSION = '919f5d4ababb95e3cf9167926e81c65939d70bf3'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-07-09 09:04:58'; + public const RELEASE_DATE = '2023-07-09 02:45:49'; /** * @var int */ diff --git a/vendor/autoload.php b/vendor/autoload.php index 933cb3d3a79..a37f23f9c3f 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit9dd325719adaf6ed04d4b9b62f70d997::getLoader(); +return ComposerAutoloaderInit1477a7c32fa2d182de5e68e06213fa7b::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index ba5698940eb..8ddf2a3c0c8 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit9dd325719adaf6ed04d4b9b62f70d997 +class ComposerAutoloaderInit1477a7c32fa2d182de5e68e06213fa7b { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInit9dd325719adaf6ed04d4b9b62f70d997 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit9dd325719adaf6ed04d4b9b62f70d997', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit1477a7c32fa2d182de5e68e06213fa7b', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit9dd325719adaf6ed04d4b9b62f70d997', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit1477a7c32fa2d182de5e68e06213fa7b', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit9dd325719adaf6ed04d4b9b62f70d997::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit1477a7c32fa2d182de5e68e06213fa7b::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInit9dd325719adaf6ed04d4b9b62f70d997::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInit1477a7c32fa2d182de5e68e06213fa7b::$files; $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 783993b8a54..fcf7f59d0aa 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit9dd325719adaf6ed04d4b9b62f70d997 +class ComposerStaticInit1477a7c32fa2d182de5e68e06213fa7b { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3077,9 +3077,9 @@ class ComposerStaticInit9dd325719adaf6ed04d4b9b62f70d997 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit9dd325719adaf6ed04d4b9b62f70d997::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit9dd325719adaf6ed04d4b9b62f70d997::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit9dd325719adaf6ed04d4b9b62f70d997::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit1477a7c32fa2d182de5e68e06213fa7b::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit1477a7c32fa2d182de5e68e06213fa7b::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit1477a7c32fa2d182de5e68e06213fa7b::$classMap; }, null, ClassLoader::class); }