Updated Rector to commit 2e18cab758224ac96e6affa2fb71f97a1526dfa7

2e18cab758 [EarlyReturn] Skip left or right is BooleanAnd on ChangeOrIfReturnToEarlyReturnRector (#799)
This commit is contained in:
Tomas Votruba 2021-08-31 15:10:56 +00:00
parent d807beef93
commit 52dd92cc24
8 changed files with 28 additions and 31 deletions

View File

@ -104,9 +104,7 @@ CODE_SAMPLE
{
if ($node instanceof \PhpParser\Node\Stmt\ClassMethod) {
$this->refactorClassMethod($node);
// @see https://github.com/rectorphp/rector-src/pull/794
// avoid duplicated ifs and returns when combined with ChangeOrIfReturnToEarlyReturnRector and ChangeAndIfToEarlyReturnRector
return null;
return $node;
}
return $this->refactorProperty($node);
}

View File

@ -5,6 +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\BooleanOr;
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Stmt\If_;
@ -78,7 +79,7 @@ CODE_SAMPLE
if (!$node->cond instanceof \PhpParser\Node\Expr\BinaryOp\BooleanOr) {
return null;
}
if ($this->isInstanceofCondOnly($node->cond)) {
if ($this->isInstanceofCondOnlyOrHasBooleanAnd($node->cond)) {
return null;
}
$nextNode = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE);
@ -137,14 +138,17 @@ CODE_SAMPLE
{
return new \PhpParser\Node\Stmt\If_($expr, ['stmts' => [$return]]);
}
private function isInstanceofCondOnly(\PhpParser\Node\Expr\BinaryOp\BooleanOr $booleanOr) : bool
private function isInstanceofCondOnlyOrHasBooleanAnd(\PhpParser\Node\Expr\BinaryOp\BooleanOr $booleanOr) : bool
{
$currentNode = $booleanOr;
if ($currentNode->left instanceof \PhpParser\Node\Expr\BinaryOp\BooleanAnd || $currentNode->right instanceof \PhpParser\Node\Expr\BinaryOp\BooleanAnd) {
return \true;
}
if ($currentNode->left instanceof \PhpParser\Node\Expr\BinaryOp\BooleanOr) {
return $this->isInstanceofCondOnly($currentNode->left);
return $this->isInstanceofCondOnlyOrHasBooleanAnd($currentNode->left);
}
if ($currentNode->right instanceof \PhpParser\Node\Expr\BinaryOp\BooleanOr) {
return $this->isInstanceofCondOnly($currentNode->right);
return $this->isInstanceofCondOnlyOrHasBooleanAnd($currentNode->right);
}
if (!$currentNode->right instanceof \PhpParser\Node\Expr\Instanceof_) {
return \false;

View File

@ -100,11 +100,6 @@ CODE_SAMPLE
}
private function shouldSkip(\PhpParser\Node\Stmt\If_ $if) : bool
{
// to avoid repetitive If_ creation when used along with ChangeOrIfReturnToEarlyReturnRector
// @see https://github.com/rectorphp/rector-src/pull/651
if ($if->cond instanceof \PhpParser\Node\Expr\BinaryOp\BooleanOr && $if->elseifs !== []) {
return \true;
}
// to avoid repetitive flipped elseif above return when used along with ChangeAndIfReturnToEarlyReturnRector
// @see https://github.com/rectorphp/rector-src/pull/654
return $if->cond instanceof \PhpParser\Node\Expr\BinaryOp\BooleanAnd && \count($if->elseifs) > 1;

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'c42b1969ce3d7d22a0f57beca1e0373e0730c84f';
public const PACKAGE_VERSION = '2e18cab758224ac96e6affa2fb71f97a1526dfa7';
/**
* @var string
*/
public const RELEASE_DATE = '2021-08-31 20:10:36';
public const RELEASE_DATE = '2021-08-31 21:56:48';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20210831\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 ComposerAutoloaderInit16fd6889ce47294594602faab52f0469::getLoader();
return ComposerAutoloaderInit105042a1a8179445770244c9b38bf481::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit16fd6889ce47294594602faab52f0469
class ComposerAutoloaderInit105042a1a8179445770244c9b38bf481
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit16fd6889ce47294594602faab52f0469
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit16fd6889ce47294594602faab52f0469', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit105042a1a8179445770244c9b38bf481', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit16fd6889ce47294594602faab52f0469', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit105042a1a8179445770244c9b38bf481', '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\ComposerStaticInit16fd6889ce47294594602faab52f0469::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit105042a1a8179445770244c9b38bf481::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInit16fd6889ce47294594602faab52f0469
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit16fd6889ce47294594602faab52f0469::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit105042a1a8179445770244c9b38bf481::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire16fd6889ce47294594602faab52f0469($fileIdentifier, $file);
composerRequire105042a1a8179445770244c9b38bf481($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire16fd6889ce47294594602faab52f0469($fileIdentifier, $file)
function composerRequire105042a1a8179445770244c9b38bf481($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit16fd6889ce47294594602faab52f0469
class ComposerStaticInit105042a1a8179445770244c9b38bf481
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -3856,9 +3856,9 @@ class ComposerStaticInit16fd6889ce47294594602faab52f0469
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit16fd6889ce47294594602faab52f0469::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit16fd6889ce47294594602faab52f0469::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit16fd6889ce47294594602faab52f0469::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit105042a1a8179445770244c9b38bf481::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit105042a1a8179445770244c9b38bf481::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit105042a1a8179445770244c9b38bf481::$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('RectorPrefix20210831\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit16fd6889ce47294594602faab52f0469', false) && !interface_exists('ComposerAutoloaderInit16fd6889ce47294594602faab52f0469', false) && !trait_exists('ComposerAutoloaderInit16fd6889ce47294594602faab52f0469', false)) {
spl_autoload_call('RectorPrefix20210831\ComposerAutoloaderInit16fd6889ce47294594602faab52f0469');
if (!class_exists('ComposerAutoloaderInit105042a1a8179445770244c9b38bf481', false) && !interface_exists('ComposerAutoloaderInit105042a1a8179445770244c9b38bf481', false) && !trait_exists('ComposerAutoloaderInit105042a1a8179445770244c9b38bf481', false)) {
spl_autoload_call('RectorPrefix20210831\ComposerAutoloaderInit105042a1a8179445770244c9b38bf481');
}
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('RectorPrefix20210831\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -3311,9 +3311,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20210831\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire16fd6889ce47294594602faab52f0469')) {
function composerRequire16fd6889ce47294594602faab52f0469() {
return \RectorPrefix20210831\composerRequire16fd6889ce47294594602faab52f0469(...func_get_args());
if (!function_exists('composerRequire105042a1a8179445770244c9b38bf481')) {
function composerRequire105042a1a8179445770244c9b38bf481() {
return \RectorPrefix20210831\composerRequire105042a1a8179445770244c9b38bf481(...func_get_args());
}
}
if (!function_exists('parseArgs')) {