mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-30 07:50:53 +00:00
Updated Rector to commit 0389ec89d79713b46f280cc6f028783c1d4e48b8
0389ec89d7
Improve ArraySpreadInsteadOfArrayMergeRector (#3568) (#3589)
This commit is contained in:
parent
7025ec875c
commit
679f8a6710
|
@ -40,8 +40,9 @@ final class ContextAnalyzer
|
|||
}
|
||||
public function isInLoop(Node $node) : bool
|
||||
{
|
||||
$stopNodes = \array_merge(ControlStructure::LOOP_NODES, self::BREAK_NODES);
|
||||
$firstParent = $this->betterNodeFinder->findParentByTypes($node, $stopNodes);
|
||||
$item0Unpacked = ControlStructure::LOOP_NODES;
|
||||
$item1Unpacked = self::BREAK_NODES;
|
||||
$firstParent = $this->betterNodeFinder->findParentByTypes($node, \array_merge($item0Unpacked, $item1Unpacked));
|
||||
if (!$firstParent instanceof Node) {
|
||||
return \false;
|
||||
}
|
||||
|
@ -64,8 +65,8 @@ final class ContextAnalyzer
|
|||
*/
|
||||
public function isInIf(Node $node) : bool
|
||||
{
|
||||
$breakNodes = \array_merge([If_::class], self::BREAK_NODES);
|
||||
$previousNode = $this->betterNodeFinder->findParentByTypes($node, $breakNodes);
|
||||
$item1Unpacked = self::BREAK_NODES;
|
||||
$previousNode = $this->betterNodeFinder->findParentByTypes($node, \array_merge([If_::class], $item1Unpacked));
|
||||
if (!$previousNode instanceof Node) {
|
||||
return \false;
|
||||
}
|
||||
|
|
|
@ -12,8 +12,6 @@ use PhpParser\Node\Expr\FuncCall;
|
|||
use PhpParser\Node\Expr\Ternary;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\StringType;
|
||||
use Rector\Core\Php\PhpVersionProvider;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
|
@ -136,16 +134,13 @@ CODE_SAMPLE
|
|||
}
|
||||
private function isArrayKeyTypeAllowed(ArrayType $arrayType) : bool
|
||||
{
|
||||
$allowedKeyTypes = [IntegerType::class];
|
||||
if ($this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ARRAY_SPREAD_STRING_KEYS)) {
|
||||
$allowedKeyTypes[] = StringType::class;
|
||||
if ($arrayType->getKeyType()->isInteger()->yes()) {
|
||||
return \true;
|
||||
}
|
||||
foreach ($allowedKeyTypes as $allowedKeyType) {
|
||||
if ($arrayType->getKeyType() instanceof $allowedKeyType) {
|
||||
return \true;
|
||||
}
|
||||
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ARRAY_SPREAD_STRING_KEYS)) {
|
||||
return \false;
|
||||
}
|
||||
return \false;
|
||||
return $arrayType->getKeyType()->isString()->yes();
|
||||
}
|
||||
private function resolveValue(Expr $expr) : Expr
|
||||
{
|
||||
|
|
|
@ -115,8 +115,8 @@ CODE_SAMPLE
|
|||
if ($hasReturn) {
|
||||
return \true;
|
||||
}
|
||||
$yieldAndConditionalNodes = \array_merge([Yield_::class], ControlStructure::CONDITIONAL_NODE_SCOPE_TYPES);
|
||||
$hasNotNeverNodes = $this->betterNodeFinder->hasInstancesOfInFunctionLikeScoped($node, $yieldAndConditionalNodes);
|
||||
$item1Unpacked = ControlStructure::CONDITIONAL_NODE_SCOPE_TYPES;
|
||||
$hasNotNeverNodes = $this->betterNodeFinder->hasInstancesOfInFunctionLikeScoped($node, \array_merge([Yield_::class], $item1Unpacked));
|
||||
if ($hasNotNeverNodes) {
|
||||
return \true;
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ CODE_SAMPLE
|
|||
return $this->isName($node->returnType, 'never');
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
private function hasNeverFuncCall($functionLike) : bool
|
||||
{
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '64cca7759d28f2dc0d17acdf55eb10779818726c';
|
||||
public const PACKAGE_VERSION = '0389ec89d79713b46f280cc6f028783c1d4e48b8';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-04-08 14:08:04';
|
||||
public const RELEASE_DATE = '2023-04-08 23:19:08';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit033adc17bbfb50a98dd62d2bd676dc77::getLoader();
|
||||
return ComposerAutoloaderInit52eceb03eedec6c93bf1a3f332a12162::getLoader();
|
||||
|
|
2
vendor/composer/autoload_classmap.php
vendored
2
vendor/composer/autoload_classmap.php
vendored
|
@ -2631,6 +2631,7 @@ return array(
|
|||
'Rector\\Symfony\\Rector\\MethodCall\\FormBuilderSetDataMapperRector' => $vendorDir . '/rector/rector-symfony/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\FormIsValidRector' => $vendorDir . '/rector/rector-symfony/src/Rector/MethodCall/FormIsValidRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\FormTypeInstanceToClassConstRector' => $vendorDir . '/rector/rector-symfony/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\GetCurrencyBundleMethodCallsToIntlRector' => $vendorDir . '/rector/rector-symfony/src/Rector/MethodCall/GetCurrencyBundleMethodCallsToIntlRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\GetHelperControllerToServiceRector' => $vendorDir . '/rector/rector-symfony/src/Rector/MethodCall/GetHelperControllerToServiceRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\GetToConstructorInjectionRector' => $vendorDir . '/rector/rector-symfony/src/Rector/MethodCall/GetToConstructorInjectionRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\LiteralGetToRequestClassConstantRector' => $vendorDir . '/rector/rector-symfony/src/Rector/MethodCall/LiteralGetToRequestClassConstantRector.php',
|
||||
|
@ -2684,6 +2685,7 @@ return array(
|
|||
'Rector\\Symfony\\ValueObject\\EventNameToClassAndConstant' => $vendorDir . '/rector/rector-symfony/src/ValueObject/EventNameToClassAndConstant.php',
|
||||
'Rector\\Symfony\\ValueObject\\EventReferenceToMethodName' => $vendorDir . '/rector/rector-symfony/src/ValueObject/EventReferenceToMethodName.php',
|
||||
'Rector\\Symfony\\ValueObject\\EventReferenceToMethodNameWithPriority' => $vendorDir . '/rector/rector-symfony/src/ValueObject/EventReferenceToMethodNameWithPriority.php',
|
||||
'Rector\\Symfony\\ValueObject\\IntlBundleClassToNewClass' => $vendorDir . '/rector/rector-symfony/src/ValueObject/IntlBundleClassToNewClass.php',
|
||||
'Rector\\Symfony\\ValueObject\\InvokableController\\ActiveClassElements' => $vendorDir . '/rector/rector-symfony/src/ValueObject/InvokableController/ActiveClassElements.php',
|
||||
'Rector\\Symfony\\ValueObject\\ReplaceServiceArgument' => $vendorDir . '/rector/rector-symfony/src/ValueObject/ReplaceServiceArgument.php',
|
||||
'Rector\\Symfony\\ValueObject\\ServiceDefinition' => $vendorDir . '/rector/rector-symfony/src/ValueObject/ServiceDefinition.php',
|
||||
|
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit033adc17bbfb50a98dd62d2bd676dc77
|
||||
class ComposerAutoloaderInit52eceb03eedec6c93bf1a3f332a12162
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit033adc17bbfb50a98dd62d2bd676dc77
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit033adc17bbfb50a98dd62d2bd676dc77', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit52eceb03eedec6c93bf1a3f332a12162', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit033adc17bbfb50a98dd62d2bd676dc77', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit52eceb03eedec6c93bf1a3f332a12162', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit033adc17bbfb50a98dd62d2bd676dc77::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit52eceb03eedec6c93bf1a3f332a12162::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit033adc17bbfb50a98dd62d2bd676dc77::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit52eceb03eedec6c93bf1a3f332a12162::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
10
vendor/composer/autoload_static.php
vendored
10
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit033adc17bbfb50a98dd62d2bd676dc77
|
||||
class ComposerStaticInit52eceb03eedec6c93bf1a3f332a12162
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -2878,6 +2878,7 @@ class ComposerStaticInit033adc17bbfb50a98dd62d2bd676dc77
|
|||
'Rector\\Symfony\\Rector\\MethodCall\\FormBuilderSetDataMapperRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\FormIsValidRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/MethodCall/FormIsValidRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\FormTypeInstanceToClassConstRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\GetCurrencyBundleMethodCallsToIntlRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/MethodCall/GetCurrencyBundleMethodCallsToIntlRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\GetHelperControllerToServiceRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/MethodCall/GetHelperControllerToServiceRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\GetToConstructorInjectionRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/MethodCall/GetToConstructorInjectionRector.php',
|
||||
'Rector\\Symfony\\Rector\\MethodCall\\LiteralGetToRequestClassConstantRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/MethodCall/LiteralGetToRequestClassConstantRector.php',
|
||||
|
@ -2931,6 +2932,7 @@ class ComposerStaticInit033adc17bbfb50a98dd62d2bd676dc77
|
|||
'Rector\\Symfony\\ValueObject\\EventNameToClassAndConstant' => __DIR__ . '/..' . '/rector/rector-symfony/src/ValueObject/EventNameToClassAndConstant.php',
|
||||
'Rector\\Symfony\\ValueObject\\EventReferenceToMethodName' => __DIR__ . '/..' . '/rector/rector-symfony/src/ValueObject/EventReferenceToMethodName.php',
|
||||
'Rector\\Symfony\\ValueObject\\EventReferenceToMethodNameWithPriority' => __DIR__ . '/..' . '/rector/rector-symfony/src/ValueObject/EventReferenceToMethodNameWithPriority.php',
|
||||
'Rector\\Symfony\\ValueObject\\IntlBundleClassToNewClass' => __DIR__ . '/..' . '/rector/rector-symfony/src/ValueObject/IntlBundleClassToNewClass.php',
|
||||
'Rector\\Symfony\\ValueObject\\InvokableController\\ActiveClassElements' => __DIR__ . '/..' . '/rector/rector-symfony/src/ValueObject/InvokableController/ActiveClassElements.php',
|
||||
'Rector\\Symfony\\ValueObject\\ReplaceServiceArgument' => __DIR__ . '/..' . '/rector/rector-symfony/src/ValueObject/ReplaceServiceArgument.php',
|
||||
'Rector\\Symfony\\ValueObject\\ServiceDefinition' => __DIR__ . '/..' . '/rector/rector-symfony/src/ValueObject/ServiceDefinition.php',
|
||||
|
@ -3135,9 +3137,9 @@ class ComposerStaticInit033adc17bbfb50a98dd62d2bd676dc77
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit033adc17bbfb50a98dd62d2bd676dc77::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit033adc17bbfb50a98dd62d2bd676dc77::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit033adc17bbfb50a98dd62d2bd676dc77::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit52eceb03eedec6c93bf1a3f332a12162::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit52eceb03eedec6c93bf1a3f332a12162::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit52eceb03eedec6c93bf1a3f332a12162::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
|
@ -2128,12 +2128,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
|
||||
"reference": "c5abb44d70b66865aa2dee1458b6ffad4257c68d"
|
||||
"reference": "d1e664193f0a04ac303a4fce825b66e1231d32ce"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/c5abb44d70b66865aa2dee1458b6ffad4257c68d",
|
||||
"reference": "c5abb44d70b66865aa2dee1458b6ffad4257c68d",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/d1e664193f0a04ac303a4fce825b66e1231d32ce",
|
||||
"reference": "d1e664193f0a04ac303a4fce825b66e1231d32ce",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2163,7 +2163,7 @@
|
|||
"tomasvotruba\/type-coverage": "^0.0.9",
|
||||
"tomasvotruba\/unused-public": "^0.0.34"
|
||||
},
|
||||
"time": "2023-04-06T11:54:03+00:00",
|
||||
"time": "2023-04-08T15:22:39+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
|
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-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 b88c766'), '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 23e55c6'), '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 8a1a163'), '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 c5abb44'));
|
||||
public const EXTENSIONS = array('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 b88c766'), '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 23e55c6'), '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 8a1a163'), '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 d1e6641'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use Rector\DependencyInjection\Rector\ClassMethod\AddMethodParentCallRector;
|
|||
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
|
||||
use Rector\Renaming\Rector\Name\RenameClassRector;
|
||||
use Rector\Renaming\ValueObject\MethodCallRename;
|
||||
use Rector\Symfony\Rector\MethodCall\GetCurrencyBundleMethodCallsToIntlRector;
|
||||
use Rector\Symfony\Rector\MethodCall\MakeDispatchFirstArgumentEventRector;
|
||||
use Rector\Symfony\Rector\MethodCall\WebTestCaseAssertIsSuccessfulRector;
|
||||
use Rector\Symfony\Rector\MethodCall\WebTestCaseAssertResponseCodeRector;
|
||||
|
@ -18,7 +19,7 @@ use Rector\Symfony\Rector\StmtsAwareInterface\TwigBundleFilesystemLoaderToTwigRe
|
|||
# https://github.com/symfony/symfony/blob/4.4/UPGRADE-4.3.md
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
# https://symfony.com/blog/new-in-symfony-4-3-better-test-assertions
|
||||
$rectorConfig->rules([WebTestCaseAssertIsSuccessfulRector::class, WebTestCaseAssertResponseCodeRector::class, TwigBundleFilesystemLoaderToTwigRector::class, MakeDispatchFirstArgumentEventRector::class]);
|
||||
$rectorConfig->rules([WebTestCaseAssertIsSuccessfulRector::class, WebTestCaseAssertResponseCodeRector::class, TwigBundleFilesystemLoaderToTwigRector::class, MakeDispatchFirstArgumentEventRector::class, GetCurrencyBundleMethodCallsToIntlRector::class]);
|
||||
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [new MethodCallRename('Symfony\\Component\\BrowserKit\\Response', 'getStatus', 'getStatusCode'), new MethodCallRename('Symfony\\Component\\Security\\Http\\Firewall', 'handleRequest', 'callListeners')]);
|
||||
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
|
||||
// assets deprecation
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# 82 Rules Overview
|
||||
# 83 Rules Overview
|
||||
|
||||
## ActionSuffixRemoverRector
|
||||
|
||||
|
@ -676,6 +676,21 @@ Move constructor dependency from form type class to an `$options` parameter
|
|||
|
||||
<br>
|
||||
|
||||
## GetCurrencyBundleMethodCallsToIntlRector
|
||||
|
||||
Intl static bundle method were changed to direct static calls
|
||||
|
||||
- class: [`Rector\Symfony\Rector\MethodCall\GetCurrencyBundleMethodCallsToIntlRector`](../src/Rector/MethodCall/GetCurrencyBundleMethodCallsToIntlRector.php)
|
||||
|
||||
```diff
|
||||
-$currencyBundle = \Symfony\Component\Intl\Intl::getCurrencyBundle();
|
||||
-
|
||||
-$currencyNames = $currencyBundle->getCurrencyNames();
|
||||
+$currencyNames = \Symfony\Component\Intl\Currencies::getNames();
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## GetHelperControllerToServiceRector
|
||||
|
||||
Replace `$this->getDoctrine()` and `$this->dispatchMessage()` calls in AbstractController with direct service use
|
||||
|
|
71
vendor/rector/rector-symfony/src/Rector/MethodCall/GetCurrencyBundleMethodCallsToIntlRector.php
vendored
Normal file
71
vendor/rector/rector-symfony/src/Rector/MethodCall/GetCurrencyBundleMethodCallsToIntlRector.php
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Symfony\Rector\MethodCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Symfony\ValueObject\IntlBundleClassToNewClass;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://symfony.com/blog/new-in-symfony-4-3-simpler-access-to-intl-data
|
||||
* @changelog https://github.com/symfony/symfony/pull/28846
|
||||
*
|
||||
* @see \Rector\Symfony\Tests\Rector\MethodCall\GetCurrencyBundleMethodCallsToIntlRector\GetCurrencyBundleMethodCallsToIntlRectorTest
|
||||
*/
|
||||
final class GetCurrencyBundleMethodCallsToIntlRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var IntlBundleClassToNewClass[]
|
||||
*/
|
||||
private $intlBundleClassesToNewClasses = [];
|
||||
public function __construct()
|
||||
{
|
||||
$this->intlBundleClassesToNewClasses[] = new IntlBundleClassToNewClass('Symfony\\Component\\Intl\\ResourceBundle\\LanguageBundleInterface', 'Symfony\\Component\\Intl\\Languages', ['getLanguageNames' => 'getNames', 'getLanguageName' => 'getName']);
|
||||
$this->intlBundleClassesToNewClasses[] = new IntlBundleClassToNewClass('Symfony\\Component\\Intl\\ResourceBundle\\RegionBundleInterface', 'Symfony\\Component\\Intl\\Currencies', ['getCountryNames' => 'getNames', 'getCountryName' => 'getName']);
|
||||
$this->intlBundleClassesToNewClasses[] = new IntlBundleClassToNewClass('Symfony\\Component\\Intl\\ResourceBundle\\CurrencyBundleInterface', 'Symfony\\Component\\Intl\\Currencies', ['getCurrencyNames' => 'getNames', 'getCurrencyName' => 'getName', 'getCurrencySymbol' => 'getSymbol', 'getFractionDigits' => 'getFractionDigits']);
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Intl static bundle method were changed to direct static calls', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
$currencyBundle = \Symfony\Component\Intl\Intl::getCurrencyBundle();
|
||||
|
||||
$currencyNames = $currencyBundle->getCurrencyNames();
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
$currencyNames = \Symfony\Component\Intl\Currencies::getNames();
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [MethodCall::class];
|
||||
}
|
||||
/**
|
||||
* @param MethodCall $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?StaticCall
|
||||
{
|
||||
foreach ($this->intlBundleClassesToNewClasses as $intlBundleClassToNewClass) {
|
||||
if (!$this->isObjectType($node->var, new ObjectType($intlBundleClassToNewClass->getOldClass()))) {
|
||||
continue;
|
||||
}
|
||||
foreach ($intlBundleClassToNewClass->getOldToNewMethods() as $oldMethodName => $newMethodName) {
|
||||
if (!$this->isName($node->name, $oldMethodName)) {
|
||||
continue;
|
||||
}
|
||||
$currenciesFullyQualified = new FullyQualified($intlBundleClassToNewClass->getNewClass());
|
||||
return new StaticCall($currenciesFullyQualified, $newMethodName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
53
vendor/rector/rector-symfony/src/ValueObject/IntlBundleClassToNewClass.php
vendored
Normal file
53
vendor/rector/rector-symfony/src/ValueObject/IntlBundleClassToNewClass.php
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Symfony\ValueObject;
|
||||
|
||||
use Rector\Core\Validation\RectorAssert;
|
||||
use RectorPrefix202304\Webmozart\Assert\Assert;
|
||||
final class IntlBundleClassToNewClass
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
*/
|
||||
private $oldClass;
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
*/
|
||||
private $newClass;
|
||||
/**
|
||||
* @var array<string, string>
|
||||
* @readonly
|
||||
*/
|
||||
private $oldToNewMethods;
|
||||
/**
|
||||
* @param array<string, string> $oldToNewMethods
|
||||
*/
|
||||
public function __construct(string $oldClass, string $newClass, array $oldToNewMethods)
|
||||
{
|
||||
$this->oldClass = $oldClass;
|
||||
$this->newClass = $newClass;
|
||||
$this->oldToNewMethods = $oldToNewMethods;
|
||||
RectorAssert::className($oldClass);
|
||||
RectorAssert::className($newClass);
|
||||
Assert::allString($oldToNewMethods);
|
||||
Assert::allString(\array_keys($oldToNewMethods));
|
||||
}
|
||||
public function getOldClass() : string
|
||||
{
|
||||
return $this->oldClass;
|
||||
}
|
||||
public function getNewClass() : string
|
||||
{
|
||||
return $this->newClass;
|
||||
}
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getOldToNewMethods() : array
|
||||
{
|
||||
return $this->oldToNewMethods;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user