Updated Rector to commit 82687502deb9d41ed79ed832baa09fe23f90d3f8

82687502de Avoid parent node lookup in RemoveEmptyClassMethodRector (#4129)
This commit is contained in:
Tomas Votruba 2023-06-08 23:05:51 +00:00
parent 08a4332d59
commit 2c295def16
7 changed files with 81 additions and 69 deletions

View File

@ -21,7 +21,7 @@ final class NewStaticToNewSelfRector extends AbstractRector
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change unsafe new static() to new self()', [new CodeSample(<<<'CODE_SAMPLE'
class SomeClass
final class SomeClass
{
public function build()
{
@ -30,7 +30,7 @@ class SomeClass
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
final class SomeClass
{
public function build()
{
@ -45,24 +45,31 @@ CODE_SAMPLE
*/
public function getNodeTypes() : array
{
return [New_::class];
return [Class_::class];
}
/**
* @param New_ $node
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
$class = $this->betterNodeFinder->findParentType($node, Class_::class);
if (!$class instanceof Class_) {
if (!$node->isFinal()) {
return null;
}
if (!$class->isFinal()) {
return null;
$hasChanged = \false;
$this->traverseNodesWithCallable($node, function (Node $node) use(&$hasChanged) : ?New_ {
if (!$node instanceof New_) {
return null;
}
if (!$this->isName($node->class, ObjectReference::STATIC)) {
return null;
}
$hasChanged = \true;
$node->class = new Name(ObjectReference::SELF);
return $node;
});
if ($hasChanged) {
return $node;
}
if (!$this->isName($node->class, ObjectReference::STATIC)) {
return null;
}
$node->class = new Name(ObjectReference::SELF);
return $node;
return null;
}
}

View File

@ -7,7 +7,6 @@ use PhpParser\Node;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\NodeTraverser;
use Rector\Core\NodeAnalyzer\ParamAnalyzer;
use Rector\Core\NodeManipulator\ClassMethodManipulator;
use Rector\Core\Rector\AbstractRector;
@ -63,33 +62,40 @@ CODE_SAMPLE
*/
public function getNodeTypes() : array
{
return [ClassMethod::class];
return [Class_::class];
}
/**
* @param ClassMethod $node
* @param Class_ $node
*/
public function refactor(Node $node) : ?int
public function refactor(Node $node) : ?Class_
{
$classLike = $this->betterNodeFinder->findParentType($node, Class_::class);
if (!$classLike instanceof Class_) {
return null;
$hasChanged = \false;
foreach ($node->stmts as $key => $stmt) {
if (!$stmt instanceof ClassMethod) {
continue;
}
if ($stmt->stmts !== null && $stmt->stmts !== []) {
continue;
}
if ($stmt->isAbstract()) {
continue;
}
if ($stmt->isFinal() && !$node->isFinal()) {
continue;
}
if ($this->shouldSkipNonFinalNonPrivateClassMethod($node, $stmt)) {
continue;
}
if ($this->shouldSkipClassMethod($node, $stmt)) {
continue;
}
unset($node->stmts[$key]);
$hasChanged = \true;
}
if ($node->stmts !== null && $node->stmts !== []) {
return null;
if ($hasChanged) {
return $node;
}
if ($node->isAbstract()) {
return null;
}
if ($node->isFinal() && !$classLike->isFinal()) {
return null;
}
if ($this->shouldSkipNonFinalNonPrivateClassMethod($classLike, $node)) {
return null;
}
if ($this->shouldSkipClassMethod($classLike, $node)) {
return null;
}
return NodeTraverser::REMOVE_NODE;
return null;
}
private function shouldSkipNonFinalNonPrivateClassMethod(Class_ $class, ClassMethod $classMethod) : bool
{

View File

@ -5,8 +5,6 @@ namespace Rector\Php55\Rector\ClassConstFetch;
use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use Rector\Core\Enum\ObjectReference;
use Rector\Core\Rector\AbstractRector;
@ -48,33 +46,34 @@ CODE_SAMPLE
*/
public function getNodeTypes() : array
{
return [ClassConstFetch::class];
return [Class_::class];
}
/**
* @param ClassConstFetch $node
* @param Class_ $node
*/
public function refactor(Node $node) : ?ClassConstFetch
public function refactor(Node $node) : ?Class_
{
if (!$node->class instanceof Name) {
if (!$node->isFinal()) {
return null;
}
if (!$node->name instanceof Identifier) {
return null;
$hasChanged = \false;
$this->traverseNodesWithCallable($node, function (Node $node) use(&$hasChanged) : ?ClassConstFetch {
if (!$node instanceof ClassConstFetch) {
return null;
}
if (!$this->isName($node->class, ObjectReference::STATIC)) {
return null;
}
if (!$this->isName($node->name, 'class')) {
return null;
}
$hasChanged = \true;
return $this->nodeFactory->createSelfFetchConstant('class');
});
if ($hasChanged) {
return $node;
}
if ($node->class->toString() !== ObjectReference::STATIC) {
return null;
}
if ($node->name->toString() !== 'class') {
return null;
}
$class = $this->betterNodeFinder->findParentType($node, Class_::class);
if (!$class instanceof Class_) {
return null;
}
if (!$class->isFinal()) {
return null;
}
return $this->nodeFactory->createSelfFetchConstant('class');
return null;
}
public function provideMinPhpVersion() : int
{

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '059783fb07cbe5bd2259d4634d32f563ce862de0';
public const PACKAGE_VERSION = '82687502deb9d41ed79ed832baa09fe23f90d3f8';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-06-08 22:49:04';
public const RELEASE_DATE = '2023-06-08 23:01:25';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit9d050947f5c31944d244056faf973a5a
class ComposerAutoloaderInitfdefce455bec7307ff935b4e2645f2c4
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit9d050947f5c31944d244056faf973a5a
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit9d050947f5c31944d244056faf973a5a', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitfdefce455bec7307ff935b4e2645f2c4', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit9d050947f5c31944d244056faf973a5a', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitfdefce455bec7307ff935b4e2645f2c4', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit9d050947f5c31944d244056faf973a5a::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitfdefce455bec7307ff935b4e2645f2c4::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit9d050947f5c31944d244056faf973a5a::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitfdefce455bec7307ff935b4e2645f2c4::$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 ComposerStaticInit9d050947f5c31944d244056faf973a5a
class ComposerStaticInitfdefce455bec7307ff935b4e2645f2c4
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3138,9 +3138,9 @@ class ComposerStaticInit9d050947f5c31944d244056faf973a5a
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit9d050947f5c31944d244056faf973a5a::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit9d050947f5c31944d244056faf973a5a::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit9d050947f5c31944d244056faf973a5a::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitfdefce455bec7307ff935b4e2645f2c4::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitfdefce455bec7307ff935b4e2645f2c4::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitfdefce455bec7307ff935b4e2645f2c4::$classMap;
}, null, ClassLoader::class);
}