Updated Rector to commit bc61ac2b0a95c93a557ccfe4f371f361ec09ab2c

bc61ac2b0a Remove parent node from StringClassNameToClassConstantRector (#4145)
This commit is contained in:
Tomas Votruba 2023-06-10 06:35:34 +00:00
parent f7beb310fa
commit 276b450e8a
9 changed files with 49 additions and 49 deletions

View File

@ -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);

View File

@ -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;
}
}

View File

@ -69,21 +69,34 @@ 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 ($node->stmts as $stmt) {
if (!$stmt instanceof ClassMethod && !$stmt instanceof Property) {
continue;
}
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($stmt);
foreach ($this->renameAnnotations as $renameAnnotation) {
if ($renameAnnotation instanceof RenameAnnotationByType && !$this->isObjectType($classLike, $renameAnnotation->getObjectType())) {
if ($renameAnnotation instanceof RenameAnnotationByType && !$this->isObjectType($node, $renameAnnotation->getObjectType())) {
continue;
}
$hasDocBlockChanged = $this->docBlockTagReplacer->replaceTagByAnother($phpDocInfo, $renameAnnotation->getOldAnnotation(), $renameAnnotation->getNewAnnotation());
@ -91,6 +104,7 @@ CODE_SAMPLE
$hasChanged = \true;
}
}
}
if (!$hasChanged) {
return null;
}

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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;
}

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitfdda859544ef89bca9c1b2d44918f846::getLoader();
return ComposerAutoloaderInit4f4ac2e25f38d6f7f362f62fcaafd8d9::getLoader();

View File

@ -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;

View File

@ -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);
}