diff --git a/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php b/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php index 9c3f9f53cb8..410456b530a 100644 --- a/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php +++ b/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php @@ -4,7 +4,6 @@ declare (strict_types=1); namespace Rector\DeadCode\Rector\MethodCall; use PhpParser\Node; -use PhpParser\Node\Arg; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Stmt\Class_; @@ -134,14 +133,6 @@ CODE_SAMPLE } return $this->reflectionAstResolver->resolveClassFromName($classReflection->getName()); } - private function shouldSkipMethodCall(MethodCall $methodCall) : bool - { - if ($this->callAnalyzer->isObjectCall($methodCall->var)) { - return \true; - } - $parentArg = $this->betterNodeFinder->findParentType($methodCall, Arg::class); - return $parentArg instanceof Arg; - } /** * @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Trait_|\PhpParser\Node\Stmt\Interface_|\PhpParser\Node\Stmt\Enum_ $classLike */ @@ -178,7 +169,7 @@ CODE_SAMPLE } private function shouldRemoveMethodCall(MethodCall $methodCall) : bool { - if ($this->shouldSkipMethodCall($methodCall)) { + if ($this->callAnalyzer->isObjectCall($methodCall->var)) { return \false; } $callerType = $this->getType($methodCall->var); diff --git a/rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php b/rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php index e311de4d6c8..c0cb2b470f4 100644 --- a/rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php +++ b/rules/Php55/Rector/String_/StringClassNameToClassConstantRector.php @@ -75,13 +75,17 @@ CODE_SAMPLE */ public function getNodeTypes() : array { - return [String_::class, FuncCall::class]; + return [String_::class, FuncCall::class, ClassConst::class]; } /** - * @param String_|FuncCall $node + * @param String_|FuncCall|ClassConst $node */ public function refactorWithScope(Node $node, Scope $scope) { + // allow class strings to be part of class const arrays, as probably on purpose + if ($node instanceof ClassConst) { + return NodeTraverser::STOP_TRAVERSAL; + } // keep allowed string as condition if ($node instanceof FuncCall) { if ($this->isName($node, 'is_a')) { @@ -95,7 +99,7 @@ CODE_SAMPLE if ($classLikeName === '') { return null; } - if ($this->shouldSkip($classLikeName, $node)) { + if ($this->shouldSkip($classLikeName)) { return null; } $fullyQualified = new FullyQualified($classLikeName); @@ -120,15 +124,11 @@ CODE_SAMPLE { return PhpVersionFeature::CLASSNAME_CONSTANT; } - private function shouldSkip(string $classLikeName, String_ $string) : bool + private function shouldSkip(string $classLikeName) : bool { if (!$this->reflectionProvider->hasClass($classLikeName)) { return \true; } - $classReflection = $this->reflectionProvider->getClass($classLikeName); - if ($classReflection->getName() !== $classLikeName) { - return \true; - } // skip short class names, mostly invalid use of strings if (\strpos($classLikeName, '\\') === \false) { return \true; @@ -142,8 +142,6 @@ CODE_SAMPLE return \true; } } - // allow class strings to be part of class const arrays, as probably on purpose - $parentClassConst = $this->betterNodeFinder->findParentType($string, ClassConst::class); - return $parentClassConst instanceof ClassConst; + return \false; } } diff --git a/rules/Renaming/Rector/ClassMethod/RenameAnnotationRector.php b/rules/Renaming/Rector/ClassMethod/RenameAnnotationRector.php index 6ef576d1c17..66c748b934c 100644 --- a/rules/Renaming/Rector/ClassMethod/RenameAnnotationRector.php +++ b/rules/Renaming/Rector/ClassMethod/RenameAnnotationRector.php @@ -69,26 +69,40 @@ CODE_SAMPLE */ public function getNodeTypes() : array { - return [ClassMethod::class, Property::class, Expression::class]; + return [Class_::class, Expression::class]; } /** - * @param ClassMethod|Property $node + * @param Class_|Expression $node */ public function refactor(Node $node) : ?Node { - $classLike = $this->betterNodeFinder->findParentType($node, Class_::class); - if (!$classLike instanceof Class_) { + $hasChanged = \false; + if ($node instanceof Expression) { + $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); + foreach ($this->renameAnnotations as $renameAnnotation) { + $hasDocBlockChanged = $this->docBlockTagReplacer->replaceTagByAnother($phpDocInfo, $renameAnnotation->getOldAnnotation(), $renameAnnotation->getNewAnnotation()); + if ($hasDocBlockChanged) { + $hasChanged = \true; + } + } + if ($hasChanged) { + return $node; + } return null; } - $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); - $hasChanged = \false; - foreach ($this->renameAnnotations as $renameAnnotation) { - if ($renameAnnotation instanceof RenameAnnotationByType && !$this->isObjectType($classLike, $renameAnnotation->getObjectType())) { + foreach ($node->stmts as $stmt) { + if (!$stmt instanceof ClassMethod && !$stmt instanceof Property) { continue; } - $hasDocBlockChanged = $this->docBlockTagReplacer->replaceTagByAnother($phpDocInfo, $renameAnnotation->getOldAnnotation(), $renameAnnotation->getNewAnnotation()); - if ($hasDocBlockChanged) { - $hasChanged = \true; + $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($stmt); + foreach ($this->renameAnnotations as $renameAnnotation) { + if ($renameAnnotation instanceof RenameAnnotationByType && !$this->isObjectType($node, $renameAnnotation->getObjectType())) { + continue; + } + $hasDocBlockChanged = $this->docBlockTagReplacer->replaceTagByAnother($phpDocInfo, $renameAnnotation->getOldAnnotation(), $renameAnnotation->getNewAnnotation()); + if ($hasDocBlockChanged) { + $hasChanged = \true; + } } } if (!$hasChanged) { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 587df9b5c1b..ea3d67686f6 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 = 'b92e3788e665f9a260ca8d74fde6e8c574d17456'; + public const PACKAGE_VERSION = 'bc61ac2b0a95c93a557ccfe4f371f361ec09ab2c'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-06-10 10:14:01'; + public const RELEASE_DATE = '2023-06-10 06:29:57'; /** * @var int */ diff --git a/src/Kernel/RectorKernel.php b/src/Kernel/RectorKernel.php index 30bb6c71265..570886fd4e5 100644 --- a/src/Kernel/RectorKernel.php +++ b/src/Kernel/RectorKernel.php @@ -15,7 +15,7 @@ final class RectorKernel /** * @var string */ - private const CACHE_KEY = 'v84'; + private const CACHE_KEY = 'v85'; /** * @var \Symfony\Component\DependencyInjection\ContainerInterface|null */ diff --git a/src/NodeAnalyzer/ArgsAnalyzer.php b/src/NodeAnalyzer/ArgsAnalyzer.php index 9a7caa13f0c..edbc3d47361 100644 --- a/src/NodeAnalyzer/ArgsAnalyzer.php +++ b/src/NodeAnalyzer/ArgsAnalyzer.php @@ -8,14 +8,11 @@ use PhpParser\Node\Identifier; final class ArgsAnalyzer { /** - * @param mixed[]|Arg[] $args + * @param Arg[] $args */ public function hasNamedArg(array $args) : bool { foreach ($args as $arg) { - if (!$arg instanceof Arg) { - continue; - } if ($arg->name instanceof Identifier) { return \true; } diff --git a/vendor/autoload.php b/vendor/autoload.php index fb04f1a32cb..b5f8e2733ff 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 ComposerAutoloaderInitfdda859544ef89bca9c1b2d44918f846::getLoader(); +return ComposerAutoloaderInit4f4ac2e25f38d6f7f362f62fcaafd8d9::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index df137febb9e..9bff7a10720 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitfdda859544ef89bca9c1b2d44918f846 +class ComposerAutoloaderInit4f4ac2e25f38d6f7f362f62fcaafd8d9 { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInitfdda859544ef89bca9c1b2d44918f846 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInitfdda859544ef89bca9c1b2d44918f846', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit4f4ac2e25f38d6f7f362f62fcaafd8d9', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInitfdda859544ef89bca9c1b2d44918f846', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit4f4ac2e25f38d6f7f362f62fcaafd8d9', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInitfdda859544ef89bca9c1b2d44918f846::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit4f4ac2e25f38d6f7f362f62fcaafd8d9::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInitfdda859544ef89bca9c1b2d44918f846::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInit4f4ac2e25f38d6f7f362f62fcaafd8d9::$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 8f6bae7a438..0024fbd87bd 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitfdda859544ef89bca9c1b2d44918f846 +class ComposerStaticInit4f4ac2e25f38d6f7f362f62fcaafd8d9 { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3128,9 +3128,9 @@ class ComposerStaticInitfdda859544ef89bca9c1b2d44918f846 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitfdda859544ef89bca9c1b2d44918f846::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitfdda859544ef89bca9c1b2d44918f846::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInitfdda859544ef89bca9c1b2d44918f846::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit4f4ac2e25f38d6f7f362f62fcaafd8d9::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit4f4ac2e25f38d6f7f362f62fcaafd8d9::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit4f4ac2e25f38d6f7f362f62fcaafd8d9::$classMap; }, null, ClassLoader::class); }