Updated Rector to commit a70d0e5518260479d055a0d5a90e28e43cad58f7

a70d0e5518 [Php54] Rename ArrayToShortArrayRector to LongArrayToShortArrayRector (#2628)
This commit is contained in:
Tomas Votruba 2022-07-03 23:03:40 +00:00
parent 043ee19675
commit b050f5de99
15 changed files with 94 additions and 77 deletions

View File

@ -4,12 +4,12 @@ declare (strict_types=1);
namespace RectorPrefix202207;
use Rector\Config\RectorConfig;
use Rector\Php54\Rector\Array_\ArrayToShortArrayRector;
use Rector\Php54\Rector\Array_\LongArrayToShortArrayRector;
use Rector\Php54\Rector\Break_\RemoveZeroBreakContinueRector;
use Rector\Php54\Rector\FuncCall\RemoveReferenceFromCallRector;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rule(ArrayToShortArrayRector::class);
$rectorConfig->rule(LongArrayToShortArrayRector::class);
$rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, ['mysqli_param_count' => 'mysqli_stmt_param_count']);
$rectorConfig->rule(RemoveReferenceFromCallRector::class);
$rectorConfig->rule(RemoveZeroBreakContinueRector::class);

View File

@ -4541,11 +4541,11 @@ Use ?: instead of ?, where useful
## Php54
### ArrayToShortArrayRector
### LongArrayToShortArrayRector
Array to short array
Long array to short array
- class: [`Rector\Php54\Rector\Array_\ArrayToShortArrayRector`](../rules/Php54/Rector/Array_/ArrayToShortArrayRector.php)
- class: [`Rector\Php54\Rector\Array_\LongArrayToShortArrayRector`](../rules/Php54/Rector/Array_/LongArrayToShortArrayRector.php)
```diff
class SomeClass

View File

@ -12,9 +12,9 @@ use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\Php54\Rector\Array_\ArrayToShortArrayRector\ArrayToShortArrayRectorTest
* @see \Rector\Tests\Php54\Rector\Array_\LongArrayToShortArrayRector\LongArrayToShortArrayRectorTest
*/
final class ArrayToShortArrayRector extends AbstractRector implements MinPhpVersionInterface
final class LongArrayToShortArrayRector extends AbstractRector implements MinPhpVersionInterface
{
public function provideMinPhpVersion() : int
{
@ -22,7 +22,7 @@ final class ArrayToShortArrayRector extends AbstractRector implements MinPhpVers
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Array to short array', [new CodeSample(<<<'CODE_SAMPLE'
return new RuleDefinition('Long array to short array', [new CodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function run()

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '3582024a0d125b8f1706a5c8114f4dbc0a3b0fa1';
public const PACKAGE_VERSION = 'a70d0e5518260479d055a0d5a90e28e43cad58f7';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-07-03 23:58:55';
public const RELEASE_DATE = '2022-07-04 00:57:31';
/**
* @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 ComposerAutoloaderInitdb39726b8fe174bb9d936ed573e06711::getLoader();
return ComposerAutoloaderInitd203fb12c6c92a9b3fb709ce0bac131a::getLoader();

View File

@ -2416,7 +2416,7 @@ return array(
'Rector\\Php53\\Rector\\FuncCall\\DirNameFileConstantToDirConstantRector' => $baseDir . '/rules/Php53/Rector/FuncCall/DirNameFileConstantToDirConstantRector.php',
'Rector\\Php53\\Rector\\Ternary\\TernaryToElvisRector' => $baseDir . '/rules/Php53/Rector/Ternary/TernaryToElvisRector.php',
'Rector\\Php53\\Rector\\Variable\\ReplaceHttpServerVarsByServerRector' => $baseDir . '/rules/Php53/Rector/Variable/ReplaceHttpServerVarsByServerRector.php',
'Rector\\Php54\\Rector\\Array_\\ArrayToShortArrayRector' => $baseDir . '/rules/Php54/Rector/Array_/ArrayToShortArrayRector.php',
'Rector\\Php54\\Rector\\Array_\\LongArrayToShortArrayRector' => $baseDir . '/rules/Php54/Rector/Array_/LongArrayToShortArrayRector.php',
'Rector\\Php54\\Rector\\Break_\\RemoveZeroBreakContinueRector' => $baseDir . '/rules/Php54/Rector/Break_/RemoveZeroBreakContinueRector.php',
'Rector\\Php54\\Rector\\FuncCall\\RemoveReferenceFromCallRector' => $baseDir . '/rules/Php54/Rector/FuncCall/RemoveReferenceFromCallRector.php',
'Rector\\Php55\\Rector\\Class_\\ClassConstantToSelfClassRector' => $baseDir . '/rules/Php55/Rector/Class_/ClassConstantToSelfClassRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitdb39726b8fe174bb9d936ed573e06711
class ComposerAutoloaderInitd203fb12c6c92a9b3fb709ce0bac131a
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInitdb39726b8fe174bb9d936ed573e06711
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitdb39726b8fe174bb9d936ed573e06711', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitd203fb12c6c92a9b3fb709ce0bac131a', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitdb39726b8fe174bb9d936ed573e06711', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitd203fb12c6c92a9b3fb709ce0bac131a', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitdb39726b8fe174bb9d936ed573e06711::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitd203fb12c6c92a9b3fb709ce0bac131a::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInitdb39726b8fe174bb9d936ed573e06711::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInitd203fb12c6c92a9b3fb709ce0bac131a::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequiredb39726b8fe174bb9d936ed573e06711($fileIdentifier, $file);
composerRequired203fb12c6c92a9b3fb709ce0bac131a($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInitdb39726b8fe174bb9d936ed573e06711
* @param string $file
* @return void
*/
function composerRequiredb39726b8fe174bb9d936ed573e06711($fileIdentifier, $file)
function composerRequired203fb12c6c92a9b3fb709ce0bac131a($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 ComposerStaticInitdb39726b8fe174bb9d936ed573e06711
class ComposerStaticInitd203fb12c6c92a9b3fb709ce0bac131a
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -2723,7 +2723,7 @@ class ComposerStaticInitdb39726b8fe174bb9d936ed573e06711
'Rector\\Php53\\Rector\\FuncCall\\DirNameFileConstantToDirConstantRector' => __DIR__ . '/../..' . '/rules/Php53/Rector/FuncCall/DirNameFileConstantToDirConstantRector.php',
'Rector\\Php53\\Rector\\Ternary\\TernaryToElvisRector' => __DIR__ . '/../..' . '/rules/Php53/Rector/Ternary/TernaryToElvisRector.php',
'Rector\\Php53\\Rector\\Variable\\ReplaceHttpServerVarsByServerRector' => __DIR__ . '/../..' . '/rules/Php53/Rector/Variable/ReplaceHttpServerVarsByServerRector.php',
'Rector\\Php54\\Rector\\Array_\\ArrayToShortArrayRector' => __DIR__ . '/../..' . '/rules/Php54/Rector/Array_/ArrayToShortArrayRector.php',
'Rector\\Php54\\Rector\\Array_\\LongArrayToShortArrayRector' => __DIR__ . '/../..' . '/rules/Php54/Rector/Array_/LongArrayToShortArrayRector.php',
'Rector\\Php54\\Rector\\Break_\\RemoveZeroBreakContinueRector' => __DIR__ . '/../..' . '/rules/Php54/Rector/Break_/RemoveZeroBreakContinueRector.php',
'Rector\\Php54\\Rector\\FuncCall\\RemoveReferenceFromCallRector' => __DIR__ . '/../..' . '/rules/Php54/Rector/FuncCall/RemoveReferenceFromCallRector.php',
'Rector\\Php55\\Rector\\Class_\\ClassConstantToSelfClassRector' => __DIR__ . '/../..' . '/rules/Php55/Rector/Class_/ClassConstantToSelfClassRector.php',
@ -3410,9 +3410,9 @@ class ComposerStaticInitdb39726b8fe174bb9d936ed573e06711
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitdb39726b8fe174bb9d936ed573e06711::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitdb39726b8fe174bb9d936ed573e06711::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitdb39726b8fe174bb9d936ed573e06711::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitd203fb12c6c92a9b3fb709ce0bac131a::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitd203fb12c6c92a9b3fb709ce0bac131a::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitd203fb12c6c92a9b3fb709ce0bac131a::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1991,12 +1991,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
"reference": "ba7d7b8458a01e15b30604bdc962f8477285b088"
"reference": "97f49a2bb2262e89a56b27349cf789d96b9b1815"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/ba7d7b8458a01e15b30604bdc962f8477285b088",
"reference": "ba7d7b8458a01e15b30604bdc962f8477285b088",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/97f49a2bb2262e89a56b27349cf789d96b9b1815",
"reference": "97f49a2bb2262e89a56b27349cf789d96b9b1815",
"shasum": ""
},
"require": {
@ -2007,7 +2007,7 @@
},
"require-dev": {
"phpstan\/extension-installer": "^1.1",
"phpstan\/phpstan": "^1.7.10",
"phpstan\/phpstan": "^1.8",
"phpstan\/phpstan-strict-rules": "^1.2",
"phpstan\/phpstan-webmozart-assert": "^1.1",
"phpunit\/phpunit": "^9.5",
@ -2020,7 +2020,7 @@
"symplify\/rule-doc-generator": "^11.0",
"symplify\/vendor-patches": "^11.0"
},
"time": "2022-07-03T21:01:00+00:00",
"time": "2022-07-03T22:06:31+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -2135,12 +2135,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-laravel.git",
"reference": "ab8aaccb0ae2b6e3c1f8b8e56557af684f69fea0"
"reference": "425881a502cc218aabb132e1641f97f7f6704e44"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-laravel\/zipball\/ab8aaccb0ae2b6e3c1f8b8e56557af684f69fea0",
"reference": "ab8aaccb0ae2b6e3c1f8b8e56557af684f69fea0",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-laravel\/zipball\/425881a502cc218aabb132e1641f97f7f6704e44",
"reference": "425881a502cc218aabb132e1641f97f7f6704e44",
"shasum": ""
},
"require": {
@ -2151,7 +2151,7 @@
},
"require-dev": {
"phpstan\/extension-installer": "^1.1",
"phpstan\/phpstan": "^1.7.1",
"phpstan\/phpstan": "^1.8",
"phpstan\/phpstan-strict-rules": "^1.2",
"phpstan\/phpstan-webmozart-assert": "^1.1",
"phpunit\/phpunit": "^9.5",
@ -2164,7 +2164,7 @@
"symplify\/rule-doc-generator": "^11.0",
"symplify\/vendor-patches": "^11.0"
},
"time": "2022-07-03T18:49:55+00:00",
"time": "2022-07-03T22:03:57+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -2202,12 +2202,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-nette.git",
"reference": "3fba0dce341584812463d3be1ab2bc57b48be9fe"
"reference": "bee7c1906f440323abec9eba0fe5b691d23073aa"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-nette\/zipball\/3fba0dce341584812463d3be1ab2bc57b48be9fe",
"reference": "3fba0dce341584812463d3be1ab2bc57b48be9fe",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-nette\/zipball\/bee7c1906f440323abec9eba0fe5b691d23073aa",
"reference": "bee7c1906f440323abec9eba0fe5b691d23073aa",
"shasum": ""
},
"require": {
@ -2225,7 +2225,7 @@
"nette\/di": "^3.0",
"nette\/forms": "3.0.*",
"phpstan\/extension-installer": "^1.1",
"phpstan\/phpstan": "^1.7.10",
"phpstan\/phpstan": "^1.8",
"phpstan\/phpstan-nette": "^1.0",
"phpstan\/phpstan-strict-rules": "^1.2",
"phpstan\/phpstan-webmozart-assert": "^1.1",
@ -2239,7 +2239,7 @@
"symplify\/rule-doc-generator": "^11.0",
"symplify\/vendor-patches": "^11.0"
},
"time": "2022-07-03T20:49:46+00:00",
"time": "2022-07-03T22:04:36+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -2347,12 +2347,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "9bc374804d5b4fa5919f1572524963a3fc9babde"
"reference": "81f779af6098414a559ec94f73563ff1a009d4b5"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/9bc374804d5b4fa5919f1572524963a3fc9babde",
"reference": "9bc374804d5b4fa5919f1572524963a3fc9babde",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/81f779af6098414a559ec94f73563ff1a009d4b5",
"reference": "81f779af6098414a559ec94f73563ff1a009d4b5",
"shasum": ""
},
"require": {
@ -2377,7 +2377,7 @@
"symplify\/rule-doc-generator": "^11.0",
"symplify\/vendor-patches": "^11.0"
},
"time": "2022-07-03T20:42:02+00:00",
"time": "2022-07-03T22:02:54+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -2404,7 +2404,7 @@
"description": "Rector upgrades rules for PHPUnit",
"support": {
"issues": "https:\/\/github.com\/rectorphp\/rector-phpunit\/issues",
"source": "https:\/\/github.com\/rectorphp\/rector-phpunit\/tree\/main"
"source": "https:\/\/github.com\/rectorphp\/rector-phpunit\/tree\/0.13.2"
},
"install-path": "..\/rector\/rector-phpunit"
},

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 86ab8c3'), '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 b177492'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main ba7d7b8'), '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 644d45b'), '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 ab8aacc'), '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 3fba0dc'), '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 d826618'), '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 9bc3748'), '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 d4e61a1'));
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 86ab8c3'), '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 b177492'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 97f49a2'), '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 644d45b'), '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 425881a'), '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 bee7c19'), '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 d826618'), '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 81f779a'), '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 d4e61a1'));
private function __construct()
{
}

View File

@ -8,7 +8,7 @@
},
"require-dev": {
"phpstan\/extension-installer": "^1.1",
"phpstan\/phpstan": "^1.7.10",
"phpstan\/phpstan": "^1.8",
"phpstan\/phpstan-strict-rules": "^1.2",
"phpstan\/phpstan-webmozart-assert": "^1.1",
"phpunit\/phpunit": "^9.5",

View File

@ -9,7 +9,7 @@
"require-dev": {
"rector\/rector-src": "dev-main",
"phpunit\/phpunit": "^9.5",
"phpstan\/phpstan": "^1.7.1",
"phpstan\/phpstan": "^1.8",
"symplify\/phpstan-rules": "^11.0",
"symplify\/phpstan-extensions": "^11.0",
"symplify\/easy-coding-standard": "^11.0",

View File

@ -17,7 +17,7 @@
"symplify\/phpstan-rules": "^11.0",
"symplify\/easy-coding-standard": "^11.0",
"symplify\/monorepo-builder": "^11.0",
"phpstan\/phpstan": "^1.7.10",
"phpstan\/phpstan": "^1.8",
"phpstan\/phpstan-nette": "^1.0",
"nette\/application": "^3.1",
"nette\/di": "^3.0",

View File

@ -7,10 +7,11 @@ use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Expression;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Rector\PHPUnit\NodeFactory\AssertCallFactory;
use Rector\PostRector\Collector\NodesToAddCollector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -32,16 +33,10 @@ final class DelegateExceptionArgumentsRector extends AbstractRector
* @var \Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer
*/
private $testsNodeAnalyzer;
/**
* @readonly
* @var \Rector\PostRector\Collector\NodesToAddCollector
*/
private $nodesToAddCollector;
public function __construct(AssertCallFactory $assertCallFactory, TestsNodeAnalyzer $testsNodeAnalyzer, NodesToAddCollector $nodesToAddCollector)
public function __construct(AssertCallFactory $assertCallFactory, TestsNodeAnalyzer $testsNodeAnalyzer)
{
$this->assertCallFactory = $assertCallFactory;
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
$this->nodesToAddCollector = $nodesToAddCollector;
}
public function getRuleDefinition() : RuleDefinition
{
@ -57,34 +52,56 @@ CODE_SAMPLE
*/
public function getNodeTypes() : array
{
return [MethodCall::class, StaticCall::class];
return [StmtsAwareInterface::class];
}
/**
* @param MethodCall|StaticCall $node
* @param StmtsAwareInterface $node
*/
public function refactor(Node $node) : ?Node
{
$oldMethodNames = \array_keys(self::OLD_TO_NEW_METHOD);
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, $oldMethodNames)) {
$stmts = (array) $node->stmts;
if ($stmts === []) {
return null;
}
if (isset($node->args[1])) {
/** @var Identifier $identifierNode */
$identifierNode = $node->name;
$oldMethodName = $identifierNode->name;
$call = $this->assertCallFactory->createCallWithName($node, self::OLD_TO_NEW_METHOD[$oldMethodName]);
$call->args[] = $node->args[1];
$this->nodesToAddCollector->addNodeAfterNode($call, $node);
unset($node->args[1]);
// add exception code method call
if (isset($node->args[2])) {
$call = $this->assertCallFactory->createCallWithName($node, 'expectExceptionCode');
$call->args[] = $node->args[2];
$this->nodesToAddCollector->addNodeAfterNode($call, $node);
unset($node->args[2]);
$hasChanged = \false;
$oldMethodNames = \array_keys(self::OLD_TO_NEW_METHOD);
foreach ($stmts as $key => $stmt) {
if (!$stmt instanceof Expression) {
continue;
}
if (!$stmt->expr instanceof StaticCall && !$stmt->expr instanceof MethodCall) {
continue;
}
$call = $stmt->expr;
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($call, $oldMethodNames)) {
continue;
}
$extraStmts = [];
if (isset($call->args[1])) {
/** @var Identifier $identifierNode */
$identifierNode = $call->name;
$oldMethodName = $identifierNode->name;
$extraCall = $this->assertCallFactory->createCallWithName($call, self::OLD_TO_NEW_METHOD[$oldMethodName]);
$extraCall->args[] = $call->args[1];
$extraStmts[] = new Expression($extraCall);
unset($call->args[1]);
// add exception code method call
if (isset($call->args[2])) {
$extraCall = $this->assertCallFactory->createCallWithName($call, 'expectExceptionCode');
$extraCall->args[] = $call->args[2];
$extraStmts[] = new Expression($extraCall);
unset($call->args[2]);
}
}
$hasChanged = \true;
$call->name = new Identifier('expectException');
$extraStmts = \array_merge($extraStmts, [new Expression($call)]);
\array_splice($stmts, $key, 1, $extraStmts);
}
$node->name = new Identifier('expectException');
return $node;
if ($hasChanged) {
$node->stmts = $stmts;
return $node;
}
return null;
}
}