Updated Rector to commit 1ff8eea8be

1ff8eea8be [DowngradePhp80] Support match as array item in DowngradeMatchToSwitchRector (#2178)
This commit is contained in:
Tomas Votruba 2022-04-30 21:35:42 +00:00
parent 905102ea3a
commit fe9dc1c27f
12 changed files with 62 additions and 50 deletions

View File

@ -5,9 +5,11 @@ namespace Rector\DowngradePhp80\Rector\Expression;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Match_;
use PhpParser\Node\Expr\MethodCall;
@ -25,6 +27,7 @@ use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Stmt\Switch_;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Rector\AbstractRector;
use Rector\Php72\NodeFactory\AnonymousFunctionFactory;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -34,6 +37,15 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class DowngradeMatchToSwitchRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @readonly
* @var \Rector\Php72\NodeFactory\AnonymousFunctionFactory
*/
private $anonymousFunctionFactory;
public function __construct(\Rector\Php72\NodeFactory\AnonymousFunctionFactory $anonymousFunctionFactory)
{
$this->anonymousFunctionFactory = $anonymousFunctionFactory;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Downgrade match() to switch()', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
@ -76,26 +88,38 @@ CODE_SAMPLE
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Stmt\Echo_::class, \PhpParser\Node\Stmt\Expression::class, \PhpParser\Node\Stmt\Return_::class];
return [\PhpParser\Node\Expr\ArrayItem::class, \PhpParser\Node\Stmt\Echo_::class, \PhpParser\Node\Stmt\Expression::class, \PhpParser\Node\Stmt\Return_::class];
}
/**
* @param Echo_|Expression|Return_ $node
* @param ArrayItem|Echo_|Expression|Return_ $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
if ($this->shouldSkipNode($node)) {
return null;
}
$match = $this->betterNodeFinder->findFirst($node, function (\PhpParser\Node $subNode) : bool {
return $subNode instanceof \PhpParser\Node\Expr\Match_;
});
if (!$match instanceof \PhpParser\Node\Expr\Match_) {
return null;
}
if ($this->shouldSkip($match)) {
if (!$match instanceof \PhpParser\Node\Expr\Match_ || $this->shouldSkipMatch($match)) {
return null;
}
$switchCases = $this->createSwitchCasesFromMatchArms($node, $match->arms);
return new \PhpParser\Node\Stmt\Switch_($match->cond, $switchCases);
$switch = new \PhpParser\Node\Stmt\Switch_($match->cond, $switchCases);
if ($node instanceof \PhpParser\Node\Expr\ArrayItem) {
$node->value = new \PhpParser\Node\Expr\FuncCall($this->anonymousFunctionFactory->create([], [$switch], null));
return $node;
}
return $switch;
}
private function shouldSkip(\PhpParser\Node\Expr\Match_ $match) : bool
private function shouldSkipNode(\PhpParser\Node $node) : bool
{
if ($node instanceof \PhpParser\Node\Stmt\Return_ && !$node->expr instanceof \PhpParser\Node\Expr\Match_) {
return \true;
}
return \false;
}
private function shouldSkipMatch(\PhpParser\Node\Expr\Match_ $match) : bool
{
return (bool) $this->betterNodeFinder->findFirst($match, function (\PhpParser\Node $subNode) : bool {
return $subNode instanceof \PhpParser\Node\Expr\ArrayItem && $subNode->unpack;
@ -104,7 +128,7 @@ CODE_SAMPLE
/**
* @param MatchArm[] $matchArms
* @return Case_[]
* @param \PhpParser\Node\Stmt\Echo_|\PhpParser\Node\Stmt\Expression|\PhpParser\Node\Stmt\Return_ $node
* @param \PhpParser\Node\Expr\ArrayItem|\PhpParser\Node\Stmt\Echo_|\PhpParser\Node\Stmt\Expression|\PhpParser\Node\Stmt\Return_ $node
*/
private function createSwitchCasesFromMatchArms($node, array $matchArms) : array
{
@ -129,14 +153,14 @@ CODE_SAMPLE
}
/**
* @return Stmt[]
* @param \PhpParser\Node\Stmt\Echo_|\PhpParser\Node\Stmt\Expression|\PhpParser\Node\Stmt\Return_ $node
* @param \PhpParser\Node\Expr\ArrayItem|\PhpParser\Node\Stmt\Echo_|\PhpParser\Node\Stmt\Expression|\PhpParser\Node\Stmt\Return_ $node
*/
private function createSwitchStmts($node, \PhpParser\Node\MatchArm $matchArm) : array
{
$stmts = [];
if ($matchArm->body instanceof \PhpParser\Node\Expr\Throw_) {
$stmts[] = new \PhpParser\Node\Stmt\Expression($matchArm->body);
} elseif ($node instanceof \PhpParser\Node\Stmt\Return_) {
} elseif ($node instanceof \PhpParser\Node\Expr\ArrayItem || $node instanceof \PhpParser\Node\Stmt\Return_) {
$stmts[] = new \PhpParser\Node\Stmt\Return_($matchArm->body);
} elseif ($node instanceof \PhpParser\Node\Stmt\Echo_) {
$stmts[] = new \PhpParser\Node\Stmt\Echo_([$matchArm->body]);

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'c8b47df3e4fbd475e474528391e24d2902cd4a8f';
public const PACKAGE_VERSION = '1ff8eea8be28f11fc52f31d6302c761936818ced';
/**
* @var string
*/
public const RELEASE_DATE = '2022-04-30 08:34:40';
public const RELEASE_DATE = '2022-05-01 04:27:37';
/**
* @var string
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit5b02e9827be2f4a223cbc72eb7ab31f5
class ComposerAutoloaderInit97d429f51a9f39c7d8cfa30039f850d9
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit5b02e9827be2f4a223cbc72eb7ab31f5
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit5b02e9827be2f4a223cbc72eb7ab31f5', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit97d429f51a9f39c7d8cfa30039f850d9', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit5b02e9827be2f4a223cbc72eb7ab31f5', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit97d429f51a9f39c7d8cfa30039f850d9', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit5b02e9827be2f4a223cbc72eb7ab31f5::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit97d429f51a9f39c7d8cfa30039f850d9::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit5b02e9827be2f4a223cbc72eb7ab31f5::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit97d429f51a9f39c7d8cfa30039f850d9::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire5b02e9827be2f4a223cbc72eb7ab31f5($fileIdentifier, $file);
composerRequire97d429f51a9f39c7d8cfa30039f850d9($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit5b02e9827be2f4a223cbc72eb7ab31f5
* @param string $file
* @return void
*/
function composerRequire5b02e9827be2f4a223cbc72eb7ab31f5($fileIdentifier, $file)
function composerRequire97d429f51a9f39c7d8cfa30039f850d9($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 ComposerStaticInit5b02e9827be2f4a223cbc72eb7ab31f5
class ComposerStaticInit97d429f51a9f39c7d8cfa30039f850d9
{
public static $files = array (
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
@ -3881,9 +3881,9 @@ class ComposerStaticInit5b02e9827be2f4a223cbc72eb7ab31f5
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit5b02e9827be2f4a223cbc72eb7ab31f5::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit5b02e9827be2f4a223cbc72eb7ab31f5::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit5b02e9827be2f4a223cbc72eb7ab31f5::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit97d429f51a9f39c7d8cfa30039f850d9::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit97d429f51a9f39c7d8cfa30039f850d9::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit97d429f51a9f39c7d8cfa30039f850d9::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2560,12 +2560,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "1d2f1db15dd82b10cb4644c03db38947c0561ab2"
"reference": "0dd840beea0647c5b9e4e7c7a39c5d2056b6213b"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/1d2f1db15dd82b10cb4644c03db38947c0561ab2",
"reference": "1d2f1db15dd82b10cb4644c03db38947c0561ab2",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/0dd840beea0647c5b9e4e7c7a39c5d2056b6213b",
"reference": "0dd840beea0647c5b9e4e7c7a39c5d2056b6213b",
"shasum": ""
},
"require": {
@ -2590,7 +2590,7 @@
"symplify\/rule-doc-generator": "^10.0",
"symplify\/vendor-patches": "^10.0"
},
"time": "2022-04-29T09:19:35+00:00",
"time": "2022-04-30T09:00:43+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b59802f'), 'rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 8dd58a0'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 784271e'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6d0fcdc'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 31bff78'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main e544f2a'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 1d2f1db'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 06e924b'), 'ssch/typo3-rector' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/ssch/typo3-rector', 'relative_install_path' => '../../../ssch/typo3-rector', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 1f14d62'));
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b59802f'), 'rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 8dd58a0'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 784271e'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 6d0fcdc'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 31bff78'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main e544f2a'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 0dd840b'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 06e924b'), 'ssch/typo3-rector' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/ssch/typo3-rector', 'relative_install_path' => '../../../ssch/typo3-rector', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 1f14d62'));
private function __construct()
{
}

View File

@ -1,10 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220430;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Rector\MethodCall\UseSpecificWillMethodRector;
return static function (\Rector\Config\RectorConfig $rectorConfig) : void {
$rectorConfig->rule(\Rector\PHPUnit\Rector\MethodCall\UseSpecificWillMethodRector::class);
};

View File

@ -7,6 +7,7 @@ use Rector\Config\RectorConfig;
use Rector\PHPUnit\Rector\MethodCall\GetMockBuilderGetMockToCreateMockRector;
use Rector\PHPUnit\Rector\MethodCall\RemoveExpectAnyFromMockRector;
use Rector\PHPUnit\Rector\MethodCall\RemoveSetMethodsMethodCallRector;
use Rector\PHPUnit\Rector\MethodCall\UseSpecificWillMethodRector;
/**
* Set to improve direct testing of your code, without mock overgrown weed everywhere. Make it simple and clear, easy to
* maintain and swift to read.
@ -22,4 +23,5 @@ return static function (\Rector\Config\RectorConfig $rectorConfig) : void {
$rectorConfig->rule(\Rector\PHPUnit\Rector\MethodCall\RemoveSetMethodsMethodCallRector::class);
$rectorConfig->rule(\Rector\PHPUnit\Rector\MethodCall\GetMockBuilderGetMockToCreateMockRector::class);
$rectorConfig->rule(\Rector\PHPUnit\Rector\MethodCall\RemoveExpectAnyFromMockRector::class);
$rectorConfig->rule(\Rector\PHPUnit\Rector\MethodCall\UseSpecificWillMethodRector::class);
};

View File

@ -46,10 +46,6 @@ final class PHPUnitSetList implements \Rector\Set\Contract\SetListInterface
* @var string
*/
public const PHPUNIT_EXCEPTION = __DIR__ . '/../../config/sets/phpunit-exception.php';
/**
* @var string
*/
public const PHPUNIT_MOCK = __DIR__ . '/../../config/sets/phpunit-mock.php';
/**
* @var string
*/

View File

@ -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('RectorPrefix20220430\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit5b02e9827be2f4a223cbc72eb7ab31f5', false) && !interface_exists('ComposerAutoloaderInit5b02e9827be2f4a223cbc72eb7ab31f5', false) && !trait_exists('ComposerAutoloaderInit5b02e9827be2f4a223cbc72eb7ab31f5', false)) {
spl_autoload_call('RectorPrefix20220430\ComposerAutoloaderInit5b02e9827be2f4a223cbc72eb7ab31f5');
if (!class_exists('ComposerAutoloaderInit97d429f51a9f39c7d8cfa30039f850d9', false) && !interface_exists('ComposerAutoloaderInit97d429f51a9f39c7d8cfa30039f850d9', false) && !trait_exists('ComposerAutoloaderInit97d429f51a9f39c7d8cfa30039f850d9', false)) {
spl_autoload_call('RectorPrefix20220430\ComposerAutoloaderInit97d429f51a9f39c7d8cfa30039f850d9');
}
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('RectorPrefix20220430\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220430\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire5b02e9827be2f4a223cbc72eb7ab31f5')) {
function composerRequire5b02e9827be2f4a223cbc72eb7ab31f5() {
return \RectorPrefix20220430\composerRequire5b02e9827be2f4a223cbc72eb7ab31f5(...func_get_args());
if (!function_exists('composerRequire97d429f51a9f39c7d8cfa30039f850d9')) {
function composerRequire97d429f51a9f39c7d8cfa30039f850d9() {
return \RectorPrefix20220430\composerRequire97d429f51a9f39c7d8cfa30039f850d9(...func_get_args());
}
}
if (!function_exists('scanPath')) {