mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 23:10:51 +00:00
Updated Rector to commit 77aeaa4dcc2fc99070999af7a28d17c4d078a4b5
77aeaa4dcc
Remove RemoveEmptyMethodCallRector as better handled by PHPStan (#4161)
This commit is contained in:
parent
5db0609ffa
commit
53778ac6ff
|
@ -32,7 +32,6 @@ use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector;
|
|||
use Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector;
|
||||
use Rector\DeadCode\Rector\If_\SimplifyIfElseWithSameContentRector;
|
||||
use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector;
|
||||
use Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector;
|
||||
use Rector\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector;
|
||||
use Rector\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector;
|
||||
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
|
||||
|
@ -76,7 +75,6 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
RemoveDeadTryCatchRector::class,
|
||||
RemoveUnusedVariableAssignRector::class,
|
||||
RemoveUnusedNonEmptyArrayBeforeForeachRector::class,
|
||||
RemoveEmptyMethodCallRector::class,
|
||||
RemoveDeadConditionAboveReturnRector::class,
|
||||
RemoveUnusedConstructorParamRector::class,
|
||||
RemoveDeadInstanceOfRector::class,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# 370 Rules Overview
|
||||
# 369 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
|||
|
||||
- [CodingStyle](#codingstyle) (34)
|
||||
|
||||
- [DeadCode](#deadcode) (43)
|
||||
- [DeadCode](#deadcode) (42)
|
||||
|
||||
- [DependencyInjection](#dependencyinjection) (1)
|
||||
|
||||
|
@ -2750,27 +2750,6 @@ Remove empty class methods not required by parents
|
|||
|
||||
<br>
|
||||
|
||||
### RemoveEmptyMethodCallRector
|
||||
|
||||
Remove empty method call
|
||||
|
||||
- class: [`Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector`](../rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
public function callThis()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
-$some = new SomeClass();
|
||||
-$some->callThis();
|
||||
+$some = new SomeClass();
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### RemoveJustPropertyFetchForAssignRector
|
||||
|
||||
Remove assign of property, just for value assign
|
||||
|
|
|
@ -1,186 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\DeadCode\Rector\MethodCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Enum_;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
use PhpParser\Node\Stmt\Trait_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Type\ThisType;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use Rector\Core\NodeAnalyzer\CallAnalyzer;
|
||||
use Rector\Core\PhpParser\AstResolver;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector\RemoveEmptyMethodCallRectorTest
|
||||
*/
|
||||
final class RemoveEmptyMethodCallRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\AstResolver
|
||||
*/
|
||||
private $reflectionAstResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeAnalyzer\CallAnalyzer
|
||||
*/
|
||||
private $callAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Reflection\ReflectionResolver
|
||||
*/
|
||||
private $reflectionResolver;
|
||||
public function __construct(AstResolver $reflectionAstResolver, CallAnalyzer $callAnalyzer, ReflectionResolver $reflectionResolver)
|
||||
{
|
||||
$this->reflectionAstResolver = $reflectionAstResolver;
|
||||
$this->callAnalyzer = $callAnalyzer;
|
||||
$this->reflectionResolver = $reflectionResolver;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Remove empty method call', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function callThis()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
$some = new SomeClass();
|
||||
$some->callThis();
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function callThis()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
$some = new SomeClass();
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [If_::class, Expression::class];
|
||||
}
|
||||
/**
|
||||
* @param If_|Expression $node
|
||||
*/
|
||||
public function refactor(Node $node)
|
||||
{
|
||||
if ($node instanceof If_) {
|
||||
return $this->refactorIf($node);
|
||||
}
|
||||
if ($node->expr instanceof Assign) {
|
||||
$assign = $node->expr;
|
||||
if (!$assign->expr instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->shouldRemoveMethodCall($assign->expr)) {
|
||||
return null;
|
||||
}
|
||||
$assign->expr = $this->nodeFactory->createFalse();
|
||||
return $node;
|
||||
}
|
||||
if ($node->expr instanceof MethodCall) {
|
||||
$methodCall = $node->expr;
|
||||
if (!$this->shouldRemoveMethodCall($methodCall)) {
|
||||
return null;
|
||||
}
|
||||
return NodeTraverser::REMOVE_NODE;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private function resolveClassLike(MethodCall $methodCall) : ?ClassLike
|
||||
{
|
||||
$classReflection = $this->reflectionResolver->resolveClassReflectionSourceObject($methodCall);
|
||||
if (!$classReflection instanceof ClassReflection) {
|
||||
return null;
|
||||
}
|
||||
return $this->reflectionAstResolver->resolveClassFromName($classReflection->getName());
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Trait_|\PhpParser\Node\Stmt\Interface_|\PhpParser\Node\Stmt\Enum_ $classLike
|
||||
*/
|
||||
private function shouldSkipClassMethod($classLike, MethodCall $methodCall, TypeWithClassName $typeWithClassName) : bool
|
||||
{
|
||||
if (!$classLike instanceof Class_) {
|
||||
return \true;
|
||||
}
|
||||
$methodName = $this->getName($methodCall->name);
|
||||
if ($methodName === null) {
|
||||
return \true;
|
||||
}
|
||||
$classMethod = $classLike->getMethod($methodName);
|
||||
if (!$classMethod instanceof ClassMethod) {
|
||||
return \true;
|
||||
}
|
||||
if ($classMethod->isAbstract()) {
|
||||
return \true;
|
||||
}
|
||||
if ((array) $classMethod->stmts !== []) {
|
||||
return \true;
|
||||
}
|
||||
$class = $this->betterNodeFinder->findParentType($methodCall, Class_::class);
|
||||
if (!$class instanceof Class_) {
|
||||
return \false;
|
||||
}
|
||||
if (!$typeWithClassName instanceof ThisType) {
|
||||
return \false;
|
||||
}
|
||||
if ($class->isFinal()) {
|
||||
return \false;
|
||||
}
|
||||
return !$classMethod->isPrivate();
|
||||
}
|
||||
private function shouldRemoveMethodCall(MethodCall $methodCall) : bool
|
||||
{
|
||||
if ($this->callAnalyzer->isObjectCall($methodCall->var)) {
|
||||
return \false;
|
||||
}
|
||||
$callerType = $this->getType($methodCall->var);
|
||||
if (!$callerType 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, $callerType);
|
||||
}
|
||||
/**
|
||||
* If->cond cannot removed,
|
||||
* it has to be replaced with false, see https://3v4l.org/U9S9i
|
||||
*/
|
||||
private function refactorIf(If_ $if) : ?If_
|
||||
{
|
||||
if (!$if->cond instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->shouldRemoveMethodCall($if->cond)) {
|
||||
return null;
|
||||
}
|
||||
$if->cond = $this->nodeFactory->createFalse();
|
||||
return $if;
|
||||
}
|
||||
}
|
|
@ -6,13 +6,10 @@ namespace Rector\Renaming\Rector\PropertyFetch;
|
|||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\VarLikeIdentifier;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\ThisType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Renaming\ValueObject\RenameProperty;
|
||||
|
@ -57,7 +54,7 @@ final class RenamePropertyRector extends AbstractRector implements ConfigurableR
|
|||
}
|
||||
return null;
|
||||
}
|
||||
return $this->processFromPropertyFetch($node);
|
||||
return $this->refactorPropertyFetch($node);
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $configuration
|
||||
|
@ -90,10 +87,8 @@ final class RenamePropertyRector extends AbstractRector implements ConfigurableR
|
|||
$this->hasChanged = \true;
|
||||
$property->props[0]->name = new VarLikeIdentifier($newProperty);
|
||||
}
|
||||
private function processFromPropertyFetch(PropertyFetch $propertyFetch) : ?PropertyFetch
|
||||
private function refactorPropertyFetch(PropertyFetch $propertyFetch) : ?PropertyFetch
|
||||
{
|
||||
$class = $this->betterNodeFinder->findParentType($propertyFetch, Class_::class);
|
||||
$nodeVarType = null;
|
||||
foreach ($this->renamedProperties as $renamedProperty) {
|
||||
$oldProperty = $renamedProperty->getOldProperty();
|
||||
if (!$this->isName($propertyFetch, $oldProperty)) {
|
||||
|
@ -102,14 +97,6 @@ final class RenamePropertyRector extends AbstractRector implements ConfigurableR
|
|||
if (!$this->isObjectType($propertyFetch->var, $renamedProperty->getObjectType())) {
|
||||
continue;
|
||||
}
|
||||
if ($class instanceof ClassLike) {
|
||||
if (!$nodeVarType instanceof Type) {
|
||||
$nodeVarType = $this->nodeTypeResolver->getType($propertyFetch->var);
|
||||
}
|
||||
if ($nodeVarType instanceof ThisType) {
|
||||
$this->renameProperty($class, $renamedProperty);
|
||||
}
|
||||
}
|
||||
$propertyFetch->name = new Identifier($renamedProperty->getNewProperty());
|
||||
return $propertyFetch;
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '3bc82de4d5b27b2852e6a1ecbc68607cf4d000ce';
|
||||
public const PACKAGE_VERSION = '77aeaa4dcc2fc99070999af7a28d17c4d078a4b5';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-06-10 11:28:05';
|
||||
public const RELEASE_DATE = '2023-06-10 12:58:50';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -15,7 +15,7 @@ final class RectorKernel
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const CACHE_KEY = 'v88';
|
||||
private const CACHE_KEY = 'v89';
|
||||
/**
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface|null
|
||||
*/
|
||||
|
|
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 ComposerAutoloaderInit99da16422db06ebfa8d0cc2b98711b3b::getLoader();
|
||||
return ComposerAutoloaderInite7daacda0f3d2a8463fb28a7c920388a::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -1728,7 +1728,6 @@ return array(
|
|||
'Rector\\DeadCode\\Rector\\If_\\RemoveUnusedNonEmptyArrayBeforeForeachRector' => $baseDir . '/rules/DeadCode/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php',
|
||||
'Rector\\DeadCode\\Rector\\If_\\SimplifyIfElseWithSameContentRector' => $baseDir . '/rules/DeadCode/Rector/If_/SimplifyIfElseWithSameContentRector.php',
|
||||
'Rector\\DeadCode\\Rector\\If_\\UnwrapFutureCompatibleIfPhpVersionRector' => $baseDir . '/rules/DeadCode/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php',
|
||||
'Rector\\DeadCode\\Rector\\MethodCall\\RemoveEmptyMethodCallRector' => $baseDir . '/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Node\\RemoveNonExistingVarAnnotationRector' => $baseDir . '/rules/DeadCode/Rector/Node/RemoveNonExistingVarAnnotationRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Plus\\RemoveDeadZeroAndOneOperationRector' => $baseDir . '/rules/DeadCode/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php',
|
||||
'Rector\\DeadCode\\Rector\\PropertyProperty\\RemoveNullPropertyInitializationRector' => $baseDir . '/rules/DeadCode/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php',
|
||||
|
|
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 ComposerAutoloaderInit99da16422db06ebfa8d0cc2b98711b3b
|
||||
class ComposerAutoloaderInite7daacda0f3d2a8463fb28a7c920388a
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit99da16422db06ebfa8d0cc2b98711b3b
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit99da16422db06ebfa8d0cc2b98711b3b', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInite7daacda0f3d2a8463fb28a7c920388a', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit99da16422db06ebfa8d0cc2b98711b3b', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInite7daacda0f3d2a8463fb28a7c920388a', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit99da16422db06ebfa8d0cc2b98711b3b::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInite7daacda0f3d2a8463fb28a7c920388a::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit99da16422db06ebfa8d0cc2b98711b3b::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInite7daacda0f3d2a8463fb28a7c920388a::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit99da16422db06ebfa8d0cc2b98711b3b
|
||||
class ComposerStaticInite7daacda0f3d2a8463fb28a7c920388a
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -1979,7 +1979,6 @@ class ComposerStaticInit99da16422db06ebfa8d0cc2b98711b3b
|
|||
'Rector\\DeadCode\\Rector\\If_\\RemoveUnusedNonEmptyArrayBeforeForeachRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php',
|
||||
'Rector\\DeadCode\\Rector\\If_\\SimplifyIfElseWithSameContentRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/If_/SimplifyIfElseWithSameContentRector.php',
|
||||
'Rector\\DeadCode\\Rector\\If_\\UnwrapFutureCompatibleIfPhpVersionRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php',
|
||||
'Rector\\DeadCode\\Rector\\MethodCall\\RemoveEmptyMethodCallRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Node\\RemoveNonExistingVarAnnotationRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Node/RemoveNonExistingVarAnnotationRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Plus\\RemoveDeadZeroAndOneOperationRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php',
|
||||
'Rector\\DeadCode\\Rector\\PropertyProperty\\RemoveNullPropertyInitializationRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php',
|
||||
|
@ -3127,9 +3126,9 @@ class ComposerStaticInit99da16422db06ebfa8d0cc2b98711b3b
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit99da16422db06ebfa8d0cc2b98711b3b::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit99da16422db06ebfa8d0cc2b98711b3b::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit99da16422db06ebfa8d0cc2b98711b3b::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInite7daacda0f3d2a8463fb28a7c920388a::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInite7daacda0f3d2a8463fb28a7c920388a::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInite7daacda0f3d2a8463fb28a7c920388a::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user