mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-24 17:36:02 +02:00
Updated Rector to commit 0afc961f2b1e7d3d1f86250fe795e3176e6527b3
0afc961f2b
Update actions/checkout v2 to v3 (#4348)
This commit is contained in:
parent
ebab7418f4
commit
e5f365df87
.github/workflows
along_other_packages.yamlbare_run.yamle2e.yamle2e_diff.yamle2e_global.yamle2e_php72.yamle2e_php74.yamlstandalone_rule_test.yaml
src/Application
vendor
2
.github/workflows/along_other_packages.yaml
vendored
2
.github/workflows/along_other_packages.yaml
vendored
@ -31,7 +31,7 @@ jobs:
|
||||
name: "PHP ${{ matrix.php_version }}"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
|
2
.github/workflows/bare_run.yaml
vendored
2
.github/workflows/bare_run.yaml
vendored
@ -16,7 +16,7 @@ jobs:
|
||||
php_version: ['7.2', '7.3', '7.4', '8.0', '8.1']
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
-
|
||||
uses: shivammathur/setup-php@v2
|
||||
|
2
.github/workflows/e2e.yaml
vendored
2
.github/workflows/e2e.yaml
vendored
@ -26,7 +26,7 @@ jobs:
|
||||
name: End to end test - ${{ matrix.directory }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
|
2
.github/workflows/e2e_diff.yaml
vendored
2
.github/workflows/e2e_diff.yaml
vendored
@ -22,7 +22,7 @@ jobs:
|
||||
name: End to end test with diff - ${{ matrix.directory }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
|
2
.github/workflows/e2e_global.yaml
vendored
2
.github/workflows/e2e_global.yaml
vendored
@ -19,7 +19,7 @@ jobs:
|
||||
name: End to end test - ${{ matrix.directory }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
|
2
.github/workflows/e2e_php72.yaml
vendored
2
.github/workflows/e2e_php72.yaml
vendored
@ -13,7 +13,7 @@ jobs:
|
||||
name: End to end test - PHP 7.2 with load ReflectionUnionType stub
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
|
2
.github/workflows/e2e_php74.yaml
vendored
2
.github/workflows/e2e_php74.yaml
vendored
@ -16,7 +16,7 @@ jobs:
|
||||
name: End to end test - PHP 7.4 and Match class name
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
|
2
.github/workflows/standalone_rule_test.yaml
vendored
2
.github/workflows/standalone_rule_test.yaml
vendored
@ -19,7 +19,7 @@ jobs:
|
||||
name: End to end test - ${{ matrix.directory }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '6cc42eb33187a9b77357c1f459d724c8aa1eb4f7';
|
||||
public const PACKAGE_VERSION = '0afc961f2b1e7d3d1f86250fe795e3176e6527b3';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-06-26 00:02:05';
|
||||
public const RELEASE_DATE = '2023-06-26 07:12:21';
|
||||
/**
|
||||
* @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 ComposerAutoloaderInit63c0cd1f8e04b29f96bbff647001340d::getLoader();
|
||||
return ComposerAutoloaderInit1ed4b401ef7dbc14a301a251d50c8c4e::getLoader();
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -2517,6 +2517,7 @@ return array(
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\Class_\\EventListenerToEventSubscriberRector' => $vendorDir . '/rector/rector-symfony/rules/CodeQuality/Rector/Class_/EventListenerToEventSubscriberRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\Class_\\LoadValidatorMetadataToAnnotationRector' => $vendorDir . '/rector/rector-symfony/rules/CodeQuality/Rector/Class_/LoadValidatorMetadataToAnnotationRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\Class_\\MakeCommandLazyRector' => $vendorDir . '/rector/rector-symfony/rules/CodeQuality/Rector/Class_/MakeCommandLazyRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\Closure\\StringExtensionToConfigBuilderRector' => $vendorDir . '/rector/rector-symfony/rules/CodeQuality/Rector/Closure/StringExtensionToConfigBuilderRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\MethodCall\\LiteralGetToRequestClassConstantRector' => $vendorDir . '/rector/rector-symfony/rules/CodeQuality/Rector/MethodCall/LiteralGetToRequestClassConstantRector.php',
|
||||
'Rector\\Symfony\\Contract\\Bridge\\Symfony\\Routing\\SymfonyRoutesProviderInterface' => $vendorDir . '/rector/rector-symfony/src/Contract/Bridge/Symfony/Routing/SymfonyRoutesProviderInterface.php',
|
||||
'Rector\\Symfony\\Contract\\EventReferenceToMethodNameInterface' => $vendorDir . '/rector/rector-symfony/src/Contract/EventReferenceToMethodNameInterface.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 ComposerAutoloaderInit63c0cd1f8e04b29f96bbff647001340d
|
||||
class ComposerAutoloaderInit1ed4b401ef7dbc14a301a251d50c8c4e
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit63c0cd1f8e04b29f96bbff647001340d
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit63c0cd1f8e04b29f96bbff647001340d', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit1ed4b401ef7dbc14a301a251d50c8c4e', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit63c0cd1f8e04b29f96bbff647001340d', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit1ed4b401ef7dbc14a301a251d50c8c4e', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit63c0cd1f8e04b29f96bbff647001340d::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit1ed4b401ef7dbc14a301a251d50c8c4e::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit63c0cd1f8e04b29f96bbff647001340d::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit1ed4b401ef7dbc14a301a251d50c8c4e::$files;
|
||||
$requireFile = \Closure::bind(static function ($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 ComposerStaticInit63c0cd1f8e04b29f96bbff647001340d
|
||||
class ComposerStaticInit1ed4b401ef7dbc14a301a251d50c8c4e
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -2769,6 +2769,7 @@ class ComposerStaticInit63c0cd1f8e04b29f96bbff647001340d
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\Class_\\EventListenerToEventSubscriberRector' => __DIR__ . '/..' . '/rector/rector-symfony/rules/CodeQuality/Rector/Class_/EventListenerToEventSubscriberRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\Class_\\LoadValidatorMetadataToAnnotationRector' => __DIR__ . '/..' . '/rector/rector-symfony/rules/CodeQuality/Rector/Class_/LoadValidatorMetadataToAnnotationRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\Class_\\MakeCommandLazyRector' => __DIR__ . '/..' . '/rector/rector-symfony/rules/CodeQuality/Rector/Class_/MakeCommandLazyRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\Closure\\StringExtensionToConfigBuilderRector' => __DIR__ . '/..' . '/rector/rector-symfony/rules/CodeQuality/Rector/Closure/StringExtensionToConfigBuilderRector.php',
|
||||
'Rector\\Symfony\\CodeQuality\\Rector\\MethodCall\\LiteralGetToRequestClassConstantRector' => __DIR__ . '/..' . '/rector/rector-symfony/rules/CodeQuality/Rector/MethodCall/LiteralGetToRequestClassConstantRector.php',
|
||||
'Rector\\Symfony\\Contract\\Bridge\\Symfony\\Routing\\SymfonyRoutesProviderInterface' => __DIR__ . '/..' . '/rector/rector-symfony/src/Contract/Bridge/Symfony/Routing/SymfonyRoutesProviderInterface.php',
|
||||
'Rector\\Symfony\\Contract\\EventReferenceToMethodNameInterface' => __DIR__ . '/..' . '/rector/rector-symfony/src/Contract/EventReferenceToMethodNameInterface.php',
|
||||
@ -3091,9 +3092,9 @@ class ComposerStaticInit63c0cd1f8e04b29f96bbff647001340d
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit63c0cd1f8e04b29f96bbff647001340d::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit63c0cd1f8e04b29f96bbff647001340d::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit63c0cd1f8e04b29f96bbff647001340d::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit1ed4b401ef7dbc14a301a251d50c8c4e::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit1ed4b401ef7dbc14a301a251d50c8c4e::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit1ed4b401ef7dbc14a301a251d50c8c4e::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
22
vendor/composer/installed.json
vendored
22
vendor/composer/installed.json
vendored
@ -2121,12 +2121,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
|
||||
"reference": "50406b3aa17688ffde6b2014db647b3bb9698a14"
|
||||
"reference": "b1145207d3bef13e660ce3039aff66daec54c8c6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/50406b3aa17688ffde6b2014db647b3bb9698a14",
|
||||
"reference": "50406b3aa17688ffde6b2014db647b3bb9698a14",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/b1145207d3bef13e660ce3039aff66daec54c8c6",
|
||||
"reference": "b1145207d3bef13e660ce3039aff66daec54c8c6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2156,7 +2156,7 @@
|
||||
"tomasvotruba\/type-coverage": "^0.2",
|
||||
"tomasvotruba\/unused-public": "^0.1"
|
||||
},
|
||||
"time": "2023-06-24T15:57:02+00:00",
|
||||
"time": "2023-06-25T19:41:36+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
@ -2622,17 +2622,17 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony\/filesystem",
|
||||
"version": "v6.3.0",
|
||||
"version_normalized": "6.3.0.0",
|
||||
"version": "v6.3.1",
|
||||
"version_normalized": "6.3.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/symfony\/filesystem.git",
|
||||
"reference": "97b698e1d77d356304def77a8d0cd73090b359ea"
|
||||
"reference": "edd36776956f2a6fcf577edb5b05eb0e3bdc52ae"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/symfony\/filesystem\/zipball\/97b698e1d77d356304def77a8d0cd73090b359ea",
|
||||
"reference": "97b698e1d77d356304def77a8d0cd73090b359ea",
|
||||
"url": "https:\/\/api.github.com\/repos\/symfony\/filesystem\/zipball\/edd36776956f2a6fcf577edb5b05eb0e3bdc52ae",
|
||||
"reference": "edd36776956f2a6fcf577edb5b05eb0e3bdc52ae",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2640,7 +2640,7 @@
|
||||
"symfony\/polyfill-ctype": "~1.8",
|
||||
"symfony\/polyfill-mbstring": "~1.8"
|
||||
},
|
||||
"time": "2023-05-30T17:12:32+00:00",
|
||||
"time": "2023-06-01T08:30:39+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
@ -2668,7 +2668,7 @@
|
||||
"description": "Provides basic utilities for the filesystem",
|
||||
"homepage": "https:\/\/symfony.com",
|
||||
"support": {
|
||||
"source": "https:\/\/github.com\/symfony\/filesystem\/tree\/v6.3.0"
|
||||
"source": "https:\/\/github.com\/symfony\/filesystem\/tree\/v6.3.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
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 f0c1a5f'), '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 b19346b'), '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 e60de61'), '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 50406b3'));
|
||||
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 f0c1a5f'), '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 b19346b'), '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 e60de61'), '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 b114520'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
# 79 Rules Overview
|
||||
# 80 Rules Overview
|
||||
|
||||
## ActionSuffixRemoverRector
|
||||
|
||||
@ -289,7 +289,7 @@ Turns old default value to parameter in `ContainerBuilder->build()` method in DI
|
||||
|
||||
Change `$container->get("some_name")` to bare type, useful since Symfony 3.4
|
||||
|
||||
- class: [`Rector\Symfony\Symfony34\Rector\Closure\ContainerGetNameToTypeInTestsRector`](../src/Symfony34/Rector/Closure/ContainerGetNameToTypeInTestsRector.php)
|
||||
- class: [`Rector\Symfony\Symfony34\Rector\Closure\ContainerGetNameToTypeInTestsRector`](../rules/Symfony34/Rector/Closure/ContainerGetNameToTypeInTestsRector.php)
|
||||
|
||||
```diff
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@ -1507,7 +1507,7 @@ Change `$services->set("name_type",` SomeType::class) to bare type, useful since
|
||||
|
||||
Changes Twig_Function_Method to Twig_SimpleFunction calls in Twig_Extension.
|
||||
|
||||
- class: [`Rector\Symfony\Rector\Return_\SimpleFunctionAndFilterRector`](../src/Rector/Return_/SimpleFunctionAndFilterRector.php)
|
||||
- class: [`Rector\Symfony\Twig134\Rector\Return_\SimpleFunctionAndFilterRector`](../rules/Twig134/Rector/Return_/SimpleFunctionAndFilterRector.php)
|
||||
|
||||
```diff
|
||||
class SomeExtension extends Twig_Extension
|
||||
@ -1555,6 +1555,43 @@ Symplify form rendering by not calling `->createView()` on `render` function
|
||||
|
||||
<br>
|
||||
|
||||
## StringExtensionToConfigBuilderRector
|
||||
|
||||
Add config builder classes
|
||||
|
||||
- class: [`Rector\Symfony\CodeQuality\Rector\Closure\StringExtensionToConfigBuilderRector`](../rules/CodeQuality/Rector/Closure/StringExtensionToConfigBuilderRector.php)
|
||||
|
||||
```diff
|
||||
-use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
+use Symfony\Config\SecurityConfig;
|
||||
|
||||
-return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
- $containerConfigurator->extension('security', [
|
||||
- 'providers' => [
|
||||
- 'webservice' => [
|
||||
- 'id' => LoginServiceUserProvider::class,
|
||||
- ],
|
||||
- ],
|
||||
- 'firewalls' => [
|
||||
- 'dev' => [
|
||||
- 'pattern' => '^/(_(profiler|wdt)|css|images|js)/',
|
||||
- 'security' => false,
|
||||
- ],
|
||||
- ],
|
||||
+return static function (SecurityConfig $securityConfig): void {
|
||||
+ $securityConfig->provider('webservice', [
|
||||
+ 'id' => LoginServiceUserProvider::class,
|
||||
+ ]);
|
||||
+
|
||||
+ $securityConfig->firewall('dev', [
|
||||
+ 'pattern' => '^/(_(profiler|wdt)|css|images|js)/',
|
||||
+ 'security' => false,
|
||||
]);
|
||||
};
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## StringFormTypeToClassRector
|
||||
|
||||
Turns string Form Type references to their CONSTANT alternatives in FormTypes in Form in Symfony. To enable custom types, add link to your container XML dump in "$rectorConfig->symfonyContainerXml(...)"
|
||||
|
142
vendor/rector/rector-symfony/rules/CodeQuality/Rector/Closure/StringExtensionToConfigBuilderRector.php
vendored
Normal file
142
vendor/rector/rector-symfony/rules/CodeQuality/Rector/Closure/StringExtensionToConfigBuilderRector.php
vendored
Normal file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Symfony\CodeQuality\Rector\Closure;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\Core\Exception\NotImplementedYetException;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Symfony\NodeAnalyzer\SymfonyPhpClosureDetector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://symfony.com/blog/new-in-symfony-5-3-config-builder-classes
|
||||
*
|
||||
* @see \Rector\Symfony\Tests\CodeQuality\Rector\Closure\StringExtensionToConfigBuilderRector\StringExtensionToConfigBuilderRectorTest
|
||||
*/
|
||||
final class StringExtensionToConfigBuilderRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Symfony\NodeAnalyzer\SymfonyPhpClosureDetector
|
||||
*/
|
||||
private $symfonyPhpClosureDetector;
|
||||
public function __construct(SymfonyPhpClosureDetector $symfonyPhpClosureDetector)
|
||||
{
|
||||
$this->symfonyPhpClosureDetector = $symfonyPhpClosureDetector;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Add config builder classes', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$containerConfigurator->extension('security', [
|
||||
'providers' => [
|
||||
'webservice' => [
|
||||
'id' => LoginServiceUserProvider::class,
|
||||
],
|
||||
],
|
||||
'firewalls' => [
|
||||
'dev' => [
|
||||
'pattern' => '^/(_(profiler|wdt)|css|images|js)/',
|
||||
'security' => false,
|
||||
],
|
||||
],
|
||||
]);
|
||||
};
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
use Symfony\Config\SecurityConfig;
|
||||
|
||||
return static function (SecurityConfig $securityConfig): void {
|
||||
$securityConfig->provider('webservice', [
|
||||
'id' => LoginServiceUserProvider::class,
|
||||
]);
|
||||
|
||||
$securityConfig->firewall('dev', [
|
||||
'pattern' => '^/(_(profiler|wdt)|css|images|js)/',
|
||||
'security' => false,
|
||||
]);
|
||||
};
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Closure::class];
|
||||
}
|
||||
/**
|
||||
* @param Closure $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$this->symfonyPhpClosureDetector->detect($node)) {
|
||||
return null;
|
||||
}
|
||||
// must be exactly one
|
||||
if (\count($node->stmts) !== 1) {
|
||||
return null;
|
||||
}
|
||||
$onlyStmt = $node->stmts[0];
|
||||
if (!$onlyStmt instanceof Expression) {
|
||||
return null;
|
||||
}
|
||||
if (!$onlyStmt->expr instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
$methodCall = $onlyStmt->expr;
|
||||
if (!$this->isName($methodCall->name, 'extension')) {
|
||||
return null;
|
||||
}
|
||||
$args = $methodCall->getArgs();
|
||||
$firstArg = $args[0];
|
||||
$extensionKey = $this->valueResolver->getValue($firstArg->value);
|
||||
if ($extensionKey !== 'security') {
|
||||
return null;
|
||||
}
|
||||
$fullyQualified = new FullyQualified('Symfony\\Config\\SecurityConfig');
|
||||
$node->params[0] = new Param(new Variable('securityConfig'), null, $fullyQualified);
|
||||
// we have a match
|
||||
$secondArg = $args[1];
|
||||
$configuration = $secondArg->value;
|
||||
if (!$configuration instanceof Array_) {
|
||||
return null;
|
||||
}
|
||||
$securityConfigVariable = new Variable('securityConfig');
|
||||
$fluentMethodCall = null;
|
||||
$configurationValues = $this->valueResolver->getValue($configuration);
|
||||
foreach ($configurationValues as $key => $value) {
|
||||
if ($key === 'providers') {
|
||||
$methodCallName = 'provider';
|
||||
} elseif ($key === 'firewalls') {
|
||||
$methodCallName = 'firewall';
|
||||
} else {
|
||||
throw new NotImplementedYetException($key);
|
||||
}
|
||||
foreach ($value as $itemName => $itemConfiguration) {
|
||||
$args = $this->nodeFactory->createArgs([$itemName, $itemConfiguration]);
|
||||
if (!$fluentMethodCall instanceof MethodCall) {
|
||||
$fluentMethodCall = new MethodCall($securityConfigVariable, $methodCallName, $args);
|
||||
} else {
|
||||
$fluentMethodCall = new MethodCall($fluentMethodCall, $methodCallName, $args);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$fluentMethodCall instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
$node->stmts = [new Expression($fluentMethodCall)];
|
||||
return $node;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user