mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-31 12:42:05 +01:00
Updated Rector to commit 3f6f70602cc4e3bd65b34720c45caf1acaa2b3e6
3f6f70602c
[DeadCode] Add RemoveDeadContinueRector (#1323)
This commit is contained in:
parent
b94eea2bd3
commit
439d1f1762
@ -25,6 +25,7 @@ use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
|
||||
use Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector;
|
||||
use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector;
|
||||
use Rector\DeadCode\Rector\Expression\SimplifyMirrorAssignRector;
|
||||
use Rector\DeadCode\Rector\For_\RemoveDeadContinueRector;
|
||||
use Rector\DeadCode\Rector\For_\RemoveDeadIfForeachForRector;
|
||||
use Rector\DeadCode\Rector\For_\RemoveDeadLoopRector;
|
||||
use Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector;
|
||||
@ -68,6 +69,7 @@ return static function (\Symfony\Component\DependencyInjection\Loader\Configurat
|
||||
$services->set(\Rector\DeadCode\Rector\FunctionLike\RemoveCodeAfterReturnRector::class);
|
||||
$services->set(\Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector::class);
|
||||
$services->set(\Rector\DeadCode\Rector\FunctionLike\RemoveDeadReturnRector::class);
|
||||
$services->set(\Rector\DeadCode\Rector\For_\RemoveDeadContinueRector::class);
|
||||
$services->set(\Rector\DeadCode\Rector\For_\RemoveDeadIfForeachForRector::class);
|
||||
$services->set(\Rector\DeadCode\Rector\BooleanAnd\RemoveAndTrueRector::class);
|
||||
$services->set(\Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector::class);
|
||||
|
79
rules/DeadCode/Rector/For_/RemoveDeadContinueRector.php
Normal file
79
rules/DeadCode/Rector/For_/RemoveDeadContinueRector.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\DeadCode\Rector\For_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Continue_;
|
||||
use PhpParser\Node\Stmt\Do_;
|
||||
use PhpParser\Node\Stmt\For_;
|
||||
use PhpParser\Node\Stmt\Foreach_;
|
||||
use PhpParser\Node\Stmt\While_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\DeadCode\Rector\For_\RemoveDeadContinueRector\RemoveDeadContinueRectorTest
|
||||
*/
|
||||
final class RemoveDeadContinueRector extends \Rector\Core\Rector\AbstractRector
|
||||
{
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Remove useless continue at the end of loops', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
|
||||
while ($i < 10) {
|
||||
++$i;
|
||||
continue;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
while ($i < 10) {
|
||||
++$i;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [\PhpParser\Node\Stmt\Do_::class, \PhpParser\Node\Stmt\For_::class, \PhpParser\Node\Stmt\Foreach_::class, \PhpParser\Node\Stmt\While_::class];
|
||||
}
|
||||
/**
|
||||
* @param Do_|For_|Foreach_|While_ $node
|
||||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
$modified = \false;
|
||||
while ($this->canRemoveLastStatement($node->stmts)) {
|
||||
\array_pop($node->stmts);
|
||||
$modified = \true;
|
||||
}
|
||||
return $modified ? $node : null;
|
||||
}
|
||||
/**
|
||||
* @param Stmt[] $stmts
|
||||
*/
|
||||
private function canRemoveLastStatement(array $stmts) : bool
|
||||
{
|
||||
if ($stmts === []) {
|
||||
return \false;
|
||||
}
|
||||
\end($stmts);
|
||||
$lastKey = \key($stmts);
|
||||
$lastStmt = $stmts[$lastKey];
|
||||
return $this->isRemovable($lastStmt);
|
||||
}
|
||||
private function isRemovable(\PhpParser\Node\Stmt $stmt) : bool
|
||||
{
|
||||
if (!$stmt instanceof \PhpParser\Node\Stmt\Continue_) {
|
||||
return \false;
|
||||
}
|
||||
if ($stmt->num instanceof \PhpParser\Node\Scalar\LNumber) {
|
||||
return $stmt->num->value < 2;
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
}
|
@ -16,11 +16,11 @@ final class VersionResolver
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '59d6ea9e31c25b17e8639a10ec8efdc636841982';
|
||||
public const PACKAGE_VERSION = '3f6f70602cc4e3bd65b34720c45caf1acaa2b3e6';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-11-28 16:51:50';
|
||||
public const RELEASE_DATE = '2021-11-28 16:52:57';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20211128\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit5f31527ca00710bb622f113bf7d92447::getLoader();
|
||||
return ComposerAutoloaderInit1ce97d352017e6e73b3a56c72f10da86::getLoader();
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -1827,6 +1827,7 @@ return array(
|
||||
'Rector\\DeadCode\\Rector\\ConstFetch\\RemovePhpVersionIdCheckRector' => $baseDir . '/rules/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Expression\\RemoveDeadStmtRector' => $baseDir . '/rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Expression\\SimplifyMirrorAssignRector' => $baseDir . '/rules/DeadCode/Rector/Expression/SimplifyMirrorAssignRector.php',
|
||||
'Rector\\DeadCode\\Rector\\For_\\RemoveDeadContinueRector' => $baseDir . '/rules/DeadCode/Rector/For_/RemoveDeadContinueRector.php',
|
||||
'Rector\\DeadCode\\Rector\\For_\\RemoveDeadIfForeachForRector' => $baseDir . '/rules/DeadCode/Rector/For_/RemoveDeadIfForeachForRector.php',
|
||||
'Rector\\DeadCode\\Rector\\For_\\RemoveDeadLoopRector' => $baseDir . '/rules/DeadCode/Rector/For_/RemoveDeadLoopRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Foreach_\\RemoveUnusedForeachKeyRector' => $baseDir . '/rules/DeadCode/Rector/Foreach_/RemoveUnusedForeachKeyRector.php',
|
||||
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit5f31527ca00710bb622f113bf7d92447
|
||||
class ComposerAutoloaderInit1ce97d352017e6e73b3a56c72f10da86
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,15 +22,15 @@ class ComposerAutoloaderInit5f31527ca00710bb622f113bf7d92447
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit5f31527ca00710bb622f113bf7d92447', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit1ce97d352017e6e73b3a56c72f10da86', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit5f31527ca00710bb622f113bf7d92447', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit1ce97d352017e6e73b3a56c72f10da86', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit5f31527ca00710bb622f113bf7d92447::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit1ce97d352017e6e73b3a56c72f10da86::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
@ -42,19 +42,19 @@ class ComposerAutoloaderInit5f31527ca00710bb622f113bf7d92447
|
||||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit5f31527ca00710bb622f113bf7d92447::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit1ce97d352017e6e73b3a56c72f10da86::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire5f31527ca00710bb622f113bf7d92447($fileIdentifier, $file);
|
||||
composerRequire1ce97d352017e6e73b3a56c72f10da86($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire5f31527ca00710bb622f113bf7d92447($fileIdentifier, $file)
|
||||
function composerRequire1ce97d352017e6e73b3a56c72f10da86($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit5f31527ca00710bb622f113bf7d92447
|
||||
class ComposerStaticInit1ce97d352017e6e73b3a56c72f10da86
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
@ -2224,6 +2224,7 @@ class ComposerStaticInit5f31527ca00710bb622f113bf7d92447
|
||||
'Rector\\DeadCode\\Rector\\ConstFetch\\RemovePhpVersionIdCheckRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/ConstFetch/RemovePhpVersionIdCheckRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Expression\\RemoveDeadStmtRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Expression\\SimplifyMirrorAssignRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Expression/SimplifyMirrorAssignRector.php',
|
||||
'Rector\\DeadCode\\Rector\\For_\\RemoveDeadContinueRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/For_/RemoveDeadContinueRector.php',
|
||||
'Rector\\DeadCode\\Rector\\For_\\RemoveDeadIfForeachForRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/For_/RemoveDeadIfForeachForRector.php',
|
||||
'Rector\\DeadCode\\Rector\\For_\\RemoveDeadLoopRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/For_/RemoveDeadLoopRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Foreach_\\RemoveUnusedForeachKeyRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Foreach_/RemoveUnusedForeachKeyRector.php',
|
||||
@ -3769,9 +3770,9 @@ class ComposerStaticInit5f31527ca00710bb622f113bf7d92447
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit5f31527ca00710bb622f113bf7d92447::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit5f31527ca00710bb622f113bf7d92447::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit5f31527ca00710bb622f113bf7d92447::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit1ce97d352017e6e73b3a56c72f10da86::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit1ce97d352017e6e73b3a56c72f10da86::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit1ce97d352017e6e73b3a56c72f10da86::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
@ -12,8 +12,8 @@ if (!class_exists('GenerateChangelogCommand', false) && !interface_exists('Gener
|
||||
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
|
||||
spl_autoload_call('RectorPrefix20211128\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit5f31527ca00710bb622f113bf7d92447', false) && !interface_exists('ComposerAutoloaderInit5f31527ca00710bb622f113bf7d92447', false) && !trait_exists('ComposerAutoloaderInit5f31527ca00710bb622f113bf7d92447', false)) {
|
||||
spl_autoload_call('RectorPrefix20211128\ComposerAutoloaderInit5f31527ca00710bb622f113bf7d92447');
|
||||
if (!class_exists('ComposerAutoloaderInit1ce97d352017e6e73b3a56c72f10da86', false) && !interface_exists('ComposerAutoloaderInit1ce97d352017e6e73b3a56c72f10da86', false) && !trait_exists('ComposerAutoloaderInit1ce97d352017e6e73b3a56c72f10da86', false)) {
|
||||
spl_autoload_call('RectorPrefix20211128\ComposerAutoloaderInit1ce97d352017e6e73b3a56c72f10da86');
|
||||
}
|
||||
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
|
||||
spl_autoload_call('RectorPrefix20211128\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
@ -81,9 +81,9 @@ if (!function_exists('print_node')) {
|
||||
return \RectorPrefix20211128\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire5f31527ca00710bb622f113bf7d92447')) {
|
||||
function composerRequire5f31527ca00710bb622f113bf7d92447() {
|
||||
return \RectorPrefix20211128\composerRequire5f31527ca00710bb622f113bf7d92447(...func_get_args());
|
||||
if (!function_exists('composerRequire1ce97d352017e6e73b3a56c72f10da86')) {
|
||||
function composerRequire1ce97d352017e6e73b3a56c72f10da86() {
|
||||
return \RectorPrefix20211128\composerRequire1ce97d352017e6e73b3a56c72f10da86(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('scanPath')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user