Updated Rector to commit 7f7bb193c5f16dec72e4a9a15f9e1a9eae902985

7f7bb193c5 [PHP 8.0] Create match right from next Throws (#2803)
This commit is contained in:
Tomas Votruba 2022-08-19 13:25:59 +00:00
parent 6b02618a3b
commit 95f1eab654
6 changed files with 48 additions and 57 deletions

View File

@ -91,6 +91,18 @@ final class MatchSwitchAnalyzer
$assignVariableNames = \array_unique($assignVariableNames);
return \count($assignVariableNames) <= 1;
}
/**
* @param CondAndExpr[] $condAndExprs
*/
public function hasCondsAndExprDefaultValue(array $condAndExprs) : bool
{
foreach ($condAndExprs as $condAndExpr) {
if ($condAndExpr->getCondExprs() === null) {
return \true;
}
}
return \false;
}
public function hasDefaultValue(Match_ $match) : bool
{
foreach ($match->arms as $matchArm) {

View File

@ -37,37 +37,30 @@ final class MatchFactory
*/
public function createFromCondAndExprs(Expr $condExpr, array $condAndExprs, ?Stmt $nextStmt) : ?MatchResult
{
$shouldRemoteNextStmt = \false;
// is default value missing? maybe it can be found in next stmt
if (!$this->matchSwitchAnalyzer->hasCondsAndExprDefaultValue($condAndExprs)) {
// 1. is followed by throws stmts?
if ($nextStmt instanceof ThrowsStmt) {
$throw = new Throw_($nextStmt->expr);
$condAndExprs[] = new CondAndExpr([], $throw, MatchKind::RETURN);
$shouldRemoteNextStmt = \true;
}
// 2. is followed by return expr
// implicit return default after switch
if ($nextStmt instanceof Return_ && $nextStmt->expr instanceof Expr) {
// @todo this should be improved
$expr = $this->resolveAssignVar($condAndExprs);
if ($expr instanceof ArrayDimFetch) {
return null;
}
$shouldRemoteNextStmt = !$expr instanceof Expr;
$condAndExprs[] = new CondAndExpr([], $nextStmt->expr, MatchKind::RETURN);
}
}
$matchArms = $this->matchArmsFactory->createFromCondAndExprs($condAndExprs);
$match = new Match_($condExpr, $matchArms);
// implicit return default after switch
if ($nextStmt instanceof Return_ && $nextStmt->expr instanceof Expr) {
return $this->processImplicitReturnAfterSwitch($match, $condAndExprs, $nextStmt->expr);
}
if ($nextStmt instanceof ThrowsStmt) {
return $this->processImplicitThrowsAfterSwitch($match, $condAndExprs, $nextStmt->expr);
}
return new MatchResult($match, \false);
}
/**
* @param CondAndExpr[] $condAndExprs
*/
private function processImplicitReturnAfterSwitch(Match_ $match, array $condAndExprs, Expr $returnExpr) : ?MatchResult
{
if ($this->matchSwitchAnalyzer->hasDefaultValue($match)) {
return new MatchResult($match, \false);
}
$expr = $this->resolveAssignVar($condAndExprs);
if ($expr instanceof ArrayDimFetch) {
return null;
}
$shouldRemoveNextStmt = \false;
if (!$expr instanceof Expr) {
$shouldRemoveNextStmt = \true;
}
$condAndExprs[] = new CondAndExpr([], $returnExpr, MatchKind::RETURN);
$matchArms = $this->matchArmsFactory->createFromCondAndExprs($condAndExprs);
$wrappedMatch = new Match_($match->cond, $matchArms);
return new MatchResult($wrappedMatch, $shouldRemoveNextStmt);
return new MatchResult($match, $shouldRemoteNextStmt);
}
/**
* @param CondAndExpr[] $condAndExprs
@ -83,18 +76,4 @@ final class MatchFactory
}
return null;
}
/**
* @param CondAndExpr[] $condAndExprs
*/
private function processImplicitThrowsAfterSwitch(Match_ $match, array $condAndExprs, Expr $throwExpr) : MatchResult
{
if ($this->matchSwitchAnalyzer->hasDefaultValue($match)) {
return new MatchResult($match, \false);
}
$throw = new Throw_($throwExpr);
$condAndExprs[] = new CondAndExpr([], $throw, MatchKind::RETURN);
$matchArms = $this->matchArmsFactory->createFromCondAndExprs($condAndExprs);
$wrappedMatch = new Match_($match->cond, $matchArms);
return new MatchResult($wrappedMatch, \true);
}
}

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '4bc378bb1846b292946f8c241092a79e863268f7';
public const PACKAGE_VERSION = '7f7bb193c5f16dec72e4a9a15f9e1a9eae902985';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-08-19 14:57:40';
public const RELEASE_DATE = '2022-08-19 15:21:43';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit37acacf548ed5342093e9d3ba7cf411a::getLoader();
return ComposerAutoloaderInitcfa8797e6218a2451bd84105dd9b6e87::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit37acacf548ed5342093e9d3ba7cf411a
class ComposerAutoloaderInitcfa8797e6218a2451bd84105dd9b6e87
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit37acacf548ed5342093e9d3ba7cf411a
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit37acacf548ed5342093e9d3ba7cf411a', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitcfa8797e6218a2451bd84105dd9b6e87', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit37acacf548ed5342093e9d3ba7cf411a', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitcfa8797e6218a2451bd84105dd9b6e87', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit37acacf548ed5342093e9d3ba7cf411a::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitcfa8797e6218a2451bd84105dd9b6e87::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit37acacf548ed5342093e9d3ba7cf411a::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInitcfa8797e6218a2451bd84105dd9b6e87::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire37acacf548ed5342093e9d3ba7cf411a($fileIdentifier, $file);
composerRequirecfa8797e6218a2451bd84105dd9b6e87($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit37acacf548ed5342093e9d3ba7cf411a
* @param string $file
* @return void
*/
function composerRequire37acacf548ed5342093e9d3ba7cf411a($fileIdentifier, $file)
function composerRequirecfa8797e6218a2451bd84105dd9b6e87($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 ComposerStaticInit37acacf548ed5342093e9d3ba7cf411a
class ComposerStaticInitcfa8797e6218a2451bd84105dd9b6e87
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -3254,9 +3254,9 @@ class ComposerStaticInit37acacf548ed5342093e9d3ba7cf411a
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit37acacf548ed5342093e9d3ba7cf411a::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit37acacf548ed5342093e9d3ba7cf411a::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit37acacf548ed5342093e9d3ba7cf411a::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitcfa8797e6218a2451bd84105dd9b6e87::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitcfa8797e6218a2451bd84105dd9b6e87::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitcfa8797e6218a2451bd84105dd9b6e87::$classMap;
}, null, ClassLoader::class);
}