Updated Rector to commit 141923f2484a506bbd523021facb07d37575e62f

141923f248 Remove removeNode() from MultiExceptionCatchRector (#4063)
This commit is contained in:
Tomas Votruba 2023-06-04 17:44:36 +00:00
parent 335ab50008
commit a21bcfc1f7
5 changed files with 27 additions and 56 deletions

View File

@ -4,8 +4,6 @@ declare (strict_types=1);
namespace Rector\Php71\Rector\TryCatch;
use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Catch_;
use PhpParser\Node\Stmt\TryCatch;
use Rector\Core\Contract\PhpParser\NodePrinterInterface;
use Rector\Core\Rector\AbstractRector;
@ -64,55 +62,28 @@ CODE_SAMPLE
if (\count($node->catches) < 2) {
return null;
}
$catchKeysByContent = $this->collectCatchKeysByContent($node);
$hasRemovedCatch = \false;
/** @var Catch_[] $catchKeys */
foreach ($catchKeysByContent as $catchKeys) {
// no duplicates
$count = \count($catchKeys);
if ($count < 2) {
$printedCatches = [];
$hasChanged = \false;
foreach ($node->catches as $key => $catch) {
$currentPrintedCatch = $this->nodePrinter->print($catch->stmts);
// already duplicated catch → remove it and join the type
if (\in_array($currentPrintedCatch, $printedCatches, \true)) {
// merge type to existing type
$existingCatchKey = \array_search($currentPrintedCatch, $printedCatches, \true);
$node->catches[$existingCatchKey]->types[] = $catch->types[0];
unset($node->catches[$key]);
$hasChanged = \true;
continue;
}
$collectedTypes = $this->collectTypesFromCatchedByIds($catchKeys);
/** @var Catch_ $firstCatch */
$firstCatch = \array_shift($catchKeys);
$firstCatch->types = $collectedTypes;
foreach ($catchKeys as $catchKey) {
$this->removeNode($catchKey);
$hasRemovedCatch = \true;
}
$printedCatches[$key] = $currentPrintedCatch;
}
if (!$hasRemovedCatch) {
return null;
if ($hasChanged) {
return $node;
}
return $node;
return null;
}
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::MULTI_EXCEPTION_CATCH;
}
/**
* @return array<string, Catch_[]>
*/
private function collectCatchKeysByContent(TryCatch $tryCatch) : array
{
$catchKeysByContent = [];
foreach ($tryCatch->catches as $catch) {
$catchContent = $this->nodePrinter->print($catch->stmts);
$catchKeysByContent[$catchContent][] = $catch;
}
return $catchKeysByContent;
}
/**
* @param Catch_[] $catches
* @return Name[]
*/
private function collectTypesFromCatchedByIds(array $catches) : array
{
$collectedTypes = [];
foreach ($catches as $catch) {
$collectedTypes = \array_merge($collectedTypes, $catch->types);
}
return $collectedTypes;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '2d99c8b3661934f33155ddb5d46e62c7ba14715a';
public const PACKAGE_VERSION = '141923f2484a506bbd523021facb07d37575e62f';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-06-04 17:22:49';
public const RELEASE_DATE = '2023-06-04 17:36:49';
/**
* @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 ComposerAutoloaderInit960df4dc54c2f3ff405a23f52f0c2f45::getLoader();
return ComposerAutoloaderInit82ed4196913b5b07441c4b4a2e9a4b7c::getLoader();

View File

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