diff --git a/rules/Php71/Rector/TryCatch/MultiExceptionCatchRector.php b/rules/Php71/Rector/TryCatch/MultiExceptionCatchRector.php index f2f9d86e877..65c86155363 100644 --- a/rules/Php71/Rector/TryCatch/MultiExceptionCatchRector.php +++ b/rules/Php71/Rector/TryCatch/MultiExceptionCatchRector.php @@ -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 - */ - 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; - } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 89654f5bf18..217cddef74a 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -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 */ diff --git a/vendor/autoload.php b/vendor/autoload.php index a363da5941f..969f121c0c2 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit960df4dc54c2f3ff405a23f52f0c2f45::getLoader(); +return ComposerAutoloaderInit82ed4196913b5b07441c4b4a2e9a4b7c::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 53c292bb140..a34793b7ec5 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -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; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 1ad0cf76eb1..f5678c1493d 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -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); }