mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 08:20:53 +00:00
Updated Rector to commit e3e31f5eba
e3e31f5eba
[PHP 8.0] Avoid double default (#176)
This commit is contained in:
parent
ff9660d77a
commit
9e4c2beae4
27
rules/Php80/NodeFactory/MatchFactory.php
Normal file
27
rules/Php80/NodeFactory/MatchFactory.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Php80\NodeFactory;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Match_;
|
||||
use Rector\Php80\ValueObject\CondAndExpr;
|
||||
final class MatchFactory
|
||||
{
|
||||
/**
|
||||
* @var \Rector\Php80\NodeFactory\MatchArmsFactory
|
||||
*/
|
||||
private $matchArmsFactory;
|
||||
public function __construct(\Rector\Php80\NodeFactory\MatchArmsFactory $matchArmsFactory)
|
||||
{
|
||||
$this->matchArmsFactory = $matchArmsFactory;
|
||||
}
|
||||
/**
|
||||
* @param CondAndExpr[] $condAndExprs
|
||||
*/
|
||||
public function createFromCondAndExprs(\PhpParser\Node\Expr $condExpr, array $condAndExprs) : \PhpParser\Node\Expr\Match_
|
||||
{
|
||||
$matchArms = $this->matchArmsFactory->createFromCondAndExprs($condAndExprs);
|
||||
return new \PhpParser\Node\Expr\Match_($condExpr, $matchArms);
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ use PhpParser\Node\Stmt\Switch_;
|
|||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Php80\NodeAnalyzer\MatchSwitchAnalyzer;
|
||||
use Rector\Php80\NodeFactory\MatchArmsFactory;
|
||||
use Rector\Php80\NodeFactory\MatchFactory;
|
||||
use Rector\Php80\NodeResolver\SwitchExprsResolver;
|
||||
use Rector\Php80\ValueObject\CondAndExpr;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
|
@ -37,14 +37,14 @@ final class ChangeSwitchToMatchRector extends \Rector\Core\Rector\AbstractRector
|
|||
*/
|
||||
private $matchSwitchAnalyzer;
|
||||
/**
|
||||
* @var \Rector\Php80\NodeFactory\MatchArmsFactory
|
||||
* @var \Rector\Php80\NodeFactory\MatchFactory
|
||||
*/
|
||||
private $matchArmsFactory;
|
||||
public function __construct(\Rector\Php80\NodeResolver\SwitchExprsResolver $switchExprsResolver, \Rector\Php80\NodeAnalyzer\MatchSwitchAnalyzer $matchSwitchAnalyzer, \Rector\Php80\NodeFactory\MatchArmsFactory $matchArmsFactory)
|
||||
private $matchFactory;
|
||||
public function __construct(\Rector\Php80\NodeResolver\SwitchExprsResolver $switchExprsResolver, \Rector\Php80\NodeAnalyzer\MatchSwitchAnalyzer $matchSwitchAnalyzer, \Rector\Php80\NodeFactory\MatchFactory $matchFactory)
|
||||
{
|
||||
$this->switchExprsResolver = $switchExprsResolver;
|
||||
$this->matchSwitchAnalyzer = $matchSwitchAnalyzer;
|
||||
$this->matchArmsFactory = $matchArmsFactory;
|
||||
$this->matchFactory = $matchFactory;
|
||||
}
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
|
@ -117,8 +117,7 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
}
|
||||
$matchArms = $this->matchArmsFactory->createFromCondAndExprs($condAndExprs);
|
||||
$match = new \PhpParser\Node\Expr\Match_($node->cond, $matchArms);
|
||||
$match = $this->matchFactory->createFromCondAndExprs($node->cond, $condAndExprs);
|
||||
if ($isReturn) {
|
||||
return new \PhpParser\Node\Stmt\Return_($match);
|
||||
}
|
||||
|
@ -135,9 +134,13 @@ CODE_SAMPLE
|
|||
});
|
||||
$assign = new \PhpParser\Node\Expr\Assign($assignExpr, $match);
|
||||
if ($prevInitializedAssign instanceof \PhpParser\Node\Expr\Assign) {
|
||||
/** @var Match_ $expr */
|
||||
$expr = $assign->expr;
|
||||
$expr->arms[] = new \PhpParser\Node\MatchArm(null, $prevInitializedAssign->expr);
|
||||
// avoid double default values
|
||||
$hasDefault = $this->hasDefaultMatchArm($match);
|
||||
if (!$hasDefault) {
|
||||
/** @var Match_ $expr */
|
||||
$expr = $assign->expr;
|
||||
$expr->arms[] = new \PhpParser\Node\MatchArm(null, $prevInitializedAssign->expr);
|
||||
}
|
||||
$parentAssign = $prevInitializedAssign->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
|
||||
if ($parentAssign instanceof \PhpParser\Node\Stmt\Expression) {
|
||||
$this->removeNode($parentAssign);
|
||||
|
@ -159,4 +162,13 @@ CODE_SAMPLE
|
|||
}
|
||||
return null;
|
||||
}
|
||||
private function hasDefaultMatchArm(\PhpParser\Node\Expr\Match_ $match) : bool
|
||||
{
|
||||
foreach ($match->arms as $matchArm) {
|
||||
if ($matchArm->conds === null) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '6e320ce114384a8c03b91668e7f02ae00fe4f047';
|
||||
public const PACKAGE_VERSION = 'e3e31f5eba216cb79f0130e7d6327d65eca0d4b1';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-06-08 07:29:05';
|
||||
public const RELEASE_DATE = '2021-06-08 07:50:11';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20210608\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -4,4 +4,4 @@
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitabad80f769a374b9ecaa5067220a92cc::getLoader();
|
||||
return ComposerAutoloaderInit16373a4a7b44f1d56492a8ac3787ff26::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -2760,6 +2760,7 @@ return array(
|
|||
'Rector\\Php80\\NodeAnalyzer\\SwitchAnalyzer' => $baseDir . '/rules/Php80/NodeAnalyzer/SwitchAnalyzer.php',
|
||||
'Rector\\Php80\\NodeFactory\\AttributeFlagFactory' => $baseDir . '/rules/Php80/NodeFactory/AttributeFlagFactory.php',
|
||||
'Rector\\Php80\\NodeFactory\\MatchArmsFactory' => $baseDir . '/rules/Php80/NodeFactory/MatchArmsFactory.php',
|
||||
'Rector\\Php80\\NodeFactory\\MatchFactory' => $baseDir . '/rules/Php80/NodeFactory/MatchFactory.php',
|
||||
'Rector\\Php80\\NodeFactory\\StrStartsWithFuncCallFactory' => $baseDir . '/rules/Php80/NodeFactory/StrStartsWithFuncCallFactory.php',
|
||||
'Rector\\Php80\\NodeManipulator\\TokenManipulator' => $baseDir . '/rules/Php80/NodeManipulator/TokenManipulator.php',
|
||||
'Rector\\Php80\\NodeResolver\\ArgumentSorter' => $baseDir . '/rules/Php80/NodeResolver/ArgumentSorter.php',
|
||||
|
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitabad80f769a374b9ecaa5067220a92cc
|
||||
class ComposerAutoloaderInit16373a4a7b44f1d56492a8ac3787ff26
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,15 +22,15 @@ class ComposerAutoloaderInitabad80f769a374b9ecaa5067220a92cc
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitabad80f769a374b9ecaa5067220a92cc', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit16373a4a7b44f1d56492a8ac3787ff26', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitabad80f769a374b9ecaa5067220a92cc', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit16373a4a7b44f1d56492a8ac3787ff26', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitabad80f769a374b9ecaa5067220a92cc::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit16373a4a7b44f1d56492a8ac3787ff26::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
|
@ -42,19 +42,19 @@ class ComposerAutoloaderInitabad80f769a374b9ecaa5067220a92cc
|
|||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInitabad80f769a374b9ecaa5067220a92cc::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit16373a4a7b44f1d56492a8ac3787ff26::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequireabad80f769a374b9ecaa5067220a92cc($fileIdentifier, $file);
|
||||
composerRequire16373a4a7b44f1d56492a8ac3787ff26($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequireabad80f769a374b9ecaa5067220a92cc($fileIdentifier, $file)
|
||||
function composerRequire16373a4a7b44f1d56492a8ac3787ff26($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitabad80f769a374b9ecaa5067220a92cc
|
||||
class ComposerStaticInit16373a4a7b44f1d56492a8ac3787ff26
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
|
@ -3115,6 +3115,7 @@ class ComposerStaticInitabad80f769a374b9ecaa5067220a92cc
|
|||
'Rector\\Php80\\NodeAnalyzer\\SwitchAnalyzer' => __DIR__ . '/../..' . '/rules/Php80/NodeAnalyzer/SwitchAnalyzer.php',
|
||||
'Rector\\Php80\\NodeFactory\\AttributeFlagFactory' => __DIR__ . '/../..' . '/rules/Php80/NodeFactory/AttributeFlagFactory.php',
|
||||
'Rector\\Php80\\NodeFactory\\MatchArmsFactory' => __DIR__ . '/../..' . '/rules/Php80/NodeFactory/MatchArmsFactory.php',
|
||||
'Rector\\Php80\\NodeFactory\\MatchFactory' => __DIR__ . '/../..' . '/rules/Php80/NodeFactory/MatchFactory.php',
|
||||
'Rector\\Php80\\NodeFactory\\StrStartsWithFuncCallFactory' => __DIR__ . '/../..' . '/rules/Php80/NodeFactory/StrStartsWithFuncCallFactory.php',
|
||||
'Rector\\Php80\\NodeManipulator\\TokenManipulator' => __DIR__ . '/../..' . '/rules/Php80/NodeManipulator/TokenManipulator.php',
|
||||
'Rector\\Php80\\NodeResolver\\ArgumentSorter' => __DIR__ . '/../..' . '/rules/Php80/NodeResolver/ArgumentSorter.php',
|
||||
|
@ -3874,9 +3875,9 @@ class ComposerStaticInitabad80f769a374b9ecaa5067220a92cc
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitabad80f769a374b9ecaa5067220a92cc::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitabad80f769a374b9ecaa5067220a92cc::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitabad80f769a374b9ecaa5067220a92cc::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit16373a4a7b44f1d56492a8ac3787ff26::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit16373a4a7b44f1d56492a8ac3787ff26::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit16373a4a7b44f1d56492a8ac3787ff26::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
|
@ -21,8 +21,8 @@ if (!class_exists('SomeTestCase', false) && !interface_exists('SomeTestCase', fa
|
|||
if (!class_exists('CheckoutEntityFactory', false) && !interface_exists('CheckoutEntityFactory', false) && !trait_exists('CheckoutEntityFactory', false)) {
|
||||
spl_autoload_call('RectorPrefix20210608\CheckoutEntityFactory');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInitabad80f769a374b9ecaa5067220a92cc', false) && !interface_exists('ComposerAutoloaderInitabad80f769a374b9ecaa5067220a92cc', false) && !trait_exists('ComposerAutoloaderInitabad80f769a374b9ecaa5067220a92cc', false)) {
|
||||
spl_autoload_call('RectorPrefix20210608\ComposerAutoloaderInitabad80f769a374b9ecaa5067220a92cc');
|
||||
if (!class_exists('ComposerAutoloaderInit16373a4a7b44f1d56492a8ac3787ff26', false) && !interface_exists('ComposerAutoloaderInit16373a4a7b44f1d56492a8ac3787ff26', false) && !trait_exists('ComposerAutoloaderInit16373a4a7b44f1d56492a8ac3787ff26', false)) {
|
||||
spl_autoload_call('RectorPrefix20210608\ComposerAutoloaderInit16373a4a7b44f1d56492a8ac3787ff26');
|
||||
}
|
||||
if (!class_exists('Doctrine\Inflector\Inflector', false) && !interface_exists('Doctrine\Inflector\Inflector', false) && !trait_exists('Doctrine\Inflector\Inflector', false)) {
|
||||
spl_autoload_call('RectorPrefix20210608\Doctrine\Inflector\Inflector');
|
||||
|
@ -3323,9 +3323,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20210608\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequireabad80f769a374b9ecaa5067220a92cc')) {
|
||||
function composerRequireabad80f769a374b9ecaa5067220a92cc() {
|
||||
return \RectorPrefix20210608\composerRequireabad80f769a374b9ecaa5067220a92cc(...func_get_args());
|
||||
if (!function_exists('composerRequire16373a4a7b44f1d56492a8ac3787ff26')) {
|
||||
function composerRequire16373a4a7b44f1d56492a8ac3787ff26() {
|
||||
return \RectorPrefix20210608\composerRequire16373a4a7b44f1d56492a8ac3787ff26(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user