mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-15 15:42:22 +00:00
Updated Rector to commit 83eef32f504c089d81d801d26a0355632bdc46b5
83eef32f50
[EarlyReturn] Reduce next attribute usage on ChangeAndIfToEarlyReturnRector (#3597)
This commit is contained in:
parent
ed4471f69f
commit
9b3b24049e
|
@ -5,6 +5,7 @@ namespace Rector\EarlyReturn\NodeFactory;
|
||||||
|
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Expr;
|
use PhpParser\Node\Expr;
|
||||||
|
use PhpParser\Node\Stmt;
|
||||||
use PhpParser\Node\Stmt\Continue_;
|
use PhpParser\Node\Stmt\Continue_;
|
||||||
use PhpParser\Node\Stmt\If_;
|
use PhpParser\Node\Stmt\If_;
|
||||||
use PhpParser\Node\Stmt\Return_;
|
use PhpParser\Node\Stmt\Return_;
|
||||||
|
@ -39,10 +40,9 @@ final class InvertedIfFactory
|
||||||
* @param Expr[] $conditions
|
* @param Expr[] $conditions
|
||||||
* @return If_[]
|
* @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 = [];
|
$ifs = [];
|
||||||
$ifNextReturn = $this->getIfNextReturn($if);
|
|
||||||
$stmt = $this->contextAnalyzer->isInLoop($if) && !$ifNextReturn instanceof Return_ ? [new Continue_()] : [$return];
|
$stmt = $this->contextAnalyzer->isInLoop($if) && !$ifNextReturn instanceof Return_ ? [new Continue_()] : [$return];
|
||||||
if ($ifNextReturn instanceof Return_) {
|
if ($ifNextReturn instanceof Return_) {
|
||||||
$stmt[0]->setAttribute(AttributeKey::COMMENTS, $ifNextReturn->getAttribute(AttributeKey::COMMENTS));
|
$stmt[0]->setAttribute(AttributeKey::COMMENTS, $ifNextReturn->getAttribute(AttributeKey::COMMENTS));
|
||||||
|
@ -65,12 +65,4 @@ final class InvertedIfFactory
|
||||||
return $node instanceof Return_ && $node->expr instanceof Expr;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ CODE_SAMPLE
|
||||||
$afterStmts = [];
|
$afterStmts = [];
|
||||||
if (!$nextStmt instanceof Return_) {
|
if (!$nextStmt instanceof Return_) {
|
||||||
$afterStmts[] = $stmt->stmts[0];
|
$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;
|
return $node;
|
||||||
}
|
}
|
||||||
// remove next node
|
// remove next node
|
||||||
|
@ -154,7 +154,7 @@ CODE_SAMPLE
|
||||||
if ($this->isInLoopWithoutContinueOrBreak($stmt)) {
|
if ($this->isInLoopWithoutContinueOrBreak($stmt)) {
|
||||||
$afterStmts[] = new Return_();
|
$afterStmts[] = new Return_();
|
||||||
}
|
}
|
||||||
$changedStmts = $this->processReplaceIfs($stmt, $booleanAndConditions, $ifNextReturnClone, $afterStmts);
|
$changedStmts = $this->processReplaceIfs($stmt, $booleanAndConditions, $ifNextReturnClone, $afterStmts, $nextStmt);
|
||||||
// update stmts
|
// update stmts
|
||||||
$node->stmts = \array_merge($newStmts, $changedStmts);
|
$node->stmts = \array_merge($newStmts, $changedStmts);
|
||||||
return $node;
|
return $node;
|
||||||
|
@ -176,9 +176,9 @@ CODE_SAMPLE
|
||||||
* @param Stmt[] $afters
|
* @param Stmt[] $afters
|
||||||
* @return Stmt[]
|
* @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);
|
$this->mirrorComments($ifs[0], $if);
|
||||||
$result = \array_merge($ifs, $afters);
|
$result = \array_merge($ifs, $afters);
|
||||||
if ($if->stmts[0] instanceof Return_) {
|
if ($if->stmts[0] instanceof Return_) {
|
||||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = 'cc30d2db2dcb4c5adacb7cf34edf25913be2bd01';
|
public const PACKAGE_VERSION = '83eef32f504c089d81d801d26a0355632bdc46b5';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2023-04-09 01:23:06';
|
public const RELEASE_DATE = '2023-04-09 10:03:03';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||||
|
|
||||||
require_once __DIR__ . '/composer/autoload_real.php';
|
require_once __DIR__ . '/composer/autoload_real.php';
|
||||||
|
|
||||||
return ComposerAutoloaderInit0ccf446dda2c38ddeb47fe0a6741726d::getLoader();
|
return ComposerAutoloaderInit59fe1b308651c754ec29d7c0bf08c532::getLoader();
|
||||||
|
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
// autoload_real.php @generated by Composer
|
// autoload_real.php @generated by Composer
|
||||||
|
|
||||||
class ComposerAutoloaderInit0ccf446dda2c38ddeb47fe0a6741726d
|
class ComposerAutoloaderInit59fe1b308651c754ec29d7c0bf08c532
|
||||||
{
|
{
|
||||||
private static $loader;
|
private static $loader;
|
||||||
|
|
||||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit0ccf446dda2c38ddeb47fe0a6741726d
|
||||||
return self::$loader;
|
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__));
|
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';
|
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->setClassMapAuthoritative(true);
|
||||||
$loader->register(true);
|
$loader->register(true);
|
||||||
|
|
||||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit0ccf446dda2c38ddeb47fe0a6741726d::$files;
|
$filesToLoad = \Composer\Autoload\ComposerStaticInit59fe1b308651c754ec29d7c0bf08c532::$files;
|
||||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
namespace Composer\Autoload;
|
namespace Composer\Autoload;
|
||||||
|
|
||||||
class ComposerStaticInit0ccf446dda2c38ddeb47fe0a6741726d
|
class ComposerStaticInit59fe1b308651c754ec29d7c0bf08c532
|
||||||
{
|
{
|
||||||
public static $files = array (
|
public static $files = array (
|
||||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||||
|
@ -3137,9 +3137,9 @@ class ComposerStaticInit0ccf446dda2c38ddeb47fe0a6741726d
|
||||||
public static function getInitializer(ClassLoader $loader)
|
public static function getInitializer(ClassLoader $loader)
|
||||||
{
|
{
|
||||||
return \Closure::bind(function () use ($loader) {
|
return \Closure::bind(function () use ($loader) {
|
||||||
$loader->prefixLengthsPsr4 = ComposerStaticInit0ccf446dda2c38ddeb47fe0a6741726d::$prefixLengthsPsr4;
|
$loader->prefixLengthsPsr4 = ComposerStaticInit59fe1b308651c754ec29d7c0bf08c532::$prefixLengthsPsr4;
|
||||||
$loader->prefixDirsPsr4 = ComposerStaticInit0ccf446dda2c38ddeb47fe0a6741726d::$prefixDirsPsr4;
|
$loader->prefixDirsPsr4 = ComposerStaticInit59fe1b308651c754ec29d7c0bf08c532::$prefixDirsPsr4;
|
||||||
$loader->classMap = ComposerStaticInit0ccf446dda2c38ddeb47fe0a6741726d::$classMap;
|
$loader->classMap = ComposerStaticInit59fe1b308651c754ec29d7c0bf08c532::$classMap;
|
||||||
|
|
||||||
}, null, ClassLoader::class);
|
}, null, ClassLoader::class);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user