mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 08:20:53 +00:00
Updated Rector to commit 84faf2905518aad5fb97caf613517f8a50827867
84faf29055
Update generate-changelog command to use objects, add simple filtering (#3232)
This commit is contained in:
parent
ebb02bd9e8
commit
e470fd1061
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 ComposerAutoloaderInitf0f163456d70a7ad1ec63c5cb8fd822b::getLoader();
|
||||
return ComposerAutoloaderInita6e7f1f65c7a9cea3f7381fa9cc66a13::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -2478,6 +2478,7 @@ return array(
|
|||
'Rector\\Symfony\\Exception\\InvalidConfigurationException' => $vendorDir . '/rector/rector-symfony/src/Exception/InvalidConfigurationException.php',
|
||||
'Rector\\Symfony\\Exception\\XmlContainerNotExistsException' => $vendorDir . '/rector/rector-symfony/src/Exception/XmlContainerNotExistsException.php',
|
||||
'Rector\\Symfony\\FormHelper\\FormTypeStringToTypeProvider' => $vendorDir . '/rector/rector-symfony/src/FormHelper/FormTypeStringToTypeProvider.php',
|
||||
'Rector\\Symfony\\Helper\\CommandHelper' => $vendorDir . '/rector/rector-symfony/src/Helper/CommandHelper.php',
|
||||
'Rector\\Symfony\\Helper\\TemplateGuesser' => $vendorDir . '/rector/rector-symfony/src/Helper/TemplateGuesser.php',
|
||||
'Rector\\Symfony\\NodeAnalyzer\\Annotations\\ClassAnnotationAssertResolver' => $vendorDir . '/rector/rector-symfony/src/NodeAnalyzer/Annotations/ClassAnnotationAssertResolver.php',
|
||||
'Rector\\Symfony\\NodeAnalyzer\\Annotations\\MethodCallAnnotationAssertResolver' => $vendorDir . '/rector/rector-symfony/src/NodeAnalyzer/Annotations/MethodCallAnnotationAssertResolver.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 ComposerAutoloaderInitf0f163456d70a7ad1ec63c5cb8fd822b
|
||||
class ComposerAutoloaderInita6e7f1f65c7a9cea3f7381fa9cc66a13
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInitf0f163456d70a7ad1ec63c5cb8fd822b
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitf0f163456d70a7ad1ec63c5cb8fd822b', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInita6e7f1f65c7a9cea3f7381fa9cc66a13', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitf0f163456d70a7ad1ec63c5cb8fd822b', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInita6e7f1f65c7a9cea3f7381fa9cc66a13', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitf0f163456d70a7ad1ec63c5cb8fd822b::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInita6e7f1f65c7a9cea3f7381fa9cc66a13::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitf0f163456d70a7ad1ec63c5cb8fd822b::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInita6e7f1f65c7a9cea3f7381fa9cc66a13::$files;
|
||||
$requireFile = 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 ComposerStaticInitf0f163456d70a7ad1ec63c5cb8fd822b
|
||||
class ComposerStaticInita6e7f1f65c7a9cea3f7381fa9cc66a13
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -2723,6 +2723,7 @@ class ComposerStaticInitf0f163456d70a7ad1ec63c5cb8fd822b
|
|||
'Rector\\Symfony\\Exception\\InvalidConfigurationException' => __DIR__ . '/..' . '/rector/rector-symfony/src/Exception/InvalidConfigurationException.php',
|
||||
'Rector\\Symfony\\Exception\\XmlContainerNotExistsException' => __DIR__ . '/..' . '/rector/rector-symfony/src/Exception/XmlContainerNotExistsException.php',
|
||||
'Rector\\Symfony\\FormHelper\\FormTypeStringToTypeProvider' => __DIR__ . '/..' . '/rector/rector-symfony/src/FormHelper/FormTypeStringToTypeProvider.php',
|
||||
'Rector\\Symfony\\Helper\\CommandHelper' => __DIR__ . '/..' . '/rector/rector-symfony/src/Helper/CommandHelper.php',
|
||||
'Rector\\Symfony\\Helper\\TemplateGuesser' => __DIR__ . '/..' . '/rector/rector-symfony/src/Helper/TemplateGuesser.php',
|
||||
'Rector\\Symfony\\NodeAnalyzer\\Annotations\\ClassAnnotationAssertResolver' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeAnalyzer/Annotations/ClassAnnotationAssertResolver.php',
|
||||
'Rector\\Symfony\\NodeAnalyzer\\Annotations\\MethodCallAnnotationAssertResolver' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeAnalyzer/Annotations/MethodCallAnnotationAssertResolver.php',
|
||||
|
@ -3060,9 +3061,9 @@ class ComposerStaticInitf0f163456d70a7ad1ec63c5cb8fd822b
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitf0f163456d70a7ad1ec63c5cb8fd822b::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitf0f163456d70a7ad1ec63c5cb8fd822b::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitf0f163456d70a7ad1ec63c5cb8fd822b::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInita6e7f1f65c7a9cea3f7381fa9cc66a13::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInita6e7f1f65c7a9cea3f7381fa9cc66a13::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInita6e7f1f65c7a9cea3f7381fa9cc66a13::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
|
@ -2122,12 +2122,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
|
||||
"reference": "50f1f80b9abf9ee10fba831948a207046bf30282"
|
||||
"reference": "4aa76596024629f6f8ef676fd7cc3ae53f5086ac"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/50f1f80b9abf9ee10fba831948a207046bf30282",
|
||||
"reference": "50f1f80b9abf9ee10fba831948a207046bf30282",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/4aa76596024629f6f8ef676fd7cc3ae53f5086ac",
|
||||
"reference": "4aa76596024629f6f8ef676fd7cc3ae53f5086ac",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2157,7 +2157,7 @@
|
|||
"symplify\/rule-doc-generator": "^11.1",
|
||||
"symplify\/vendor-patches": "^11.1"
|
||||
},
|
||||
"time": "2022-12-21T07:56:16+00:00",
|
||||
"time": "2022-12-21T15:12:14+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 d5c39ae'), '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 b1ca6d7'), '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 9ea5f62'), '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 a236bc6'), '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 50f1f80'));
|
||||
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 d5c39ae'), '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 b1ca6d7'), '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 9ea5f62'), '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 a236bc6'), '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 4aa7659'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
187
vendor/rector/rector-symfony/src/Helper/CommandHelper.php
vendored
Normal file
187
vendor/rector/rector-symfony/src/Helper/CommandHelper.php
vendored
Normal file
|
@ -0,0 +1,187 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Symfony\Helper;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeRemoval\NodeRemover;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
|
||||
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
/**
|
||||
* @see \Rector\Symfony\Tests\Rector\Class_\CommandPropertyToAttributeRector\CommandPropertyToAttributeRectorTest
|
||||
*/
|
||||
final class CommandHelper
|
||||
{
|
||||
public const ATTRIBUTE = 'Symfony\\Component\\Console\\Attribute\\AsCommand';
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
|
||||
*/
|
||||
private $phpAttributeAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeTypeResolver\NodeTypeResolver
|
||||
*/
|
||||
private $nodeTypeResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
|
||||
*/
|
||||
private $simpleCallableNodeTraverser;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeRemoval\NodeRemover
|
||||
*/
|
||||
private $nodeRemover;
|
||||
public function __construct(PhpAttributeAnalyzer $phpAttributeAnalyzer, NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeRemover $nodeRemover)
|
||||
{
|
||||
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||
$this->nodeRemover = $nodeRemover;
|
||||
}
|
||||
public function getCommandAliasesValueFromAttributeOrSetter(Class_ $class) : ?Array_
|
||||
{
|
||||
$commandAliases = null;
|
||||
$classMethod = $class->getMethod('configure');
|
||||
if (!$classMethod instanceof ClassMethod) {
|
||||
return $this->resolveAliasesFromAttribute($class);
|
||||
}
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable((array) $classMethod->stmts, function (Node $node) use(&$commandAliases) {
|
||||
if (!$node instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if ($node->isFirstClassCallable()) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeTypeResolver->isObjectType($node->var, new ObjectType('Symfony\\Component\\Console\\Command\\Command'))) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeNameResolver->isName($node->name, 'setAliases')) {
|
||||
return null;
|
||||
}
|
||||
/** @var Arg $arg */
|
||||
$arg = $node->args[0];
|
||||
if (!$arg->value instanceof Array_) {
|
||||
return null;
|
||||
}
|
||||
$commandAliases = $arg->value;
|
||||
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parentNode instanceof MethodCall) {
|
||||
$parentNode->var = $node->var;
|
||||
} else {
|
||||
$this->nodeRemover->removeNode($node);
|
||||
}
|
||||
return NodeTraverser::STOP_TRAVERSAL;
|
||||
});
|
||||
return $commandAliases;
|
||||
}
|
||||
public function getCommandHiddenValueFromAttributeOrSetter(Class_ $class) : ?ConstFetch
|
||||
{
|
||||
$commandHidden = null;
|
||||
$classMethod = $class->getMethod('configure');
|
||||
if (!$classMethod instanceof ClassMethod) {
|
||||
return $this->resolveHiddenFromAttribute($class);
|
||||
}
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable((array) $classMethod->stmts, function (Node $node) use(&$commandHidden) {
|
||||
if (!$node instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if ($node->isFirstClassCallable()) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeTypeResolver->isObjectType($node->var, new ObjectType('Symfony\\Component\\Console\\Command\\Command'))) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeNameResolver->isName($node->name, 'setHidden')) {
|
||||
return null;
|
||||
}
|
||||
$commandHidden = $this->getCommandHiddenValue($node);
|
||||
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parentNode instanceof MethodCall) {
|
||||
$parentNode->var = $node->var;
|
||||
} else {
|
||||
$this->nodeRemover->removeNode($node);
|
||||
}
|
||||
return NodeTraverser::STOP_TRAVERSAL;
|
||||
});
|
||||
return $commandHidden;
|
||||
}
|
||||
public function getCommandHiddenValue(MethodCall $methodCall) : ?ConstFetch
|
||||
{
|
||||
if (!isset($methodCall->args[0])) {
|
||||
return new ConstFetch(new Name('true'));
|
||||
}
|
||||
/** @var Arg $arg */
|
||||
$arg = $methodCall->args[0];
|
||||
if (!$arg->value instanceof ConstFetch) {
|
||||
return null;
|
||||
}
|
||||
return $arg->value;
|
||||
}
|
||||
/**
|
||||
* @return string|\PhpParser\Node\Expr\ConstFetch|\PhpParser\Node\Expr\Array_|null
|
||||
*/
|
||||
public function getArgumentValueFromAttribute(Class_ $class, int $argumentIndexKey)
|
||||
{
|
||||
$argumentValue = null;
|
||||
foreach ($class->attrGroups as $attrGroup) {
|
||||
foreach ($attrGroup->attrs as $attribute) {
|
||||
if (!$this->nodeNameResolver->isName($attribute->name, self::ATTRIBUTE)) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($attribute->args[$argumentIndexKey])) {
|
||||
continue;
|
||||
}
|
||||
$arg = $attribute->args[$argumentIndexKey];
|
||||
if ($arg->value instanceof String_) {
|
||||
$argumentValue = $arg->value->value;
|
||||
} elseif ($arg->value instanceof ConstFetch || $arg->value instanceof Array_) {
|
||||
$argumentValue = $arg->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $argumentValue;
|
||||
}
|
||||
private function resolveHiddenFromAttribute(Class_ $class) : ?ConstFetch
|
||||
{
|
||||
$commandHidden = null;
|
||||
if ($this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE)) {
|
||||
$commandHiddenFromArgument = $this->getArgumentValueFromAttribute($class, 3);
|
||||
if ($commandHiddenFromArgument instanceof ConstFetch) {
|
||||
$commandHidden = $commandHiddenFromArgument;
|
||||
}
|
||||
}
|
||||
return $commandHidden;
|
||||
}
|
||||
private function resolveAliasesFromAttribute(Class_ $class) : ?Array_
|
||||
{
|
||||
$commandAliases = null;
|
||||
if ($this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE)) {
|
||||
$commandAliasesFromArgument = $this->getArgumentValueFromAttribute($class, 2);
|
||||
if ($commandAliasesFromArgument instanceof Array_) {
|
||||
$commandAliases = $commandAliasesFromArgument;
|
||||
}
|
||||
}
|
||||
return $commandAliases;
|
||||
}
|
||||
}
|
|
@ -5,23 +5,20 @@ namespace Rector\Symfony\Rector\Class_;
|
|||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Attribute;
|
||||
use PhpParser\Node\AttributeGroup;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
|
||||
use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory;
|
||||
use Rector\Symfony\Helper\CommandHelper;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
@ -32,7 +29,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
*/
|
||||
final class CommandPropertyToAttributeRector extends AbstractRector implements MinPhpVersionInterface
|
||||
{
|
||||
private const ATTRIBUTE = 'Symfony\\Component\\Console\\Attribute\\AsCommand';
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory
|
||||
|
@ -48,11 +44,17 @@ final class CommandPropertyToAttributeRector extends AbstractRector implements M
|
|||
* @var \PHPStan\Reflection\ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
public function __construct(PhpAttributeGroupFactory $phpAttributeGroupFactory, PhpAttributeAnalyzer $phpAttributeAnalyzer, ReflectionProvider $reflectionProvider)
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Symfony\Helper\CommandHelper
|
||||
*/
|
||||
private $commandHelper;
|
||||
public function __construct(PhpAttributeGroupFactory $phpAttributeGroupFactory, PhpAttributeAnalyzer $phpAttributeAnalyzer, ReflectionProvider $reflectionProvider, CommandHelper $commandHelper)
|
||||
{
|
||||
$this->phpAttributeGroupFactory = $phpAttributeGroupFactory;
|
||||
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
$this->commandHelper = $commandHelper;
|
||||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
{
|
||||
|
@ -95,7 +97,7 @@ CODE_SAMPLE
|
|||
if (!$this->isObjectType($node, new ObjectType('Symfony\\Component\\Console\\Command\\Command'))) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->reflectionProvider->hasClass(self::ATTRIBUTE)) {
|
||||
if (!$this->reflectionProvider->hasClass(CommandHelper::ATTRIBUTE)) {
|
||||
return null;
|
||||
}
|
||||
$defaultName = $this->resolveDefaultName($node);
|
||||
|
@ -103,14 +105,13 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
$defaultDescription = $this->resolveDefaultDescription($node);
|
||||
$array = $this->resolveAliases($node);
|
||||
$constFetch = $this->resolveHidden($node);
|
||||
$node->attrGroups[] = $this->createAttributeGroup($defaultName, $defaultDescription, $array, $constFetch);
|
||||
return $node;
|
||||
$array = $this->commandHelper->getCommandAliasesValueFromAttributeOrSetter($node);
|
||||
$constFetch = $this->commandHelper->getCommandHiddenValueFromAttributeOrSetter($node);
|
||||
return $this->replaceAsCommandAttribute($node, $this->createAttributeGroupAsCommand($defaultName, $defaultDescription, $array, $constFetch));
|
||||
}
|
||||
private function createAttributeGroup(string $defaultName, ?string $defaultDescription, ?Array_ $array, ?ConstFetch $constFetch) : AttributeGroup
|
||||
private function createAttributeGroupAsCommand(string $defaultName, ?string $defaultDescription, ?Array_ $array, ?ConstFetch $constFetch) : AttributeGroup
|
||||
{
|
||||
$attributeGroup = $this->phpAttributeGroupFactory->createFromClass(self::ATTRIBUTE);
|
||||
$attributeGroup = $this->phpAttributeGroupFactory->createFromClass(CommandHelper::ATTRIBUTE);
|
||||
$attributeGroup->attrs[0]->args[] = new Arg(new String_($defaultName));
|
||||
if ($defaultDescription !== null) {
|
||||
$attributeGroup->attrs[0]->args[] = new Arg(new String_($defaultDescription));
|
||||
|
@ -150,25 +151,10 @@ CODE_SAMPLE
|
|||
}
|
||||
}
|
||||
// Get DefaultName from attribute
|
||||
if ($defaultName === null && $this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE)) {
|
||||
$defaultName = $this->getDefaultNameFromAttribute($class);
|
||||
}
|
||||
return $defaultName;
|
||||
}
|
||||
private function getDefaultNameFromAttribute(Class_ $class) : ?string
|
||||
{
|
||||
$defaultName = null;
|
||||
foreach ($class->attrGroups as $attrGroup) {
|
||||
foreach ($attrGroup->attrs as $attribute) {
|
||||
if (!$this->nodeNameResolver->isName($attribute->name, self::ATTRIBUTE)) {
|
||||
continue;
|
||||
}
|
||||
$arg = $attribute->args[0];
|
||||
if (!$arg->value instanceof String_) {
|
||||
continue;
|
||||
}
|
||||
$defaultName = $arg->value->value;
|
||||
$this->removeNode($attrGroup);
|
||||
if ($defaultName === null && $this->phpAttributeAnalyzer->hasPhpAttribute($class, CommandHelper::ATTRIBUTE)) {
|
||||
$defaultNameFromArgument = $this->commandHelper->getArgumentValueFromAttribute($class, 0);
|
||||
if (\is_string($defaultNameFromArgument)) {
|
||||
$defaultName = $defaultNameFromArgument;
|
||||
}
|
||||
}
|
||||
return $defaultName;
|
||||
|
@ -183,85 +169,58 @@ CODE_SAMPLE
|
|||
$this->removeNode($property);
|
||||
}
|
||||
}
|
||||
return $this->resolveDefaultDescriptionFromAttribute($class, $defaultDescription);
|
||||
}
|
||||
private function resolveDefaultDescriptionFromAttribute(Class_ $class, ?string $defaultDescription) : ?string
|
||||
{
|
||||
if ($defaultDescription === null && $this->phpAttributeAnalyzer->hasPhpAttribute($class, CommandHelper::ATTRIBUTE)) {
|
||||
$defaultDescriptionFromArgument = $this->commandHelper->getArgumentValueFromAttribute($class, 1);
|
||||
if (\is_string($defaultDescriptionFromArgument)) {
|
||||
$defaultDescription = $defaultDescriptionFromArgument;
|
||||
}
|
||||
}
|
||||
return $defaultDescription;
|
||||
}
|
||||
private function resolveAliases(Class_ $class) : ?Array_
|
||||
private function replaceAsCommandAttribute(Class_ $class, AttributeGroup $createAttributeGroup) : ?Class_
|
||||
{
|
||||
$commandAliases = null;
|
||||
$classMethod = $class->getMethod('configure');
|
||||
if (!$classMethod instanceof ClassMethod) {
|
||||
$hasAsCommandAttribute = \false;
|
||||
$replacedAsCommandAttribute = \false;
|
||||
foreach ($class->attrGroups as $attrGroup) {
|
||||
foreach ($attrGroup->attrs as $attribute) {
|
||||
if ($this->nodeNameResolver->isName($attribute->name, CommandHelper::ATTRIBUTE)) {
|
||||
$hasAsCommandAttribute = \true;
|
||||
$replacedAsCommandAttribute = $this->replaceArguments($attribute, $createAttributeGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($hasAsCommandAttribute === \false) {
|
||||
$class->attrGroups[] = $createAttributeGroup;
|
||||
$replacedAsCommandAttribute = \true;
|
||||
}
|
||||
if ($replacedAsCommandAttribute === \false) {
|
||||
return null;
|
||||
}
|
||||
$this->traverseNodesWithCallable((array) $classMethod->stmts, function (Node $node) use(&$commandAliases) {
|
||||
if (!$node instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if ($node->isFirstClassCallable()) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isObjectType($node->var, new ObjectType('Symfony\\Component\\Console\\Command\\Command'))) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($node->name, 'setAliases')) {
|
||||
return null;
|
||||
}
|
||||
/** @var Arg $arg */
|
||||
$arg = $node->args[0];
|
||||
if (!$arg->value instanceof Array_) {
|
||||
return null;
|
||||
}
|
||||
$commandAliases = $arg->value;
|
||||
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parentNode instanceof MethodCall) {
|
||||
$parentNode->var = $node->var;
|
||||
} else {
|
||||
$this->removeNode($node);
|
||||
}
|
||||
return NodeTraverser::STOP_TRAVERSAL;
|
||||
});
|
||||
return $commandAliases;
|
||||
return $class;
|
||||
}
|
||||
private function resolveHidden(Class_ $class) : ?ConstFetch
|
||||
private function replaceArguments(Attribute $attribute, AttributeGroup $createAttributeGroup) : bool
|
||||
{
|
||||
$commandHidden = null;
|
||||
$classMethod = $class->getMethod('configure');
|
||||
if (!$classMethod instanceof ClassMethod) {
|
||||
return null;
|
||||
$replacedAsCommandAttribute = \false;
|
||||
if (!$attribute->args[0]->value instanceof String_) {
|
||||
$attribute->args[0] = $createAttributeGroup->attrs[0]->args[0];
|
||||
$replacedAsCommandAttribute = \true;
|
||||
}
|
||||
$this->traverseNodesWithCallable((array) $classMethod->stmts, function (Node $node) use(&$commandHidden) {
|
||||
if (!$node instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if ($node->isFirstClassCallable()) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isObjectType($node->var, new ObjectType('Symfony\\Component\\Console\\Command\\Command'))) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($node->name, 'setHidden')) {
|
||||
return null;
|
||||
}
|
||||
$commandHidden = $this->getCommandHiddenValue($node);
|
||||
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parentNode instanceof MethodCall) {
|
||||
$parentNode->var = $node->var;
|
||||
} else {
|
||||
$this->removeNode($node);
|
||||
}
|
||||
return NodeTraverser::STOP_TRAVERSAL;
|
||||
});
|
||||
return $commandHidden;
|
||||
}
|
||||
private function getCommandHiddenValue(MethodCall $methodCall) : ?ConstFetch
|
||||
{
|
||||
if (!isset($methodCall->args[0])) {
|
||||
return new ConstFetch(new Name('true'));
|
||||
if (!isset($attribute->args[1]) && isset($createAttributeGroup->attrs[0]->args[1])) {
|
||||
$attribute->args[1] = $createAttributeGroup->attrs[0]->args[1];
|
||||
$replacedAsCommandAttribute = \true;
|
||||
}
|
||||
/** @var Arg $arg */
|
||||
$arg = $methodCall->args[0];
|
||||
if (!$arg->value instanceof ConstFetch) {
|
||||
return null;
|
||||
if (!isset($attribute->args[2]) && isset($createAttributeGroup->attrs[0]->args[2])) {
|
||||
$attribute->args[2] = $createAttributeGroup->attrs[0]->args[2];
|
||||
$replacedAsCommandAttribute = \true;
|
||||
}
|
||||
return $arg->value;
|
||||
if (!isset($attribute->args[3]) && isset($createAttributeGroup->attrs[0]->args[3])) {
|
||||
$attribute->args[3] = $createAttributeGroup->attrs[0]->args[3];
|
||||
$replacedAsCommandAttribute = \true;
|
||||
}
|
||||
return $replacedAsCommandAttribute;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user