Updated Rector to commit 83eef32f504c089d81d801d26a0355632bdc46b5

83eef32f50 [EarlyReturn] Reduce next attribute usage on ChangeAndIfToEarlyReturnRector (#3597)
This commit is contained in:
Tomas Votruba 2023-04-09 03:06:57 +00:00
parent ed4471f69f
commit 9b3b24049e
6 changed files with 18 additions and 26 deletions

View File

@ -5,6 +5,7 @@ namespace Rector\EarlyReturn\NodeFactory;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Continue_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
@ -39,10 +40,9 @@ final class InvertedIfFactory
* @param Expr[] $conditions
* @return If_[]
*/
public function createFromConditions(If_ $if, array $conditions, Return_ $return) : array
public function createFromConditions(If_ $if, array $conditions, Return_ $return, ?Stmt $ifNextReturn) : array
{
$ifs = [];
$ifNextReturn = $this->getIfNextReturn($if);
$stmt = $this->contextAnalyzer->isInLoop($if) && !$ifNextReturn instanceof Return_ ? [new Continue_()] : [$return];
if ($ifNextReturn instanceof Return_) {
$stmt[0]->setAttribute(AttributeKey::COMMENTS, $ifNextReturn->getAttribute(AttributeKey::COMMENTS));
@ -65,12 +65,4 @@ final class InvertedIfFactory
return $node instanceof Return_ && $node->expr instanceof Expr;
});
}
private function getIfNextReturn(If_ $if) : ?Return_
{
$nextNode = $if->getAttribute(AttributeKey::NEXT_NODE);
if (!$nextNode instanceof Return_) {
return null;
}
return $nextNode;
}
}

View File

@ -144,7 +144,7 @@ CODE_SAMPLE
$afterStmts = [];
if (!$nextStmt instanceof Return_) {
$afterStmts[] = $stmt->stmts[0];
$node->stmts = \array_merge($newStmts, $this->processReplaceIfs($stmt, $booleanAndConditions, new Return_(), $afterStmts));
$node->stmts = \array_merge($newStmts, $this->processReplaceIfs($stmt, $booleanAndConditions, new Return_(), $afterStmts, $nextStmt));
return $node;
}
// remove next node
@ -154,7 +154,7 @@ CODE_SAMPLE
if ($this->isInLoopWithoutContinueOrBreak($stmt)) {
$afterStmts[] = new Return_();
}
$changedStmts = $this->processReplaceIfs($stmt, $booleanAndConditions, $ifNextReturnClone, $afterStmts);
$changedStmts = $this->processReplaceIfs($stmt, $booleanAndConditions, $ifNextReturnClone, $afterStmts, $nextStmt);
// update stmts
$node->stmts = \array_merge($newStmts, $changedStmts);
return $node;
@ -176,9 +176,9 @@ CODE_SAMPLE
* @param Stmt[] $afters
* @return Stmt[]
*/
private function processReplaceIfs(If_ $if, array $conditions, Return_ $ifNextReturnClone, array $afters) : array
private function processReplaceIfs(If_ $if, array $conditions, Return_ $ifNextReturnClone, array $afters, ?Stmt $nextStmt) : array
{
$ifs = $this->invertedIfFactory->createFromConditions($if, $conditions, $ifNextReturnClone);
$ifs = $this->invertedIfFactory->createFromConditions($if, $conditions, $ifNextReturnClone, $nextStmt);
$this->mirrorComments($ifs[0], $if);
$result = \array_merge($ifs, $afters);
if ($if->stmts[0] instanceof Return_) {

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'cc30d2db2dcb4c5adacb7cf34edf25913be2bd01';
public const PACKAGE_VERSION = '83eef32f504c089d81d801d26a0355632bdc46b5';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-04-09 01:23:06';
public const RELEASE_DATE = '2023-04-09 10:03:03';
/**
* @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 ComposerAutoloaderInit0ccf446dda2c38ddeb47fe0a6741726d::getLoader();
return ComposerAutoloaderInit59fe1b308651c754ec29d7c0bf08c532::getLoader();

View File

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