mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit af780c8f07bfe6fcf011789979369f03e279db44
af780c8f07
Removing parent node calls (#4137)
This commit is contained in:
parent
b0e2693e28
commit
d11bfc6bb9
|
@ -1,4 +1,4 @@
|
|||
# 371 Rules Overview
|
||||
# 370 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
|||
|
||||
- [CodingStyle](#codingstyle) (34)
|
||||
|
||||
- [DeadCode](#deadcode) (44)
|
||||
- [DeadCode](#deadcode) (43)
|
||||
|
||||
- [DependencyInjection](#dependencyinjection) (1)
|
||||
|
||||
|
@ -2678,24 +2678,6 @@ Remove operation with 1 and 0, that have no effect on the value
|
|||
|
||||
<br>
|
||||
|
||||
### RemoveDelegatingParentCallRector
|
||||
|
||||
Removed dead parent call, that does not change anything
|
||||
|
||||
- class: [`Rector\DeadCode\Rector\ClassMethod\RemoveDelegatingParentCallRector`](../rules/DeadCode/Rector/ClassMethod/RemoveDelegatingParentCallRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function prettyPrint(array $stmts): string
|
||||
- {
|
||||
- return parent::prettyPrint($stmts);
|
||||
- }
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### RemoveDoubleAssignRector
|
||||
|
||||
Simplify useless double assigns
|
||||
|
|
|
@ -125,8 +125,7 @@ CODE_SAMPLE
|
|||
return \true;
|
||||
}
|
||||
if ($this->nodeNameResolver->isName($classMethod, MethodName::CONSTRUCT)) {
|
||||
$class = $this->betterNodeFinder->findParentType($classMethod, Class_::class);
|
||||
return $class instanceof Class_ && $class->extends instanceof FullyQualified;
|
||||
return $class->extends instanceof FullyQualified;
|
||||
}
|
||||
return $this->nodeNameResolver->isName($classMethod, MethodName::INVOKE);
|
||||
}
|
||||
|
|
|
@ -5,13 +5,12 @@ namespace Rector\DependencyInjection\Rector\ClassMethod;
|
|||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Enum\ObjectReference;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
@ -19,7 +18,7 @@ use RectorPrefix202306\Webmozart\Assert\Assert;
|
|||
/**
|
||||
* @see \Rector\Tests\DependencyInjection\Rector\ClassMethod\AddMethodParentCallRector\AddMethodParentCallRectorTest
|
||||
*/
|
||||
final class AddMethodParentCallRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
final class AddMethodParentCallRector extends AbstractScopeAwareRector implements ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var array<string, string>
|
||||
|
@ -59,22 +58,21 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
$classLike = $this->betterNodeFinder->findParentType($node, ClassLike::class);
|
||||
if (!$classLike instanceof ClassLike) {
|
||||
if (!$scope->isInClass()) {
|
||||
return null;
|
||||
}
|
||||
$className = (string) $this->nodeNameResolver->getName($classLike);
|
||||
$classReflection = $scope->getClassReflection();
|
||||
foreach ($this->methodByParentTypes as $type => $method) {
|
||||
// not itself
|
||||
if ($className === $type) {
|
||||
if ($classReflection->getName() === $type) {
|
||||
continue;
|
||||
}
|
||||
if ($this->shouldSkipMethod($node, $method)) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->isObjectType($classLike, new ObjectType($type))) {
|
||||
if (!$classReflection->isSubclassOf($type)) {
|
||||
continue;
|
||||
}
|
||||
$node->stmts[] = $this->createParentStaticCall($method);
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\Php55\Rector\FuncCall;
|
||||
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Core\Enum\ObjectReference;
|
||||
use Rector\Core\NodeAnalyzer\ClassAnalyzer;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
|
@ -18,17 +17,8 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
* @changelog https://3v4l.org/GU9dP
|
||||
* @see \Rector\Tests\Php55\Rector\FuncCall\GetCalledClassToSelfClassRector\GetCalledClassToSelfClassRectorTest
|
||||
*/
|
||||
final class GetCalledClassToSelfClassRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class GetCalledClassToSelfClassRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeAnalyzer\ClassAnalyzer
|
||||
*/
|
||||
private $classAnalyzer;
|
||||
public function __construct(ClassAnalyzer $classAnalyzer)
|
||||
{
|
||||
$this->classAnalyzer = $classAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change get_called_class() to self::class on final class', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
|
@ -61,19 +51,19 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param FuncCall $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if (!$this->isName($node, 'get_called_class')) {
|
||||
return null;
|
||||
}
|
||||
$class = $this->betterNodeFinder->findParentType($node, Class_::class);
|
||||
if (!$class instanceof Class_) {
|
||||
if (!$scope->isInClass()) {
|
||||
return null;
|
||||
}
|
||||
if ($class->isFinal()) {
|
||||
$classReflection = $scope->getClassReflection();
|
||||
if ($classReflection->isFinalByKeyword()) {
|
||||
return $this->nodeFactory->createClassConstFetch(ObjectReference::SELF, 'class');
|
||||
}
|
||||
if ($this->classAnalyzer->isAnonymousClass($class)) {
|
||||
if ($classReflection->isAnonymous()) {
|
||||
return $this->nodeFactory->createClassConstFetch(ObjectReference::SELF, 'class');
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -5,10 +5,9 @@ namespace Rector\Php55\Rector\FuncCall;
|
|||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Core\Enum\ObjectReference;
|
||||
use Rector\Core\NodeAnalyzer\ClassAnalyzer;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
|
@ -18,17 +17,8 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
* @changelog https://3v4l.org/dJgXd
|
||||
* @see \Rector\Tests\Php55\Rector\FuncCall\GetCalledClassToStaticClassRector\GetCalledClassToStaticClassRectorTest
|
||||
*/
|
||||
final class GetCalledClassToStaticClassRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class GetCalledClassToStaticClassRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeAnalyzer\ClassAnalyzer
|
||||
*/
|
||||
private $classAnalyzer;
|
||||
public function __construct(ClassAnalyzer $classAnalyzer)
|
||||
{
|
||||
$this->classAnalyzer = $classAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change get_called_class() to static::class on non-final class', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
|
@ -61,19 +51,19 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param FuncCall $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if (!$this->isName($node, 'get_called_class')) {
|
||||
return null;
|
||||
}
|
||||
$class = $this->betterNodeFinder->findParentType($node, Class_::class);
|
||||
if (!$class instanceof Class_) {
|
||||
return $this->nodeFactory->createClassConstFetch(ObjectReference::STATIC, 'class');
|
||||
}
|
||||
if ($this->classAnalyzer->isAnonymousClass($class)) {
|
||||
if (!$scope->isInClass()) {
|
||||
return null;
|
||||
}
|
||||
if (!$class->isFinal()) {
|
||||
$classReflection = $scope->getClassReflection();
|
||||
if ($classReflection->isAnonymous()) {
|
||||
return null;
|
||||
}
|
||||
if (!$classReflection->isFinal()) {
|
||||
return $this->nodeFactory->createClassConstFetch(ObjectReference::STATIC, 'class');
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -9,7 +9,8 @@ use PhpParser\Node\Expr\Variable;
|
|||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
|
@ -23,7 +24,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
*
|
||||
* @see \Rector\Tests\Php80\Rector\ClassConstFetch\ClassOnThisVariableObjectRector\ClassOnThisVariableObjectRectorTest
|
||||
*/
|
||||
final class ClassOnThisVariableObjectRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class ClassOnThisVariableObjectRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
|
@ -52,23 +53,30 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassConstFetch::class];
|
||||
return [Class_::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassConstFetch $node
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if ($this->shouldSkip($node)) {
|
||||
return null;
|
||||
$className = $node->isFinal() ? 'self' : 'static';
|
||||
$hasChanged = \false;
|
||||
$this->traverseNodesWithCallable($node, function (Node $node) use(&$hasChanged, $className) : ?ClassConstFetch {
|
||||
if (!$node instanceof ClassConstFetch) {
|
||||
return null;
|
||||
}
|
||||
if ($this->shouldSkip($node)) {
|
||||
return null;
|
||||
}
|
||||
$node->class = new Name($className);
|
||||
$hasChanged = \true;
|
||||
return $node;
|
||||
});
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
$class = $this->betterNodeFinder->findParentType($node, Class_::class);
|
||||
if (!$class instanceof Class_) {
|
||||
return null;
|
||||
}
|
||||
$className = $class->isFinal() ? 'self' : 'static';
|
||||
$node->class = new Name($className);
|
||||
return $node;
|
||||
return null;
|
||||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
{
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '8fe22e43b593963c405fac48c5d093e1575afd49';
|
||||
public const PACKAGE_VERSION = 'af780c8f07bfe6fcf011789979369f03e279db44';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-06-09 16:37:36';
|
||||
public const RELEASE_DATE = '2023-06-09 16:54:47';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -15,7 +15,7 @@ final class RectorKernel
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const CACHE_KEY = 'v82';
|
||||
private const CACHE_KEY = 'v83';
|
||||
/**
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface|null
|
||||
*/
|
||||
|
|
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit51c321187b76c9986a7613d6daf92167::getLoader();
|
||||
return ComposerAutoloaderInit45c6c7287d901d58b750167655728442::getLoader();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit51c321187b76c9986a7613d6daf92167
|
||||
class ComposerAutoloaderInit45c6c7287d901d58b750167655728442
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit51c321187b76c9986a7613d6daf92167
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit51c321187b76c9986a7613d6daf92167', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit45c6c7287d901d58b750167655728442', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit51c321187b76c9986a7613d6daf92167', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit45c6c7287d901d58b750167655728442', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit51c321187b76c9986a7613d6daf92167::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit45c6c7287d901d58b750167655728442::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit51c321187b76c9986a7613d6daf92167::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit45c6c7287d901d58b750167655728442::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit51c321187b76c9986a7613d6daf92167
|
||||
class ComposerStaticInit45c6c7287d901d58b750167655728442
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -3128,9 +3128,9 @@ class ComposerStaticInit51c321187b76c9986a7613d6daf92167
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit51c321187b76c9986a7613d6daf92167::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit51c321187b76c9986a7613d6daf92167::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit51c321187b76c9986a7613d6daf92167::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit45c6c7287d901d58b750167655728442::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit45c6c7287d901d58b750167655728442::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit45c6c7287d901d58b750167655728442::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue