Updated Rector to commit a16bc1b576

a16bc1b576 skip privatization, as unknown side effect (#2542)
This commit is contained in:
Tomas Votruba 2022-06-20 17:57:13 +00:00
parent 491ac4d181
commit 9550950b4e
14 changed files with 281 additions and 56 deletions

2
vendor/autoload.php vendored
View File

@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit2d0e67670e493d32afef1404cf79bdcb::getLoader();
return ComposerAutoloaderInitc78cb6afb27140288b663d1dae738aed::getLoader();

View File

@ -2790,6 +2790,7 @@ return array(
'Rector\\Symfony\\NodeAnalyzer\\SymfonyTestCaseAnalyzer' => $vendorDir . '/rector/rector-symfony/src/NodeAnalyzer/SymfonyTestCaseAnalyzer.php',
'Rector\\Symfony\\NodeFactory\\Annotations\\DoctrineAnnotationFromNewFactory' => $vendorDir . '/rector/rector-symfony/src/NodeFactory/Annotations/DoctrineAnnotationFromNewFactory.php',
'Rector\\Symfony\\NodeFactory\\Annotations\\DoctrineAnnotationKeyToValuesResolver' => $vendorDir . '/rector/rector-symfony/src/NodeFactory/Annotations/DoctrineAnnotationKeyToValuesResolver.php',
'Rector\\Symfony\\NodeFactory\\Annotations\\StringValueQuoteWrapper' => $vendorDir . '/rector/rector-symfony/src/NodeFactory/Annotations/StringValueQuoteWrapper.php',
'Rector\\Symfony\\NodeFactory\\ArrayFromCompactFactory' => $vendorDir . '/rector/rector-symfony/src/NodeFactory/ArrayFromCompactFactory.php',
'Rector\\Symfony\\NodeFactory\\BareLogoutClassMethodFactory' => $vendorDir . '/rector/rector-symfony/src/NodeFactory/BareLogoutClassMethodFactory.php',
'Rector\\Symfony\\NodeFactory\\EventReferenceFactory' => $vendorDir . '/rector/rector-symfony/src/NodeFactory/EventReferenceFactory.php',
@ -2830,6 +2831,7 @@ return array(
'Rector\\Symfony\\Rector\\Class_\\LoadValidatorMetadataToAnnotationRector' => $vendorDir . '/rector/rector-symfony/src/Rector/Class_/LoadValidatorMetadataToAnnotationRector.php',
'Rector\\Symfony\\Rector\\Class_\\LogoutHandlerToLogoutEventSubscriberRector' => $vendorDir . '/rector/rector-symfony/src/Rector/Class_/LogoutHandlerToLogoutEventSubscriberRector.php',
'Rector\\Symfony\\Rector\\Class_\\LogoutSuccessHandlerToLogoutEventSubscriberRector' => $vendorDir . '/rector/rector-symfony/src/Rector/Class_/LogoutSuccessHandlerToLogoutEventSubscriberRector.php',
'Rector\\Symfony\\Rector\\Class_\\MagicClosureTwigExtensionToNativeMethodsRector' => $vendorDir . '/rector/rector-symfony/src/Rector/Class_/MagicClosureTwigExtensionToNativeMethodsRector.php',
'Rector\\Symfony\\Rector\\Class_\\MakeCommandLazyRector' => $vendorDir . '/rector/rector-symfony/src/Rector/Class_/MakeCommandLazyRector.php',
'Rector\\Symfony\\Rector\\ConstFetch\\ConstraintUrlOptionRector' => $vendorDir . '/rector/rector-symfony/src/Rector/ConstFetch/ConstraintUrlOptionRector.php',
'Rector\\Symfony\\Rector\\FuncCall\\ReplaceServiceArgumentRector' => $vendorDir . '/rector/rector-symfony/src/Rector/FuncCall/ReplaceServiceArgumentRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit2d0e67670e493d32afef1404cf79bdcb
class ComposerAutoloaderInitc78cb6afb27140288b663d1dae738aed
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit2d0e67670e493d32afef1404cf79bdcb
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit2d0e67670e493d32afef1404cf79bdcb', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitc78cb6afb27140288b663d1dae738aed', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit2d0e67670e493d32afef1404cf79bdcb', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitc78cb6afb27140288b663d1dae738aed', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit2d0e67670e493d32afef1404cf79bdcb::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitc78cb6afb27140288b663d1dae738aed::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit2d0e67670e493d32afef1404cf79bdcb::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInitc78cb6afb27140288b663d1dae738aed::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire2d0e67670e493d32afef1404cf79bdcb($fileIdentifier, $file);
composerRequirec78cb6afb27140288b663d1dae738aed($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit2d0e67670e493d32afef1404cf79bdcb
* @param string $file
* @return void
*/
function composerRequire2d0e67670e493d32afef1404cf79bdcb($fileIdentifier, $file)
function composerRequirec78cb6afb27140288b663d1dae738aed($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 ComposerStaticInit2d0e67670e493d32afef1404cf79bdcb
class ComposerStaticInitc78cb6afb27140288b663d1dae738aed
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -3091,6 +3091,7 @@ class ComposerStaticInit2d0e67670e493d32afef1404cf79bdcb
'Rector\\Symfony\\NodeAnalyzer\\SymfonyTestCaseAnalyzer' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeAnalyzer/SymfonyTestCaseAnalyzer.php',
'Rector\\Symfony\\NodeFactory\\Annotations\\DoctrineAnnotationFromNewFactory' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeFactory/Annotations/DoctrineAnnotationFromNewFactory.php',
'Rector\\Symfony\\NodeFactory\\Annotations\\DoctrineAnnotationKeyToValuesResolver' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeFactory/Annotations/DoctrineAnnotationKeyToValuesResolver.php',
'Rector\\Symfony\\NodeFactory\\Annotations\\StringValueQuoteWrapper' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeFactory/Annotations/StringValueQuoteWrapper.php',
'Rector\\Symfony\\NodeFactory\\ArrayFromCompactFactory' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeFactory/ArrayFromCompactFactory.php',
'Rector\\Symfony\\NodeFactory\\BareLogoutClassMethodFactory' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeFactory/BareLogoutClassMethodFactory.php',
'Rector\\Symfony\\NodeFactory\\EventReferenceFactory' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeFactory/EventReferenceFactory.php',
@ -3131,6 +3132,7 @@ class ComposerStaticInit2d0e67670e493d32afef1404cf79bdcb
'Rector\\Symfony\\Rector\\Class_\\LoadValidatorMetadataToAnnotationRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/Class_/LoadValidatorMetadataToAnnotationRector.php',
'Rector\\Symfony\\Rector\\Class_\\LogoutHandlerToLogoutEventSubscriberRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/Class_/LogoutHandlerToLogoutEventSubscriberRector.php',
'Rector\\Symfony\\Rector\\Class_\\LogoutSuccessHandlerToLogoutEventSubscriberRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/Class_/LogoutSuccessHandlerToLogoutEventSubscriberRector.php',
'Rector\\Symfony\\Rector\\Class_\\MagicClosureTwigExtensionToNativeMethodsRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/Class_/MagicClosureTwigExtensionToNativeMethodsRector.php',
'Rector\\Symfony\\Rector\\Class_\\MakeCommandLazyRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/Class_/MakeCommandLazyRector.php',
'Rector\\Symfony\\Rector\\ConstFetch\\ConstraintUrlOptionRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/ConstFetch/ConstraintUrlOptionRector.php',
'Rector\\Symfony\\Rector\\FuncCall\\ReplaceServiceArgumentRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/FuncCall/ReplaceServiceArgumentRector.php',
@ -3397,9 +3399,9 @@ class ComposerStaticInit2d0e67670e493d32afef1404cf79bdcb
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit2d0e67670e493d32afef1404cf79bdcb::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit2d0e67670e493d32afef1404cf79bdcb::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit2d0e67670e493d32afef1404cf79bdcb::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitc78cb6afb27140288b663d1dae738aed::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitc78cb6afb27140288b663d1dae738aed::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitc78cb6afb27140288b663d1dae738aed::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1991,12 +1991,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-generator.git",
"reference": "285cbcacd4f3f798fd404b7bfa3efbf1744709ba"
"reference": "cca34ded590dfbbbbde3fd3e6723b5657dfa9696"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-generator\/zipball\/285cbcacd4f3f798fd404b7bfa3efbf1744709ba",
"reference": "285cbcacd4f3f798fd404b7bfa3efbf1744709ba",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-generator\/zipball\/cca34ded590dfbbbbde3fd3e6723b5657dfa9696",
"reference": "cca34ded590dfbbbbde3fd3e6723b5657dfa9696",
"shasum": ""
},
"require": {
@ -2025,7 +2025,7 @@
"symplify\/phpstan-rules": "^11.0",
"symplify\/vendor-patches": "^11.0"
},
"time": "2022-06-14T07:06:32+00:00",
"time": "2022-06-20T16:12:42+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -2050,7 +2050,7 @@
"homepage": "https:\/\/getrector.org",
"support": {
"issues": "https:\/\/github.com\/rectorphp\/rector-generator\/issues",
"source": "https:\/\/github.com\/rectorphp\/rector-generator\/tree\/0.6.7"
"source": "https:\/\/github.com\/rectorphp\/rector-generator\/tree\/0.6.8"
},
"funding": [
{
@ -2347,12 +2347,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "d26d4ae9b6e702b80166fe131ab8b10e33475a14"
"reference": "c730231e908be8ab2bfd98ff27c0c06c92e24fa7"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/d26d4ae9b6e702b80166fe131ab8b10e33475a14",
"reference": "d26d4ae9b6e702b80166fe131ab8b10e33475a14",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/c730231e908be8ab2bfd98ff27c0c06c92e24fa7",
"reference": "c730231e908be8ab2bfd98ff27c0c06c92e24fa7",
"shasum": ""
},
"require": {
@ -2381,7 +2381,7 @@
"symplify\/rule-doc-generator": "^11.0",
"symplify\/vendor-patches": "^11.0"
},
"time": "2022-06-20T14:47:45+00:00",
"time": "2022-06-20T17:45:14+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

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 527dc23'), '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 cc103d0'), '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 285cbca'), '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 a2e37f3'), '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 3ea1ed7'), '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 fdbecca'), '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 3f4cc81'), '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 d26d4ae'));
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 527dc23'), '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 cc103d0'), '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 cca34de'), '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 a2e37f3'), '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 3ea1ed7'), '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 fdbecca'), '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 3f4cc81'), '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 c730231'));
private function __construct()
{
}

View File

@ -74,7 +74,7 @@ final class FileGenerator
// add core package main config
if (\substr_compare($targetFilePath, 'configured_rule.php', -\strlen('configured_rule.php')) === 0) {
$rectorConfigLine = 'return static function (RectorConfig $rectorConfig): void {';
$content = \str_replace($rectorConfigLine, $rectorConfigLine . \PHP_EOL . ' $rectorConfig->import(__DIR__ . \'/../../../../../config/config.php\')' . \PHP_EOL, $content);
$content = \str_replace($rectorConfigLine, $rectorConfigLine . \PHP_EOL . ' $rectorConfig->import(__DIR__ . \'/../../../../../config/config.php\');' . \PHP_EOL, $content);
}
}
$this->smartFileSystem->dumpFile($targetFilePath, $content);

View File

@ -1,4 +1,4 @@
# 65 Rules Overview
# 66 Rules Overview
## ActionSuffixRemoverRector
@ -171,7 +171,10 @@ use Rector\Config\RectorConfig;
use Rector\Symfony\Rector\Class_\ChangeFileLoaderInExtensionAndKernelRector;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(ChangeFileLoaderInExtensionAndKernelRector::class, [Rector\Symfony\Rector\Class_\ChangeFileLoaderInExtensionAndKernelRector::FROM: 'xml', Rector\Symfony\Rector\Class_\ChangeFileLoaderInExtensionAndKernelRector::TO: 'yaml']);
$rectorConfig->ruleWithConfiguration(ChangeFileLoaderInExtensionAndKernelRector::class, [
ChangeFileLoaderInExtensionAndKernelRector::FROM => 'xml',
ChangeFileLoaderInExtensionAndKernelRector::TO => 'yaml',
]);
};
```
@ -237,8 +240,11 @@ Add `Symfony\Component\Console\Attribute\AsCommand` to Symfony Commands and remo
- class: [`Rector\Symfony\Rector\Class_\CommandPropertyToAttributeRector`](../src/Rector/Class_/CommandPropertyToAttributeRector.php)
```diff
+#[\Symfony\Component\Console\Attribute\AsCommand('sunshine')]
class SunshineCommand extends \Symfony\Component\Console\Command\Command
+use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
+#[AsCommand('sunshine')]
final class SunshineCommand extends Command
{
- /** @var string|null */
- public static $defaultName = 'sunshine';
@ -829,6 +835,38 @@ Change logout success handler to an event listener that listens to LogoutEvent
<br>
## MagicClosureTwigExtensionToNativeMethodsRector
Change TwigExtension function/filter magic closures to inlined and clear callables
- class: [`Rector\Symfony\Rector\Class_\MagicClosureTwigExtensionToNativeMethodsRector`](../src/Rector/Class_/MagicClosureTwigExtensionToNativeMethodsRector.php)
```diff
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
final class TerminologyExtension extends AbstractExtension
{
public function getFunctions(): array
{
return [
- new TwigFunction('resolve', [$this, 'resolve']);
+ new TwigFunction('resolve', function ($values) {
+ return $value + 100;
+ }),
];
- }
-
-
- private function resolve($value)
- {
- return $value + 100;
}
}
```
<br>
## MakeCommandLazyRector
Make Symfony commands lazy

View File

@ -6,8 +6,7 @@ namespace RectorPrefix202206;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Set\Contract\SetListInterface;
use Rector\Symfony\Contract\Bridge\Symfony\Routing\SymfonyRoutesProviderInterface;
use RectorPrefix202206\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator) : void {
$parameters = $containerConfigurator->parameters();
$parameters->set('types_to_skip', [SymfonyRoutesProviderInterface::class, SetListInterface::class, RectorInterface::class]);
use RectorPrefix202206\Symplify\EasyCI\Config\EasyCIConfig;
return static function (EasyCIConfig $easyCIConfig) : void {
$easyCIConfig->typesToSkip([SymfonyRoutesProviderInterface::class, SetListInterface::class, RectorInterface::class]);
};

View File

@ -29,6 +29,7 @@ return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(StringClassNameToClassConstantRector::class, [
'Symfony\\*',
'Twig_*',
'Twig*',
'Swift_*',
'Doctrine\\*',
// loaded from project itself

View File

@ -6,7 +6,6 @@ namespace Rector\Symfony\NodeFactory\Annotations;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
final class DoctrineAnnotationKeyToValuesResolver
{
@ -15,9 +14,15 @@ final class DoctrineAnnotationKeyToValuesResolver
* @var \Rector\Core\PhpParser\Node\Value\ValueResolver
*/
private $valueResolver;
public function __construct(ValueResolver $valueResolver)
/**
* @readonly
* @var \Rector\Symfony\NodeFactory\Annotations\StringValueQuoteWrapper
*/
private $stringValueQuoteWrapper;
public function __construct(ValueResolver $valueResolver, \Rector\Symfony\NodeFactory\Annotations\StringValueQuoteWrapper $stringValueQuoteWrapper)
{
$this->valueResolver = $valueResolver;
$this->stringValueQuoteWrapper = $stringValueQuoteWrapper;
}
/**
* @return array<string|null, mixed>|mixed[]
@ -32,7 +37,7 @@ final class DoctrineAnnotationKeyToValuesResolver
}
$key = $this->resolveKey($arrayItem);
$value = $this->valueResolver->getValue($arrayItem->value);
$value = $this->wrapStringValuesInQuotes($value, $key);
$value = $this->stringValueQuoteWrapper->wrap($value, $key);
// implicit key with no name
if ($key === null) {
$annotationKeyToValues[] = $value;
@ -42,7 +47,7 @@ final class DoctrineAnnotationKeyToValuesResolver
}
} else {
$singleValue = $this->valueResolver->getValue($expr);
$singleValue = $this->wrapStringValuesInQuotes($singleValue, null);
$singleValue = $this->stringValueQuoteWrapper->wrap($singleValue, null);
return [$singleValue];
}
return $annotationKeyToValues;
@ -54,24 +59,4 @@ final class DoctrineAnnotationKeyToValuesResolver
}
return $this->valueResolver->getValue($arrayItem->key);
}
/**
* @return mixed
* @param mixed $value
*/
private function wrapStringValuesInQuotes($value, ?string $key)
{
if (\is_string($value)) {
return '"' . $value . '"';
}
if (\is_array($value)) {
// include quotes in groups
if ($key === 'groups') {
foreach ($value as $nestedKey => $nestedValue) {
$value[$nestedKey] = '"' . $nestedValue . '"';
}
}
return new CurlyListNode($value);
}
return $value;
}
}

View File

@ -0,0 +1,39 @@
<?php
declare (strict_types=1);
namespace Rector\Symfony\NodeFactory\Annotations;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
final class StringValueQuoteWrapper
{
/**
* @return mixed
* @param mixed $value
*/
public function wrap($value, ?string $key)
{
if (\is_string($value)) {
return '"' . $value . '"';
}
if (\is_array($value)) {
return $this->wrapArray($value, $key);
}
return $value;
}
/**
* @param mixed[] $value
*/
private function wrapArray(array $value, ?string $key) : CurlyListNode
{
// include quotes in groups
if (\in_array($key, ['groups', 'schemes', 'choices'], \true)) {
foreach ($value as $nestedKey => $nestedValue) {
if (\is_numeric($nestedValue)) {
continue;
}
$value[$nestedKey] = '"' . $nestedValue . '"';
}
}
return new CurlyListNode($value);
}
}

View File

@ -0,0 +1,159 @@
<?php
declare (strict_types=1);
namespace Rector\Symfony\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Reflection\Php\PhpMethodReflection;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\NodeCollector\NodeAnalyzer\ArrayCallableMethodMatcher;
use Rector\NodeCollector\ValueObject\ArrayCallable;
use Rector\Php72\NodeFactory\AnonymousFunctionFactory;
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Symfony\Tests\Rector\Class_\MagicClosureTwigExtensionToNativeMethodsRector\MagicClosureTwigExtensionToNativeMethodsRectorTest
*/
final class MagicClosureTwigExtensionToNativeMethodsRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Php72\NodeFactory\AnonymousFunctionFactory
*/
private $anonymousFunctionFactory;
/**
* @readonly
* @var \Rector\Core\Reflection\ReflectionResolver
*/
private $reflectionResolver;
/**
* @readonly
* @var \Rector\NodeCollector\NodeAnalyzer\ArrayCallableMethodMatcher
*/
private $arrayCallableMethodMatcher;
/**
* @readonly
* @var \Rector\Privatization\NodeManipulator\VisibilityManipulator
*/
private $visibilityManipulator;
public function __construct(AnonymousFunctionFactory $anonymousFunctionFactory, ReflectionResolver $reflectionResolver, ArrayCallableMethodMatcher $arrayCallableMethodMatcher, VisibilityManipulator $visibilityManipulator)
{
$this->anonymousFunctionFactory = $anonymousFunctionFactory;
$this->reflectionResolver = $reflectionResolver;
$this->arrayCallableMethodMatcher = $arrayCallableMethodMatcher;
$this->visibilityManipulator = $visibilityManipulator;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change TwigExtension function/filter magic closures to inlined and clear callables', [new CodeSample(<<<'CODE_SAMPLE'
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
final class TerminologyExtension extends AbstractExtension
{
public function getFunctions(): array
{
return [
new TwigFunction('resolve', [$this, 'resolve']);
];
}
private function resolve($value)
{
return $value + 100;
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
final class TerminologyExtension extends AbstractExtension
{
public function getFunctions(): array
{
return [
new TwigFunction('resolve', function ($values) {
return $value + 100;
}),
];
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->nodeTypeResolver->isObjectTypes($node, [new ObjectType('Twig_ExtensionInterface'), new ObjectType('Twig\\Extension\\ExtensionInterface')])) {
return null;
}
$hasFunctionsChanged = \false;
$getFunctionsClassMethod = $node->getMethod('getFunctions');
if ($getFunctionsClassMethod instanceof ClassMethod) {
$hasFunctionsChanged = $this->refactorClassMethod($node, $getFunctionsClassMethod);
}
$hasFiltersChanged = \false;
$getFiltersClassMethod = $node->getMethod('getFilters');
if ($getFiltersClassMethod instanceof ClassMethod) {
$hasFiltersChanged = $this->refactorClassMethod($node, $getFiltersClassMethod);
}
if ($hasFiltersChanged || $hasFunctionsChanged) {
return $node;
}
return null;
}
private function refactorClassMethod(Class_ $class, ClassMethod $classMethod) : bool
{
$hasChanged = \false;
$this->traverseNodesWithCallable($classMethod, function (Node $node) use(&$hasChanged, $class) : ?Node {
if (!$node instanceof Array_) {
return null;
}
$arrayCallable = $this->arrayCallableMethodMatcher->match($node);
if (!$arrayCallable instanceof ArrayCallable) {
return null;
}
$phpMethodReflection = $this->reflectionResolver->resolveMethodReflection($arrayCallable->getClass(), $arrayCallable->getMethod(), null);
if (!$phpMethodReflection instanceof PhpMethodReflection) {
return null;
}
$closure = $this->anonymousFunctionFactory->createFromPhpMethodReflection($phpMethodReflection, $arrayCallable->getCallerExpr());
if (!$closure instanceof Closure) {
return null;
}
// make method private, if local one
$localClassMethod = $class->getMethod($arrayCallable->getMethod());
if ($localClassMethod instanceof ClassMethod) {
$stmtsCount = \count((array) $localClassMethod->stmts);
if ($stmtsCount === 1) {
// inline and remove method
$closure->stmts = $localClassMethod->stmts;
$this->removeNode($localClassMethod);
} else {
$this->visibilityManipulator->makePrivate($localClassMethod);
}
}
$hasChanged = \true;
return $closure;
});
return $hasChanged;
}
}