Updated Rector to commit 3df70bdd234efe4c6f49607df5378fb150b111e7

3df70bdd23 Remove NEXT_NODE from RemoveDuplicatedIfReturnRector (#3858)
This commit is contained in:
Tomas Votruba 2023-05-15 13:00:55 +00:00
parent 1e7e201657
commit 73738c0fb1
5 changed files with 18 additions and 40 deletions

View File

@ -4,7 +4,6 @@ declare (strict_types=1);
namespace Rector\DeadCode\Rector\FunctionLike;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Expr\Variable;
@ -18,7 +17,6 @@ use Rector\Core\NodeManipulator\IfManipulator;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\Core\Rector\AbstractRector;
use Rector\DeadCode\NodeCollector\ModifiedVariableNamesCollector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -100,10 +98,10 @@ CODE_SAMPLE
if ($ifWithOnlyReturnsByHash === []) {
return null;
}
$hasRemovedNode = \false;
$hasChanged = \false;
foreach ($ifWithOnlyReturnsByHash as $ifWithOnlyReturns) {
$isBool = $this->isBoolVarIfCondReturnTrueNextReturnBoolVar($ifWithOnlyReturns);
if (!$isBool && \count($ifWithOnlyReturns) < 2) {
if (\count($ifWithOnlyReturns) < 2) {
continue;
}
if (!$isBool) {
@ -112,10 +110,10 @@ CODE_SAMPLE
}
foreach ($ifWithOnlyReturns as $ifWithOnlyReturn) {
$this->removeNode($ifWithOnlyReturn);
$hasRemovedNode = \true;
$hasChanged = \true;
}
}
if ($hasRemovedNode) {
if ($hasChanged) {
return $node;
}
return null;
@ -128,35 +126,15 @@ CODE_SAMPLE
if (\count($ifWithOnlyReturns) > 1) {
return \false;
}
/** @var Expr $cond */
$cond = $ifWithOnlyReturns[0]->cond;
if (!\in_array(\get_class($cond), [Variable::class, PropertyFetch::class, StaticPropertyFetch::class], \true)) {
return \false;
}
$type = $this->nodeTypeResolver->getType($cond);
if (!$type->isBoolean()->yes()) {
return \false;
}
$nextNode = $ifWithOnlyReturns[0]->getAttribute(AttributeKey::NEXT_NODE);
if (!$nextNode instanceof Return_) {
return \false;
}
$expr = $nextNode->expr;
if (!$expr instanceof Expr) {
return \false;
}
if (!$this->nodeComparator->areNodesEqual($expr, $cond)) {
return \false;
}
/** @var Return_ $returnStmt */
$returnStmt = $ifWithOnlyReturns[0]->stmts[0];
if (!$returnStmt->expr instanceof Expr) {
return \false;
}
return $this->valueResolver->isValue($returnStmt->expr, \true);
return $type->isBoolean()->yes();
}
/**
* @return If_[][]
* @return array<string, If_[]>
*/
private function collectDuplicatedIfWithOnlyReturnByHash(FunctionLike $functionLike) : array
{

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '7a86ac22a0535b75f9e525776a315777029d7bdb';
public const PACKAGE_VERSION = '3df70bdd234efe4c6f49607df5378fb150b111e7';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-15 13:43:50';
public const RELEASE_DATE = '2023-05-15 12:57:00';
/**
* @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 ComposerAutoloaderInit82593379e4cd238e3035ce0611679ef9::getLoader();
return ComposerAutoloaderInit90591f1fd31a62e945310977dc81d00a::getLoader();

View File

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