Skip to content

Commit

Permalink
Updated Rector to commit 1ff8eea
Browse files Browse the repository at this point in the history
rectorphp/rector-src@1ff8eea [DowngradePhp80] Support match as array item in DowngradeMatchToSwitchRector (#2178)
  • Loading branch information
TomasVotruba committed Apr 30, 2022
1 parent 905102e commit fe9dc1c
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

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;
Expand All @@ -25,6 +27,7 @@
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;
/**
Expand All @@ -34,6 +37,15 @@
*/
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'
Expand Down Expand Up @@ -76,26 +88,38 @@ public function run()
*/
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 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 shouldSkip(\PhpParser\Node\Expr\Match_ $match) : bool
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;
Expand All @@ -104,7 +128,7 @@ private function shouldSkip(\PhpParser\Node\Expr\Match_ $match) : bool
/**
* @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
{
Expand All @@ -129,14 +153,14 @@ private function createSwitchCasesFromMatchArms($node, array $matchArms) : array
}
/**
* @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]);
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit5b02e9827be2f4a223cbc72eb7ab31f5::getLoader();
return ComposerAutoloaderInit97d429f51a9f39c7d8cfa30039f850d9::getLoader();
14 changes: 7 additions & 7 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit5b02e9827be2f4a223cbc72eb7ab31f5
class ComposerAutoloaderInit97d429f51a9f39c7d8cfa30039f850d9
{
private static $loader;

Expand All @@ -22,19 +22,19 @@ public static function getLoader()
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;
Expand All @@ -46,7 +46,7 @@ public static function getLoader()
* @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;
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit5b02e9827be2f4a223cbc72eb7ab31f5
class ComposerStaticInit97d429f51a9f39c7d8cfa30039f850d9
{
public static $files = array (
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/installed.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/rector/extension-installer/src/GeneratedConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
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()
{
}
Expand Down
10 changes: 0 additions & 10 deletions vendor/rector/rector-phpunit/config/sets/phpunit-mock.php

This file was deleted.

2 changes: 2 additions & 0 deletions vendor/rector/rector-phpunit/config/sets/remove-mocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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.
Expand All @@ -22,4 +23,5 @@
$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);
};
4 changes: 0 additions & 4 deletions vendor/rector/rector-phpunit/src/Set/PHPUnitSetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
10 changes: 5 additions & 5 deletions vendor/scoper-autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
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');
Expand Down Expand Up @@ -59,9 +59,9 @@ function 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')) {
Expand Down

0 comments on commit fe9dc1c

Please sign in to comment.