diff --git a/rules/Php80/NodeAnalyzer/MatchSwitchAnalyzer.php b/rules/Php80/NodeAnalyzer/MatchSwitchAnalyzer.php index 6fd57e72e07..f18f00da962 100644 --- a/rules/Php80/NodeAnalyzer/MatchSwitchAnalyzer.php +++ b/rules/Php80/NodeAnalyzer/MatchSwitchAnalyzer.php @@ -3,12 +3,16 @@ declare (strict_types=1); namespace Rector\Php80\NodeAnalyzer; +use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Match_; +use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Switch_; use PhpParser\Node\Stmt\Throw_; +use Rector\Core\PhpParser\Comparing\NodeComparator; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Php80\Enum\MatchKind; @@ -25,10 +29,16 @@ final class MatchSwitchAnalyzer * @var \Rector\NodeNameResolver\NodeNameResolver */ private $nodeNameResolver; - public function __construct(\Rector\Php80\NodeAnalyzer\SwitchAnalyzer $switchAnalyzer, \Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver) + /** + * @readonly + * @var \Rector\Core\PhpParser\Comparing\NodeComparator + */ + private $nodeComparator; + public function __construct(\Rector\Php80\NodeAnalyzer\SwitchAnalyzer $switchAnalyzer, \Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\Core\PhpParser\Comparing\NodeComparator $nodeComparator) { $this->switchAnalyzer = $switchAnalyzer; $this->nodeNameResolver = $nodeNameResolver; + $this->nodeComparator = $nodeComparator; } /** * @param CondAndExpr[] $condAndExprs @@ -110,15 +120,32 @@ final class MatchSwitchAnalyzer } private function isNextStmtReturnWithExpr(\PhpParser\Node\Stmt\Switch_ $switch) : bool { - $parent = $switch->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE); - if (!$parent instanceof \PhpParser\Node\Stmt\Return_) { + $next = $switch->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE); + if (!$next instanceof \PhpParser\Node\Stmt\Return_) { return \false; } - return $parent->expr !== null; + if (!$next->expr instanceof \PhpParser\Node\Expr) { + return \false; + } + foreach ($switch->cases as $case) { + /** @var Expression[] $expressions */ + $expressions = \array_filter($case->stmts, function (\PhpParser\Node $node) : bool { + return $node instanceof \PhpParser\Node\Stmt\Expression; + }); + foreach ($expressions as $expression) { + if (!$expression->expr instanceof \PhpParser\Node\Expr\Assign) { + continue; + } + if (!$this->nodeComparator->areNodesEqual($expression->expr->var, $next->expr)) { + return \false; + } + } + } + return \true; } private function isNextStmtThrows(\PhpParser\Node\Stmt\Switch_ $switch) : bool { - $parent = $switch->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE); - return $parent instanceof \PhpParser\Node\Stmt\Throw_; + $next = $switch->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE); + return $next instanceof \PhpParser\Node\Stmt\Throw_; } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 0e4a6fb4d8a..c8d83dbcbf3 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -16,11 +16,11 @@ final class VersionResolver /** * @var string */ - public const PACKAGE_VERSION = 'f90acd4c3ab5541e65dfd49566d6680db9d929d9'; + public const PACKAGE_VERSION = '3f0a0b7259737f77c673c3e7c462a6530c0123f5'; /** * @var string */ - public const RELEASE_DATE = '2022-05-19 21:25:28'; + public const RELEASE_DATE = '2022-05-19 18:23:22'; /** * @var string */ diff --git a/vendor/autoload.php b/vendor/autoload.php index d080ba180cd..aa9c4fd056d 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit278000ff8d716d1a065e7d4ed8beb64b::getLoader(); +return ComposerAutoloaderInit41157f8d50e36491d857618c080429c8::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 158a70b0e44..d6e2ee5e18d 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit278000ff8d716d1a065e7d4ed8beb64b +class ComposerAutoloaderInit41157f8d50e36491d857618c080429c8 { private static $loader; @@ -22,19 +22,19 @@ class ComposerAutoloaderInit278000ff8d716d1a065e7d4ed8beb64b return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit278000ff8d716d1a065e7d4ed8beb64b', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit41157f8d50e36491d857618c080429c8', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit278000ff8d716d1a065e7d4ed8beb64b', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit41157f8d50e36491d857618c080429c8', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit278000ff8d716d1a065e7d4ed8beb64b::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit41157f8d50e36491d857618c080429c8::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $includeFiles = \Composer\Autoload\ComposerStaticInit278000ff8d716d1a065e7d4ed8beb64b::$files; + $includeFiles = \Composer\Autoload\ComposerStaticInit41157f8d50e36491d857618c080429c8::$files; foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire278000ff8d716d1a065e7d4ed8beb64b($fileIdentifier, $file); + composerRequire41157f8d50e36491d857618c080429c8($fileIdentifier, $file); } return $loader; @@ -46,7 +46,7 @@ class ComposerAutoloaderInit278000ff8d716d1a065e7d4ed8beb64b * @param string $file * @return void */ -function composerRequire278000ff8d716d1a065e7d4ed8beb64b($fileIdentifier, $file) +function composerRequire41157f8d50e36491d857618c080429c8($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 f727e170987..9bb36dc9f95 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit278000ff8d716d1a065e7d4ed8beb64b +class ComposerStaticInit41157f8d50e36491d857618c080429c8 { public static $files = array ( '320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php', @@ -3907,9 +3907,9 @@ class ComposerStaticInit278000ff8d716d1a065e7d4ed8beb64b public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit278000ff8d716d1a065e7d4ed8beb64b::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit278000ff8d716d1a065e7d4ed8beb64b::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit278000ff8d716d1a065e7d4ed8beb64b::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit41157f8d50e36491d857618c080429c8::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit41157f8d50e36491d857618c080429c8::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit41157f8d50e36491d857618c080429c8::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/scoper-autoload.php b/vendor/scoper-autoload.php index 22ecce305b9..7495b37da4e 100644 --- a/vendor/scoper-autoload.php +++ b/vendor/scoper-autoload.php @@ -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('RectorPrefix20220519\AutoloadIncluder'); } -if (!class_exists('ComposerAutoloaderInit278000ff8d716d1a065e7d4ed8beb64b', false) && !interface_exists('ComposerAutoloaderInit278000ff8d716d1a065e7d4ed8beb64b', false) && !trait_exists('ComposerAutoloaderInit278000ff8d716d1a065e7d4ed8beb64b', false)) { - spl_autoload_call('RectorPrefix20220519\ComposerAutoloaderInit278000ff8d716d1a065e7d4ed8beb64b'); +if (!class_exists('ComposerAutoloaderInit41157f8d50e36491d857618c080429c8', false) && !interface_exists('ComposerAutoloaderInit41157f8d50e36491d857618c080429c8', false) && !trait_exists('ComposerAutoloaderInit41157f8d50e36491d857618c080429c8', false)) { + spl_autoload_call('RectorPrefix20220519\ComposerAutoloaderInit41157f8d50e36491d857618c080429c8'); } 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('RectorPrefix20220519\Helmich\TypoScriptParser\Parser\AST\Statement'); @@ -59,9 +59,9 @@ if (!function_exists('print_node')) { return \RectorPrefix20220519\print_node(...func_get_args()); } } -if (!function_exists('composerRequire278000ff8d716d1a065e7d4ed8beb64b')) { - function composerRequire278000ff8d716d1a065e7d4ed8beb64b() { - return \RectorPrefix20220519\composerRequire278000ff8d716d1a065e7d4ed8beb64b(...func_get_args()); +if (!function_exists('composerRequire41157f8d50e36491d857618c080429c8')) { + function composerRequire41157f8d50e36491d857618c080429c8() { + return \RectorPrefix20220519\composerRequire41157f8d50e36491d857618c080429c8(...func_get_args()); } } if (!function_exists('scanPath')) {