mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
Updated Rector to commit 6e88b21cfdbf459d4c2b4c97c0db2c9b2d90b572
6e88b21cfd
Remove PARENT_NODE from RemoveEmptyMethodCallRector (#3932)
This commit is contained in:
parent
410006adf0
commit
71d07f8bbf
@ -23,7 +23,6 @@ use Rector\Core\NodeAnalyzer\CallAnalyzer;
|
||||
use Rector\Core\PhpParser\AstResolver;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
@ -82,41 +81,28 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [MethodCall::class];
|
||||
return [Expression::class, If_::class, Assign::class];
|
||||
}
|
||||
/**
|
||||
* @param MethodCall $node
|
||||
* @param Expression|If_|Assign $node
|
||||
*/
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope)
|
||||
{
|
||||
if ($this->shouldSkip($node)) {
|
||||
if ($node instanceof If_) {
|
||||
return $this->refactorIf($node, $scope);
|
||||
}
|
||||
if ($node instanceof Expression) {
|
||||
$this->refactorExpression($node, $scope);
|
||||
return null;
|
||||
}
|
||||
$type = $scope->getType($node->var);
|
||||
if (!$type instanceof TypeWithClassName) {
|
||||
if (!$node->expr instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
$classLike = $this->resolveClassLike($node);
|
||||
if (!$classLike instanceof ClassLike) {
|
||||
if (!$this->shouldRemoveMethodCall($node->expr, $scope)) {
|
||||
return null;
|
||||
}
|
||||
/** @var Class_|Trait_|Interface_|Enum_ $classLike */
|
||||
if ($this->shouldSkipClassMethod($classLike, $node, $type)) {
|
||||
return null;
|
||||
}
|
||||
// if->cond cannot removed, it has to be replaced with false, see https://3v4l.org/U9S9i
|
||||
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parentNode instanceof If_ && $parentNode->cond === $node) {
|
||||
return $this->nodeFactory->createFalse();
|
||||
}
|
||||
if ($parentNode instanceof Assign) {
|
||||
return $this->nodeFactory->createFalse();
|
||||
}
|
||||
if (!$parentNode instanceof Expression) {
|
||||
return null;
|
||||
}
|
||||
$this->removeNode($node);
|
||||
return null;
|
||||
$node->expr = $this->nodeFactory->createFalse();
|
||||
return $node;
|
||||
}
|
||||
private function resolveClassLike(MethodCall $methodCall) : ?ClassLike
|
||||
{
|
||||
@ -126,7 +112,7 @@ CODE_SAMPLE
|
||||
}
|
||||
return $this->reflectionAstResolver->resolveClassFromName($classReflection->getName());
|
||||
}
|
||||
private function shouldSkip(MethodCall $methodCall) : bool
|
||||
private function shouldSkipMethodCall(MethodCall $methodCall) : bool
|
||||
{
|
||||
if ($this->callAnalyzer->isObjectCall($methodCall->var)) {
|
||||
return \true;
|
||||
@ -168,4 +154,46 @@ CODE_SAMPLE
|
||||
}
|
||||
return !$classMethod->isPrivate();
|
||||
}
|
||||
private function shouldRemoveMethodCall(MethodCall $methodCall, Scope $scope) : bool
|
||||
{
|
||||
if ($this->shouldSkipMethodCall($methodCall)) {
|
||||
return \false;
|
||||
}
|
||||
$type = $scope->getType($methodCall->var);
|
||||
if (!$type instanceof TypeWithClassName) {
|
||||
return \false;
|
||||
}
|
||||
$classLike = $this->resolveClassLike($methodCall);
|
||||
if (!$classLike instanceof ClassLike) {
|
||||
return \false;
|
||||
}
|
||||
/** @var Class_|Trait_|Interface_|Enum_ $classLike */
|
||||
return !$this->shouldSkipClassMethod($classLike, $methodCall, $type);
|
||||
}
|
||||
/**
|
||||
* If->cond cannot removed,
|
||||
* it has to be replaced with false, see https://3v4l.org/U9S9i
|
||||
*/
|
||||
private function refactorIf(If_ $if, Scope $scope) : ?If_
|
||||
{
|
||||
if (!$if->cond instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->shouldRemoveMethodCall($if->cond, $scope)) {
|
||||
return null;
|
||||
}
|
||||
$if->cond = $this->nodeFactory->createFalse();
|
||||
return $if;
|
||||
}
|
||||
private function refactorExpression(Expression $expression, Scope $scope) : void
|
||||
{
|
||||
if (!$expression->expr instanceof MethodCall) {
|
||||
return;
|
||||
}
|
||||
$methodCall = $expression->expr;
|
||||
if (!$this->shouldRemoveMethodCall($methodCall, $scope)) {
|
||||
return;
|
||||
}
|
||||
$this->removeNode($expression);
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '4793a0d4c1294645177a18710667c7b35bcaaca3';
|
||||
public const PACKAGE_VERSION = '6e88b21cfdbf459d4c2b4c97c0db2c9b2d90b572';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-05-22 14:23:57';
|
||||
public const RELEASE_DATE = '2023-05-22 14:33:41';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
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 ComposerAutoloaderInit84be3e2579f71421f4250bd3a12f65b8::getLoader();
|
||||
return ComposerAutoloaderInit6cdbfadb270320cddd4897ea8aa9810a::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 ComposerAutoloaderInit84be3e2579f71421f4250bd3a12f65b8
|
||||
class ComposerAutoloaderInit6cdbfadb270320cddd4897ea8aa9810a
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit84be3e2579f71421f4250bd3a12f65b8
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit84be3e2579f71421f4250bd3a12f65b8', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit6cdbfadb270320cddd4897ea8aa9810a', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit84be3e2579f71421f4250bd3a12f65b8', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit6cdbfadb270320cddd4897ea8aa9810a', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit84be3e2579f71421f4250bd3a12f65b8::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit6cdbfadb270320cddd4897ea8aa9810a::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit84be3e2579f71421f4250bd3a12f65b8::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit6cdbfadb270320cddd4897ea8aa9810a::$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 ComposerStaticInit84be3e2579f71421f4250bd3a12f65b8
|
||||
class ComposerStaticInit6cdbfadb270320cddd4897ea8aa9810a
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3111,9 +3111,9 @@ class ComposerStaticInit84be3e2579f71421f4250bd3a12f65b8
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit84be3e2579f71421f4250bd3a12f65b8::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit84be3e2579f71421f4250bd3a12f65b8::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit84be3e2579f71421f4250bd3a12f65b8::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit6cdbfadb270320cddd4897ea8aa9810a::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit6cdbfadb270320cddd4897ea8aa9810a::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit6cdbfadb270320cddd4897ea8aa9810a::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user