Updated Rector to commit 33158773d1a8e00a77d1e557b919c5e206245f94

33158773d1 [EarlyReturn] Clean up unnecessary tweak on ChangeOrIfReturnToEarlyReturnRector (#1843)
This commit is contained in:
Tomas Votruba 2022-02-20 14:15:59 +00:00
parent b2ae6d5638
commit 4b2d0513ec
6 changed files with 36 additions and 34 deletions

View File

@ -5,7 +5,7 @@ namespace Rector\EarlyReturn\Rector\If_;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Instanceof_;
@ -13,6 +13,7 @@ use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\Core\NodeManipulator\IfManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -81,7 +82,7 @@ CODE_SAMPLE
if (!$node->cond instanceof \PhpParser\Node\Expr\BinaryOp\BooleanOr) {
return null;
}
if ($this->isInstanceofCondOnlyOrHasBooleanAnd($node->cond)) {
if ($this->isInstanceofCondOnly($node->cond)) {
return null;
}
// maybe used along with Php8ResourceReturnToObjectRector rule
@ -90,6 +91,11 @@ CODE_SAMPLE
}
/** @var Return_ $return */
$return = $node->stmts[0];
// same return? skip
$next = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE);
if ($next instanceof \PhpParser\Node\Stmt\Return_ && $this->nodeComparator->areNodesEqual($return, $next)) {
return null;
}
$ifs = $this->createMultipleIfs($node->cond, $return, []);
// ensure ifs not removed by other rules
if ($ifs === []) {
@ -143,21 +149,17 @@ CODE_SAMPLE
{
return new \PhpParser\Node\Stmt\If_($expr, ['stmts' => [$return]]);
}
private function isInstanceofCondOnlyOrHasBooleanAnd(\PhpParser\Node\Expr\BinaryOp\BooleanOr $booleanOr) : bool
/**
* @param \PhpParser\Node\Expr\BinaryOp|\PhpParser\Node\Expr\BinaryOp\BooleanOr $booleanOr
*/
private function isInstanceofCondOnly($booleanOr) : bool
{
$currentNode = $booleanOr;
if ($currentNode->left instanceof \PhpParser\Node\Expr\BinaryOp\BooleanAnd || $currentNode->right instanceof \PhpParser\Node\Expr\BinaryOp\BooleanAnd) {
return \true;
if ($booleanOr->left instanceof \PhpParser\Node\Expr\BinaryOp) {
return $this->isInstanceofCondOnly($booleanOr->left);
}
if ($currentNode->left instanceof \PhpParser\Node\Expr\BinaryOp\BooleanOr) {
return $this->isInstanceofCondOnlyOrHasBooleanAnd($currentNode->left);
if ($booleanOr->right instanceof \PhpParser\Node\Expr\BinaryOp) {
return $this->isInstanceofCondOnly($booleanOr->right);
}
if ($currentNode->right instanceof \PhpParser\Node\Expr\BinaryOp\BooleanOr) {
return $this->isInstanceofCondOnlyOrHasBooleanAnd($currentNode->right);
}
if (!$currentNode->right instanceof \PhpParser\Node\Expr\Instanceof_) {
return \false;
}
return $currentNode->left instanceof \PhpParser\Node\Expr\Instanceof_;
return $booleanOr->right instanceof \PhpParser\Node\Expr\Instanceof_;
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '2dd05f65da0924ec259d720b8ca46d25810b34ff';
public const PACKAGE_VERSION = '33158773d1a8e00a77d1e557b919c5e206245f94';
/**
* @var string
*/
public const RELEASE_DATE = '2022-02-20 12:17:34';
public const RELEASE_DATE = '2022-02-20 15:07:51';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220220\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitd14021b5ecc48125eba20b8cf5c558fa::getLoader();
return ComposerAutoloaderInitce524ce9ef7cab350fa2cef25f67422c::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitd14021b5ecc48125eba20b8cf5c558fa
class ComposerAutoloaderInitce524ce9ef7cab350fa2cef25f67422c
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInitd14021b5ecc48125eba20b8cf5c558fa
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitd14021b5ecc48125eba20b8cf5c558fa', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitce524ce9ef7cab350fa2cef25f67422c', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInitd14021b5ecc48125eba20b8cf5c558fa', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitce524ce9ef7cab350fa2cef25f67422c', '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\ComposerStaticInitd14021b5ecc48125eba20b8cf5c558fa::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitce524ce9ef7cab350fa2cef25f67422c::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,12 +42,12 @@ class ComposerAutoloaderInitd14021b5ecc48125eba20b8cf5c558fa
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitd14021b5ecc48125eba20b8cf5c558fa::$files;
$includeFiles = Composer\Autoload\ComposerStaticInitce524ce9ef7cab350fa2cef25f67422c::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequired14021b5ecc48125eba20b8cf5c558fa($fileIdentifier, $file);
composerRequirece524ce9ef7cab350fa2cef25f67422c($fileIdentifier, $file);
}
return $loader;
@ -59,7 +59,7 @@ class ComposerAutoloaderInitd14021b5ecc48125eba20b8cf5c558fa
* @param string $file
* @return void
*/
function composerRequired14021b5ecc48125eba20b8cf5c558fa($fileIdentifier, $file)
function composerRequirece524ce9ef7cab350fa2cef25f67422c($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 ComposerStaticInitd14021b5ecc48125eba20b8cf5c558fa
class ComposerStaticInitce524ce9ef7cab350fa2cef25f67422c
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -3852,9 +3852,9 @@ class ComposerStaticInitd14021b5ecc48125eba20b8cf5c558fa
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitd14021b5ecc48125eba20b8cf5c558fa::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitd14021b5ecc48125eba20b8cf5c558fa::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitd14021b5ecc48125eba20b8cf5c558fa::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitce524ce9ef7cab350fa2cef25f67422c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitce524ce9ef7cab350fa2cef25f67422c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitce524ce9ef7cab350fa2cef25f67422c::$classMap;
}, null, ClassLoader::class);
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20220220\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInitd14021b5ecc48125eba20b8cf5c558fa', false) && !interface_exists('ComposerAutoloaderInitd14021b5ecc48125eba20b8cf5c558fa', false) && !trait_exists('ComposerAutoloaderInitd14021b5ecc48125eba20b8cf5c558fa', false)) {
spl_autoload_call('RectorPrefix20220220\ComposerAutoloaderInitd14021b5ecc48125eba20b8cf5c558fa');
if (!class_exists('ComposerAutoloaderInitce524ce9ef7cab350fa2cef25f67422c', false) && !interface_exists('ComposerAutoloaderInitce524ce9ef7cab350fa2cef25f67422c', false) && !trait_exists('ComposerAutoloaderInitce524ce9ef7cab350fa2cef25f67422c', false)) {
spl_autoload_call('RectorPrefix20220220\ComposerAutoloaderInitce524ce9ef7cab350fa2cef25f67422c');
}
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('RectorPrefix20220220\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220220\print_node(...func_get_args());
}
}
if (!function_exists('composerRequired14021b5ecc48125eba20b8cf5c558fa')) {
function composerRequired14021b5ecc48125eba20b8cf5c558fa() {
return \RectorPrefix20220220\composerRequired14021b5ecc48125eba20b8cf5c558fa(...func_get_args());
if (!function_exists('composerRequirece524ce9ef7cab350fa2cef25f67422c')) {
function composerRequirece524ce9ef7cab350fa2cef25f67422c() {
return \RectorPrefix20220220\composerRequirece524ce9ef7cab350fa2cef25f67422c(...func_get_args());
}
}
if (!function_exists('scanPath')) {