mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-29 07:20:52 +00:00
Updated Rector to commit eeacb4fb2889cd04a4ef532c59337089dc8ecb7c
eeacb4fb28
Add support for interface in AnnotationToAttributeRector rule (#2958)
This commit is contained in:
parent
0c28bef447
commit
89cb1be74d
|
@ -11,6 +11,7 @@ use PhpParser\Node\Param;
|
|||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\Use_;
|
||||
use PHPStan\PhpDocParser\Ast\Node as DocNode;
|
||||
|
@ -117,10 +118,10 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Class_::class, Property::class, Param::class, ClassMethod::class, Function_::class, Closure::class, ArrowFunction::class];
|
||||
return [Class_::class, Property::class, Param::class, ClassMethod::class, Function_::class, Closure::class, ArrowFunction::class, Interface_::class];
|
||||
}
|
||||
/**
|
||||
* @param Class_|Property|Param|ClassMethod|Function_|Closure|ArrowFunction $node
|
||||
* @param Class_|Property|Param|ClassMethod|Function_|Closure|ArrowFunction|Interface_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
|
|
|
@ -17,12 +17,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '643c444d936e692a8a0224b7e7c81a74be40d398';
|
||||
public const PACKAGE_VERSION = 'eeacb4fb2889cd04a4ef532c59337089dc8ecb7c';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-09-25 00:32:52';
|
||||
public const RELEASE_DATE = '2022-09-27 16:33:31';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit6f996a84018146e04a5217d95e34e960::getLoader();
|
||||
return ComposerAutoloaderInitd3cbe069ee674e7b3c2958b5a037bb2b::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -2337,6 +2337,7 @@ return array(
|
|||
'Rector\\PhpDocParser\\PhpParser\\SmartPhpParserFactory' => $baseDir . '/packages/PhpDocParser/PhpParser/SmartPhpParserFactory.php',
|
||||
'Rector\\PhpDocParser\\TypeAnalyzer\\ClassMethodReturnTypeResolver' => $baseDir . '/packages/PhpDocParser/TypeAnalyzer/ClassMethodReturnTypeResolver.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\AttributeKey' => $baseDir . '/packages/PhpDocParser/ValueObject/AttributeKey.php',
|
||||
'Rector\\PhpParser\\Rector\\MethodCall\\ParserFactoryRector' => $vendorDir . '/rector/rector-php-parser/src/Rector/MethodCall/ParserFactoryRector.php',
|
||||
'Rector\\PhpParser\\Set\\PhpParserSetList' => $vendorDir . '/rector/rector-php-parser/src/Set/PhpParserSetList.php',
|
||||
'Rector\\PostRector\\Application\\PostFileProcessor' => $baseDir . '/packages/PostRector/Application/PostFileProcessor.php',
|
||||
'Rector\\PostRector\\Collector\\NodesToAddCollector' => $baseDir . '/packages/PostRector/Collector/NodesToAddCollector.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 ComposerAutoloaderInit6f996a84018146e04a5217d95e34e960
|
||||
class ComposerAutoloaderInitd3cbe069ee674e7b3c2958b5a037bb2b
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInit6f996a84018146e04a5217d95e34e960
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit6f996a84018146e04a5217d95e34e960', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitd3cbe069ee674e7b3c2958b5a037bb2b', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit6f996a84018146e04a5217d95e34e960', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitd3cbe069ee674e7b3c2958b5a037bb2b', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit6f996a84018146e04a5217d95e34e960::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitd3cbe069ee674e7b3c2958b5a037bb2b::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit6f996a84018146e04a5217d95e34e960::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInitd3cbe069ee674e7b3c2958b5a037bb2b::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire6f996a84018146e04a5217d95e34e960($fileIdentifier, $file);
|
||||
composerRequired3cbe069ee674e7b3c2958b5a037bb2b($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInit6f996a84018146e04a5217d95e34e960
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire6f996a84018146e04a5217d95e34e960($fileIdentifier, $file)
|
||||
function composerRequired3cbe069ee674e7b3c2958b5a037bb2b($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit6f996a84018146e04a5217d95e34e960
|
||||
class ComposerStaticInitd3cbe069ee674e7b3c2958b5a037bb2b
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -2597,6 +2597,7 @@ class ComposerStaticInit6f996a84018146e04a5217d95e34e960
|
|||
'Rector\\PhpDocParser\\PhpParser\\SmartPhpParserFactory' => __DIR__ . '/../..' . '/packages/PhpDocParser/PhpParser/SmartPhpParserFactory.php',
|
||||
'Rector\\PhpDocParser\\TypeAnalyzer\\ClassMethodReturnTypeResolver' => __DIR__ . '/../..' . '/packages/PhpDocParser/TypeAnalyzer/ClassMethodReturnTypeResolver.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\AttributeKey' => __DIR__ . '/../..' . '/packages/PhpDocParser/ValueObject/AttributeKey.php',
|
||||
'Rector\\PhpParser\\Rector\\MethodCall\\ParserFactoryRector' => __DIR__ . '/..' . '/rector/rector-php-parser/src/Rector/MethodCall/ParserFactoryRector.php',
|
||||
'Rector\\PhpParser\\Set\\PhpParserSetList' => __DIR__ . '/..' . '/rector/rector-php-parser/src/Set/PhpParserSetList.php',
|
||||
'Rector\\PostRector\\Application\\PostFileProcessor' => __DIR__ . '/../..' . '/packages/PostRector/Application/PostFileProcessor.php',
|
||||
'Rector\\PostRector\\Collector\\NodesToAddCollector' => __DIR__ . '/../..' . '/packages/PostRector/Collector/NodesToAddCollector.php',
|
||||
|
@ -3107,9 +3108,9 @@ class ComposerStaticInit6f996a84018146e04a5217d95e34e960
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit6f996a84018146e04a5217d95e34e960::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit6f996a84018146e04a5217d95e34e960::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit6f996a84018146e04a5217d95e34e960::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitd3cbe069ee674e7b3c2958b5a037bb2b::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitd3cbe069ee674e7b3c2958b5a037bb2b::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitd3cbe069ee674e7b3c2958b5a037bb2b::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
11
vendor/composer/installed.json
vendored
11
vendor/composer/installed.json
vendored
|
@ -2061,12 +2061,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-php-parser.git",
|
||||
"reference": "8d6cbe9cb66130011f41050d65e7cf53cae6cc05"
|
||||
"reference": "9c21f5f57464fc5af8765a1007eced8f7f62677c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-php-parser\/zipball\/8d6cbe9cb66130011f41050d65e7cf53cae6cc05",
|
||||
"reference": "8d6cbe9cb66130011f41050d65e7cf53cae6cc05",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-php-parser\/zipball\/9c21f5f57464fc5af8765a1007eced8f7f62677c",
|
||||
"reference": "9c21f5f57464fc5af8765a1007eced8f7f62677c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2083,6 +2083,7 @@
|
|||
"phpunit\/phpunit": "^9.5.21",
|
||||
"rector\/phpstan-rules": "^0.6",
|
||||
"rector\/rector-debugging": "dev-main",
|
||||
"rector\/rector-generator": "^0.6.13",
|
||||
"rector\/rector-src": "dev-main",
|
||||
"symplify\/easy-coding-standard": "^11.1",
|
||||
"symplify\/phpstan-extensions": "^11.1",
|
||||
|
@ -2090,7 +2091,7 @@
|
|||
"symplify\/rule-doc-generator": "^11.1",
|
||||
"symplify\/vendor-patches": "^11.1"
|
||||
},
|
||||
"time": "2022-09-17T07:18:28+00:00",
|
||||
"time": "2022-09-26T00:05:09+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
@ -2117,7 +2118,7 @@
|
|||
"description": "Rector upgrades rules for PHP-Parser",
|
||||
"support": {
|
||||
"issues": "https:\/\/github.com\/rectorphp\/rector-php-parser\/issues",
|
||||
"source": "https:\/\/github.com\/rectorphp\/rector-php-parser\/tree\/main"
|
||||
"source": "https:\/\/github.com\/rectorphp\/rector-php-parser\/tree\/0.14.0"
|
||||
},
|
||||
"install-path": "..\/rector\/rector-php-parser"
|
||||
},
|
||||
|
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
|
@ -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 a489bf0'), '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 c56069f'), '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 d75c674'), '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 2decdcf'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 8d6cbe9'), '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 294de0c'), '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 963c24d'), '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 421857f'));
|
||||
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 a489bf0'), '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 c56069f'), '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 d75c674'), '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 2decdcf'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9c21f5f'), '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 294de0c'), '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 963c24d'), '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 421857f'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
"phpstan\/phpstan-strict-rules": "^1.3",
|
||||
"phpstan\/phpstan-webmozart-assert": "^1.2",
|
||||
"symplify\/vendor-patches": "^11.1",
|
||||
"rector\/rector-debugging": "dev-main"
|
||||
"rector\/rector-debugging": "dev-main",
|
||||
"rector\/rector-generator": "^0.6.13"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
|
@ -4,7 +4,19 @@ declare (strict_types=1);
|
|||
namespace RectorPrefix202209;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
|
||||
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
|
||||
use Rector\Renaming\Rector\Name\RenameClassRector;
|
||||
use Rector\Renaming\ValueObject\MethodCallRename;
|
||||
use Rector\Renaming\ValueObject\RenameClassAndConstFetch;
|
||||
/**
|
||||
* @see https://github.com/nikic/PHP-Parser/blob/master/UPGRADE-5.0.md
|
||||
*/
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, ['PhpParser\\Node\\Expr\\ArrayItem' => 'PhpParser\\Node\\ArrayItem', 'PhpParser\\Node\\Expr\\ClosureUse' => 'PhpParser\\Node\\ClosureUse', 'PhpParser\\Node\\Scalar\\EncapsedStringPart' => 'PhpParser\\Node\\InterpolatedStringPart', 'PhpParser\\Node\\Scalar\\LNumber' => 'PhpParser\\Node\\Scalar\\Int_', 'PhpParser\\Node\\Stmt\\DeclareDeclare' => 'PhpParser\\Node\\DeclareItem', 'PhpParser\\Node\\Stmt\\PropertyProperty' => 'PhpParser\\Node\\PropertyItem', 'PhpParser\\Node\\Stmt\\StaticVar' => 'PhpParser\\Node\\StaticVar']);
|
||||
// https://github.com/nikic/PHP-Parser/blob/master/UPGRADE-5.0.md#renamed-nodes
|
||||
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, ['PhpParser\\Node\\Scalar\\LNumber' => 'PhpParser\\Node\\Scalar\\Int_', 'PhpParser\\Node\\Scalar\\DNumber' => 'PhpParser\\Node\\Scalar\\Float_', 'PhpParser\\Node\\Scalar\\Encapsed' => 'PhpParser\\Node\\Scalar\\InterpolatedString', 'PhpParser\\Node\\Scalar\\EncapsedStringPart' => 'PhpParser\\Node\\InterpolatedStringPart', 'PhpParser\\Node\\Expr\\ArrayItem' => 'PhpParser\\Node\\ArrayItem', 'PhpParser\\Node\\Expr\\ClosureUse' => 'PhpParser\\Node\\ClosureUse', 'PhpParser\\Node\\Stmt\\DeclareDeclare' => 'PhpParser\\Node\\DeclareItem', 'PhpParser\\Node\\Stmt\\PropertyProperty' => 'PhpParser\\Node\\PropertyItem', 'PhpParser\\Node\\Stmt\\StaticVar' => 'PhpParser\\Node\\StaticVar', 'PhpParser\\Node\\Stmt\\UseUse' => 'PhpParser\\Node\\UseItem']);
|
||||
// https://github.com/nikic/PHP-Parser/blob/master/UPGRADE-5.0.md#modifiers
|
||||
$rectorConfig->ruleWithConfiguration(RenameClassConstFetchRector::class, [new RenameClassAndConstFetch('PhpParser\\Node\\Stmt\\Class_', 'MODIFIER_PUBLIC', 'PhpParser\\Modifiers', 'PUBLIC'), new RenameClassAndConstFetch('PhpParser\\Node\\Stmt\\Class_', 'MODIFIER_PUBLIC', 'PhpParser\\Modifiers', 'PUBLIC'), new RenameClassAndConstFetch('PhpParser\\Node\\Stmt\\Class_', 'MODIFIER_PROTECTED', 'PhpParser\\Modifiers', 'PROTECTED'), new RenameClassAndConstFetch('PhpParser\\Node\\Stmt\\Class_', 'MODIFIER_PRIVATE', 'PhpParser\\Modifiers', 'PRIVATE'), new RenameClassAndConstFetch('PhpParser\\Node\\Stmt\\Class_', 'MODIFIER_STATIC', 'PhpParser\\Modifiers', 'STATIC'), new RenameClassAndConstFetch('PhpParser\\Node\\Stmt\\Class_', 'MODIFIER_ABSTRACT', 'PhpParser\\Modifiers', 'ABSTRACT'), new RenameClassAndConstFetch('PhpParser\\Node\\Stmt\\Class_', 'MODIFIER_FINAL', 'PhpParser\\Modifiers', 'FINAL'), new RenameClassAndConstFetch('PhpParser\\Node\\Stmt\\Class_', 'MODIFIER_READONLY', 'PhpParser\\Modifiers', 'READONLY'), new RenameClassAndConstFetch('PhpParser\\Node\\Stmt\\Class_', 'VISIBILITY_MODIFIER_MASK', 'PhpParser\\Modifiers', 'VISIBILITY_MASK')]);
|
||||
// https://github.com/nikic/PHP-Parser/blob/master/UPGRADE-5.0.md#other-removed-functionality
|
||||
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [new MethodCallRename('PhpParser\\Node\\Expr\\MethodCall', 'setTypeHint', 'setType')]);
|
||||
};
|
||||
|
|
|
@ -1 +1,18 @@
|
|||
# 0 Rules Overview
|
||||
# 1 Rules Overview
|
||||
|
||||
## ParserFactoryRector
|
||||
|
||||
Upgrade ParserFactory `create()` method
|
||||
|
||||
- class: [`Rector\PhpParser\Rector\MethodCall\ParserFactoryRector`](../src/Rector/MethodCall/ParserFactoryRector.php)
|
||||
|
||||
```diff
|
||||
use PhpParser\ParserFactory;
|
||||
|
||||
$factory = new ParserFactory;
|
||||
|
||||
-$parser = $factory->create(ParserFactory::PREFER_PHP7);
|
||||
+$parser = $factory->createForNewestSupportedVersion();
|
||||
```
|
||||
|
||||
<br>
|
||||
|
|
1
vendor/rector/rector-php-parser/rector.php
vendored
1
vendor/rector/rector-php-parser/rector.php
vendored
|
@ -12,5 +12,6 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
$rectorConfig->importNames();
|
||||
$rectorConfig->paths([__DIR__ . '/src', __DIR__ . '/tests']);
|
||||
$rectorConfig->skip([StringClassNameToClassConstantRector::class => [__DIR__ . '/config']]);
|
||||
$rectorConfig->ruleWithConfiguration(StringClassNameToClassConstantRector::class, ['PhpParser\\PhpVersion', 'PhpParser\\ParserFactory']);
|
||||
$rectorConfig->parallel();
|
||||
};
|
||||
|
|
76
vendor/rector/rector-php-parser/src/Rector/MethodCall/ParserFactoryRector.php
vendored
Normal file
76
vendor/rector/rector-php-parser/src/Rector/MethodCall/ParserFactoryRector.php
vendored
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PhpParser\Rector\MethodCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://github.com/nikic/PHP-Parser/blob/master/UPGRADE-5.0.md#changes-to-the-parser-factory
|
||||
*
|
||||
* @see \Rector\PhpParser\Tests\Rector\MethodCall\ParserFactoryRector\ParserFactoryRectorTest
|
||||
*/
|
||||
final class ParserFactoryRector extends AbstractRector
|
||||
{
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Upgrade ParserFactory create() method', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
use PhpParser\ParserFactory;
|
||||
|
||||
$factory = new ParserFactory;
|
||||
|
||||
$parser = $factory->create(ParserFactory::PREFER_PHP7);
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
use PhpParser\ParserFactory;
|
||||
|
||||
$factory = new ParserFactory;
|
||||
|
||||
$parser = $factory->createForNewestSupportedVersion();
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [MethodCall::class];
|
||||
}
|
||||
/**
|
||||
* @param MethodCall $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$this->isObjectType($node->var, new ObjectType('PhpParser\\ParserFactory'))) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($node->name, 'create')) {
|
||||
return null;
|
||||
}
|
||||
$args = $node->getArgs();
|
||||
$value = $this->valueResolver->getValue($args[0]->value);
|
||||
if ($value === 1) {
|
||||
$node->name = new Identifier('createForNewestSupportedVersion');
|
||||
$node->args = [];
|
||||
return $node;
|
||||
}
|
||||
if ($value === 4) {
|
||||
$node->name = new Identifier('createForVersion');
|
||||
$fullyQualified = new FullyQualified('PhpParser\\PhpVersion');
|
||||
$fromStringStaticCall = new StaticCall($fullyQualified, 'fromString', [new Arg(new String_('5.6'))]);
|
||||
$node->args = [new Arg($fromStringStaticCall)];
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user