Updated Rector to commit 6c8c40bb746ce70ab8faa7e80ae088edaba771e7

6c8c40bb74 [DeadCode] Merge RemoveDeadConstructorRector, to RemoveEmptyClassMethodRector with same behavior (#2829)
This commit is contained in:
Tomas Votruba 2022-08-24 08:43:17 +00:00
parent ac412ec638
commit 0e5ee3dc93
8 changed files with 16 additions and 131 deletions

View File

@ -12,7 +12,6 @@ use Rector\DeadCode\Rector\BinaryOp\RemoveDuplicatedInstanceOfRector;
use Rector\DeadCode\Rector\BooleanAnd\RemoveAndTrueRector;
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
use Rector\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveDelegatingParentCallRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveLastReturnRector;
@ -66,7 +65,6 @@ return static function (RectorConfig $rectorConfig) : void {
RemoveUnusedPrivatePropertyRector::class,
RemoveUnusedPrivateClassConstantRector::class,
RemoveUnusedPrivateMethodRector::class,
RemoveDeadConstructorRector::class,
RemoveDeadReturnRector::class,
RemoveDeadContinueRector::class,
RemoveDeadIfForeachForRector::class,

View File

@ -1,4 +1,4 @@
# 410 Rules Overview
# 409 Rules Overview
<br>
@ -14,7 +14,7 @@
- [Composer](#composer) (6)
- [DeadCode](#deadcode) (49)
- [DeadCode](#deadcode) (48)
- [DependencyInjection](#dependencyinjection) (2)
@ -2857,23 +2857,6 @@ Remove dead condition above return
<br>
### RemoveDeadConstructorRector
Remove empty constructor
- class: [`Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector`](../rules/DeadCode/Rector/ClassMethod/RemoveDeadConstructorRector.php)
```diff
class SomeClass
{
- public function __construct()
- {
- }
}
```
<br>
### RemoveDeadContinueRector
Remove useless continue at the end of loops

View File

@ -1,94 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\DeadCode\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\NodeAnalyzer\ParamAnalyzer;
use Rector\Core\NodeManipulator\ClassMethodManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector\RemoveDeadConstructorRectorTest
*/
final class RemoveDeadConstructorRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Core\NodeManipulator\ClassMethodManipulator
*/
private $classMethodManipulator;
/**
* @readonly
* @var \Rector\Core\NodeAnalyzer\ParamAnalyzer
*/
private $paramAnalyzer;
public function __construct(ClassMethodManipulator $classMethodManipulator, ParamAnalyzer $paramAnalyzer)
{
$this->classMethodManipulator = $classMethodManipulator;
$this->paramAnalyzer = $paramAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Remove empty constructor', [new CodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function __construct()
{
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
{
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ClassMethod::class];
}
/**
* @param ClassMethod $node
*/
public function refactor(Node $node) : ?Node
{
$classLike = $this->betterNodeFinder->findParentType($node, Class_::class);
if (!$classLike instanceof Class_) {
return null;
}
if ($this->shouldSkipPropertyPromotion($node)) {
return null;
}
if ($classLike->extends instanceof FullyQualified) {
return null;
}
$this->removeNode($node);
return null;
}
private function shouldSkipPropertyPromotion(ClassMethod $classMethod) : bool
{
if (!$this->isName($classMethod, MethodName::CONSTRUCT)) {
return \true;
}
if ($classMethod->stmts === null) {
return \true;
}
if ($classMethod->stmts !== []) {
return \true;
}
if ($this->paramAnalyzer->hasPropertyPromotion($classMethod->params)) {
return \true;
}
return $this->classMethodManipulator->isNamedConstructor($classMethod);
}
}

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '9018492c75866aacc5a71329f921312d31772987';
public const PACKAGE_VERSION = '6c8c40bb746ce70ab8faa7e80ae088edaba771e7';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-08-24 08:24:13';
public const RELEASE_DATE = '2022-08-24 10:39:04';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -1661,7 +1661,6 @@ return array(
'Rector\\DeadCode\\Rector\\Cast\\RecastingRemovalRector' => $baseDir . '/rules/DeadCode/Rector/Cast/RecastingRemovalRector.php',
'Rector\\DeadCode\\Rector\\ClassConst\\RemoveUnusedPrivateClassConstantRector' => $baseDir . '/rules/DeadCode/Rector/ClassConst/RemoveUnusedPrivateClassConstantRector.php',
'Rector\\DeadCode\\Rector\\ClassLike\\RemoveAnnotationRector' => $baseDir . '/rules/DeadCode/Rector/ClassLike/RemoveAnnotationRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveDeadConstructorRector' => $baseDir . '/rules/DeadCode/Rector/ClassMethod/RemoveDeadConstructorRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveDelegatingParentCallRector' => $baseDir . '/rules/DeadCode/Rector/ClassMethod/RemoveDelegatingParentCallRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveEmptyClassMethodRector' => $baseDir . '/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveLastReturnRector' => $baseDir . '/rules/DeadCode/Rector/ClassMethod/RemoveLastReturnRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit25f8cae84e9b6b1c64dbee5f269829a2
class ComposerAutoloaderInit0aec6cd0ff6700b07aec486881ed9118
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit25f8cae84e9b6b1c64dbee5f269829a2
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit25f8cae84e9b6b1c64dbee5f269829a2', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit0aec6cd0ff6700b07aec486881ed9118', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit25f8cae84e9b6b1c64dbee5f269829a2', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit0aec6cd0ff6700b07aec486881ed9118', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit25f8cae84e9b6b1c64dbee5f269829a2::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit0aec6cd0ff6700b07aec486881ed9118::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit25f8cae84e9b6b1c64dbee5f269829a2::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit0aec6cd0ff6700b07aec486881ed9118::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire25f8cae84e9b6b1c64dbee5f269829a2($fileIdentifier, $file);
composerRequire0aec6cd0ff6700b07aec486881ed9118($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit25f8cae84e9b6b1c64dbee5f269829a2
* @param string $file
* @return void
*/
function composerRequire25f8cae84e9b6b1c64dbee5f269829a2($fileIdentifier, $file)
function composerRequire0aec6cd0ff6700b07aec486881ed9118($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 ComposerStaticInit25f8cae84e9b6b1c64dbee5f269829a2
class ComposerStaticInit0aec6cd0ff6700b07aec486881ed9118
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -1958,7 +1958,6 @@ class ComposerStaticInit25f8cae84e9b6b1c64dbee5f269829a2
'Rector\\DeadCode\\Rector\\Cast\\RecastingRemovalRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Cast/RecastingRemovalRector.php',
'Rector\\DeadCode\\Rector\\ClassConst\\RemoveUnusedPrivateClassConstantRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/ClassConst/RemoveUnusedPrivateClassConstantRector.php',
'Rector\\DeadCode\\Rector\\ClassLike\\RemoveAnnotationRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/ClassLike/RemoveAnnotationRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveDeadConstructorRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/ClassMethod/RemoveDeadConstructorRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveDelegatingParentCallRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/ClassMethod/RemoveDelegatingParentCallRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveEmptyClassMethodRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveLastReturnRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/ClassMethod/RemoveLastReturnRector.php',
@ -3259,9 +3258,9 @@ class ComposerStaticInit25f8cae84e9b6b1c64dbee5f269829a2
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit25f8cae84e9b6b1c64dbee5f269829a2::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit25f8cae84e9b6b1c64dbee5f269829a2::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit25f8cae84e9b6b1c64dbee5f269829a2::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit0aec6cd0ff6700b07aec486881ed9118::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit0aec6cd0ff6700b07aec486881ed9118::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit0aec6cd0ff6700b07aec486881ed9118::$classMap;
}, null, ClassLoader::class);
}