Updated Rector to commit 3dfe7f9c11dc0ea75ba73da6f4639c1718843dc2

3dfe7f9c11 [Test] Enable displayDetailsOnTestsThatTriggerWarnings to true in tests to show warning (#4020)
This commit is contained in:
Tomas Votruba 2023-05-29 14:21:02 +00:00
parent 9f963a664a
commit 84d2957596
15 changed files with 119 additions and 154 deletions

2
vendor/autoload.php vendored
View File

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

View File

@ -2498,7 +2498,6 @@ 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\\MessengerHelper' => $vendorDir . '/rector/rector-symfony/src/Helper/MessengerHelper.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',
@ -2506,6 +2505,8 @@ return array(
'Rector\\Symfony\\NodeAnalyzer\\Annotations\\PropertyAnnotationAssertResolver' => $vendorDir . '/rector/rector-symfony/src/NodeAnalyzer/Annotations/PropertyAnnotationAssertResolver.php',
'Rector\\Symfony\\NodeAnalyzer\\Annotations\\StmtMethodCallMatcher' => $vendorDir . '/rector/rector-symfony/src/NodeAnalyzer/Annotations/StmtMethodCallMatcher.php',
'Rector\\Symfony\\NodeAnalyzer\\ClassAnalyzer' => $vendorDir . '/rector/rector-symfony/src/NodeAnalyzer/ClassAnalyzer.php',
'Rector\\Symfony\\NodeAnalyzer\\Command\\AttributeValueResolver' => $vendorDir . '/rector/rector-symfony/src/NodeAnalyzer/Command/AttributeValueResolver.php',
'Rector\\Symfony\\NodeAnalyzer\\Command\\SetAliasesMethodCallExtractor' => $vendorDir . '/rector/rector-symfony/src/NodeAnalyzer/Command/SetAliasesMethodCallExtractor.php',
'Rector\\Symfony\\NodeAnalyzer\\DependencyInjectionMethodCallAnalyzer' => $vendorDir . '/rector/rector-symfony/src/NodeAnalyzer/DependencyInjectionMethodCallAnalyzer.php',
'Rector\\Symfony\\NodeAnalyzer\\FormAddMethodCallAnalyzer' => $vendorDir . '/rector/rector-symfony/src/NodeAnalyzer/FormAddMethodCallAnalyzer.php',
'Rector\\Symfony\\NodeAnalyzer\\FormCollectionAnalyzer' => $vendorDir . '/rector/rector-symfony/src/NodeAnalyzer/FormCollectionAnalyzer.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit5e03358f1b8a6c37a4b1e0f505237893
class ComposerAutoloaderInitccb0f5f37374e069cc240905b0f6415d
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit5e03358f1b8a6c37a4b1e0f505237893
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit5e03358f1b8a6c37a4b1e0f505237893', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitccb0f5f37374e069cc240905b0f6415d', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit5e03358f1b8a6c37a4b1e0f505237893', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitccb0f5f37374e069cc240905b0f6415d', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit5e03358f1b8a6c37a4b1e0f505237893::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitccb0f5f37374e069cc240905b0f6415d::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit5e03358f1b8a6c37a4b1e0f505237893::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitccb0f5f37374e069cc240905b0f6415d::$files;
$requireFile = \Closure::bind(static function ($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 ComposerStaticInit5e03358f1b8a6c37a4b1e0f505237893
class ComposerStaticInitccb0f5f37374e069cc240905b0f6415d
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2740,7 +2740,6 @@ class ComposerStaticInit5e03358f1b8a6c37a4b1e0f505237893
'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\\MessengerHelper' => __DIR__ . '/..' . '/rector/rector-symfony/src/Helper/MessengerHelper.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',
@ -2748,6 +2747,8 @@ class ComposerStaticInit5e03358f1b8a6c37a4b1e0f505237893
'Rector\\Symfony\\NodeAnalyzer\\Annotations\\PropertyAnnotationAssertResolver' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeAnalyzer/Annotations/PropertyAnnotationAssertResolver.php',
'Rector\\Symfony\\NodeAnalyzer\\Annotations\\StmtMethodCallMatcher' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeAnalyzer/Annotations/StmtMethodCallMatcher.php',
'Rector\\Symfony\\NodeAnalyzer\\ClassAnalyzer' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeAnalyzer/ClassAnalyzer.php',
'Rector\\Symfony\\NodeAnalyzer\\Command\\AttributeValueResolver' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeAnalyzer/Command/AttributeValueResolver.php',
'Rector\\Symfony\\NodeAnalyzer\\Command\\SetAliasesMethodCallExtractor' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeAnalyzer/Command/SetAliasesMethodCallExtractor.php',
'Rector\\Symfony\\NodeAnalyzer\\DependencyInjectionMethodCallAnalyzer' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeAnalyzer/DependencyInjectionMethodCallAnalyzer.php',
'Rector\\Symfony\\NodeAnalyzer\\FormAddMethodCallAnalyzer' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeAnalyzer/FormAddMethodCallAnalyzer.php',
'Rector\\Symfony\\NodeAnalyzer\\FormCollectionAnalyzer' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeAnalyzer/FormCollectionAnalyzer.php',
@ -3083,9 +3084,9 @@ class ComposerStaticInit5e03358f1b8a6c37a4b1e0f505237893
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit5e03358f1b8a6c37a4b1e0f505237893::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit5e03358f1b8a6c37a4b1e0f505237893::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit5e03358f1b8a6c37a4b1e0f505237893::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitccb0f5f37374e069cc240905b0f6415d::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitccb0f5f37374e069cc240905b0f6415d::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitccb0f5f37374e069cc240905b0f6415d::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2059,12 +2059,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "70c2f1368a2b72db44ee55e7d7ba9175c75bba62"
"reference": "2348d4facdbd5f32d24d7e0204d867dffb0e5784"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/70c2f1368a2b72db44ee55e7d7ba9175c75bba62",
"reference": "70c2f1368a2b72db44ee55e7d7ba9175c75bba62",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/2348d4facdbd5f32d24d7e0204d867dffb0e5784",
"reference": "2348d4facdbd5f32d24d7e0204d867dffb0e5784",
"shasum": ""
},
"require": {
@ -2094,7 +2094,7 @@
"tomasvotruba\/type-coverage": "^0.0.9",
"tomasvotruba\/unused-public": "^0.0.34"
},
"time": "2023-05-29T14:02:53+00:00",
"time": "2023-05-29T14:15:43+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-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 7e3df08'), '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 abf0a7f'), '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 edbdd0e'), '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 70c2f13'));
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 7e3df08'), '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 abf0a7f'), '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 edbdd0e'), '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 2348d4f'));
private function __construct()
{
}

View File

@ -8,17 +8,17 @@ final class SensioAttribute
/**
* @var string
*/
public const PARAM_CONVERTER_CLASS = 'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\ParamConverter';
public const PARAM_CONVERTER = 'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\ParamConverter';
/**
* @var string
*/
public const ENTITY_CLASS = 'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Entity';
public const ENTITY = 'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Entity';
/**
* @var string
*/
public const SENSIO_METHOD = 'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Method';
public const METHOD = 'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Method';
/**
* @var string
*/
public const SENSIO_TEMPLATE = 'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template';
public const TEMPLATE = 'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template';
}

View File

@ -16,5 +16,9 @@ final class SymfonyAnnotation
/**
* @var string
*/
public const MAP_ENTITY_CLASS = 'Symfony\\Bridge\\Doctrine\\Attribute\\MapEntity';
public const MAP_ENTITY = 'Symfony\\Bridge\\Doctrine\\Attribute\\MapEntity';
/**
* @var string
*/
public const AS_COMMAND = 'Symfony\\Component\\Console\\Attribute\\AsCommand';
}

View File

@ -0,0 +1,46 @@
<?php
declare (strict_types=1);
namespace Rector\Symfony\NodeAnalyzer\Command;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\Symfony\Enum\SymfonyAnnotation;
final class AttributeValueResolver
{
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
public function __construct(NodeNameResolver $nodeNameResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
}
/**
* @return string|\PhpParser\Node\Expr\ConstFetch|\PhpParser\Node\Expr\Array_|null
*/
public function getArgumentValueFromAttribute(Class_ $class, int $argumentIndexKey)
{
foreach ($class->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attribute) {
if (!$this->nodeNameResolver->isName($attribute->name, SymfonyAnnotation::AS_COMMAND)) {
continue;
}
if (!isset($attribute->args[$argumentIndexKey])) {
continue;
}
$arg = $attribute->args[$argumentIndexKey];
if ($arg->value instanceof String_) {
return $arg->value->value;
} elseif ($arg->value instanceof ConstFetch || $arg->value instanceof Array_) {
return $arg->value;
}
}
}
return null;
}
}

View File

@ -1,32 +1,22 @@
<?php
declare (strict_types=1);
namespace Rector\Symfony\Helper;
namespace Rector\Symfony\NodeAnalyzer\Command;
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\Node\Stmt\Expression;
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
use Rector\Symfony\Enum\SymfonyAnnotation;
final class SetAliasesMethodCallExtractor
{
public const ATTRIBUTE = 'Symfony\\Component\\Console\\Attribute\\AsCommand';
/**
* @readonly
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
@ -49,16 +39,16 @@ final class CommandHelper
private $simpleCallableNodeTraverser;
/**
* @readonly
* @var \Rector\NodeRemoval\NodeRemover
* @var \Rector\Symfony\NodeAnalyzer\Command\AttributeValueResolver
*/
private $nodeRemover;
public function __construct(PhpAttributeAnalyzer $phpAttributeAnalyzer, NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeRemover $nodeRemover)
private $attributeValueResolver;
public function __construct(PhpAttributeAnalyzer $phpAttributeAnalyzer, NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, \Rector\Symfony\NodeAnalyzer\Command\AttributeValueResolver $attributeValueResolver)
{
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
$this->nodeNameResolver = $nodeNameResolver;
$this->nodeTypeResolver = $nodeTypeResolver;
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
$this->nodeRemover = $nodeRemover;
$this->attributeValueResolver = $attributeValueResolver;
}
public function resolveCommandAliasesFromAttributeOrSetter(Class_ $class) : ?Array_
{
@ -90,97 +80,12 @@ final class CommandHelper
});
return $aliasesArray;
}
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->nodeNameResolver->isName($node->name, 'setHidden')) {
return null;
}
if (!$this->nodeTypeResolver->isObjectType($node->var, new ObjectType('Symfony\\Component\\Console\\Command\\Command'))) {
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 isSetAliasesMethodCall(MethodCall $methodCall) : bool
{
if (!$this->nodeNameResolver->isName($methodCall->name, 'setAliases')) {
return \false;
}
return $this->nodeTypeResolver->isObjectType($methodCall->var, new ObjectType('Symfony\\Component\\Console\\Command\\Command'));
}
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 resolveCommandAliasesFromAttribute(Class_ $class) : ?Array_
{
if (!$this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE)) {
if (!$this->phpAttributeAnalyzer->hasPhpAttribute($class, SymfonyAnnotation::AS_COMMAND)) {
return null;
}
$commandAliasesFromArgument = $this->getArgumentValueFromAttribute($class, 2);
$commandAliasesFromArgument = $this->attributeValueResolver->getArgumentValueFromAttribute($class, 2);
if ($commandAliasesFromArgument instanceof Array_) {
return $commandAliasesFromArgument;
}
@ -211,4 +116,11 @@ final class CommandHelper
}
return null;
}
private function isSetAliasesMethodCall(MethodCall $methodCall) : bool
{
if (!$this->nodeNameResolver->isName($methodCall->name, 'setAliases')) {
return \false;
}
return $this->nodeTypeResolver->isObjectType($methodCall->var, new ObjectType('Symfony\\Component\\Console\\Command\\Command'));
}
}

View File

@ -92,7 +92,7 @@ CODE_SAMPLE
return null;
}
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
$sensioDoctrineAnnotationTagValueNode = $phpDocInfo->getByAnnotationClass(SensioAttribute::SENSIO_METHOD);
$sensioDoctrineAnnotationTagValueNode = $phpDocInfo->getByAnnotationClass(SensioAttribute::METHOD);
if (!$sensioDoctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
return null;
}

View File

@ -83,7 +83,7 @@ CODE_SAMPLE
$hasChanged = \false;
foreach ($node->attrGroups as $attrGroupKey => $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
if (!$this->isNames($attr, [SensioAttribute::PARAM_CONVERTER_CLASS, SensioAttribute::ENTITY_CLASS])) {
if (!$this->isNames($attr, [SensioAttribute::PARAM_CONVERTER, SensioAttribute::ENTITY])) {
continue;
}
$attribute = $this->refactorAttribute($node, $attr, $attrGroup);
@ -129,7 +129,7 @@ CODE_SAMPLE
unset($attribute->args[$exprIndex]);
}
$attribute->args = \array_merge($attribute->args, $newArguments);
$attribute->name = new FullyQualified(SymfonyAnnotation::MAP_ENTITY_CLASS);
$attribute->name = new FullyQualified(SymfonyAnnotation::MAP_ENTITY);
$this->addMapEntityAttribute($classMethod, $name, $attributeGroup);
return $attribute;
}

View File

@ -97,7 +97,7 @@ CODE_SAMPLE
if (!$this->hasReturn($node)) {
return null;
}
if ($this->attrinationFinder->hasByOne($node, SensioAttribute::SENSIO_TEMPLATE) || $this->attrinationFinder->hasByOne($node, SymfonyAnnotation::TWIG_TEMPLATE)) {
if ($this->attrinationFinder->hasByOne($node, SensioAttribute::TEMPLATE) || $this->attrinationFinder->hasByOne($node, SymfonyAnnotation::TWIG_TEMPLATE)) {
$node->returnType = new NullableType(new Identifier('array'));
return $node;
}

View File

@ -8,7 +8,6 @@ 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\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
@ -18,7 +17,9 @@ use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory;
use Rector\Symfony\Helper\CommandHelper;
use Rector\Symfony\Enum\SymfonyAnnotation;
use Rector\Symfony\NodeAnalyzer\Command\AttributeValueResolver;
use Rector\Symfony\NodeAnalyzer\Command\SetAliasesMethodCallExtractor;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -39,6 +40,11 @@ final class CommandPropertyToAttributeRector extends AbstractRector implements M
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
*/
private $phpAttributeAnalyzer;
/**
* @readonly
* @var \Rector\Symfony\NodeAnalyzer\Command\AttributeValueResolver
*/
private $attributeValueResolver;
/**
* @readonly
* @var \PHPStan\Reflection\ReflectionProvider
@ -46,15 +52,16 @@ final class CommandPropertyToAttributeRector extends AbstractRector implements M
private $reflectionProvider;
/**
* @readonly
* @var \Rector\Symfony\Helper\CommandHelper
* @var \Rector\Symfony\NodeAnalyzer\Command\SetAliasesMethodCallExtractor
*/
private $commandHelper;
public function __construct(PhpAttributeGroupFactory $phpAttributeGroupFactory, PhpAttributeAnalyzer $phpAttributeAnalyzer, ReflectionProvider $reflectionProvider, CommandHelper $commandHelper)
private $setAliasesMethodCallExtractor;
public function __construct(PhpAttributeGroupFactory $phpAttributeGroupFactory, PhpAttributeAnalyzer $phpAttributeAnalyzer, AttributeValueResolver $attributeValueResolver, ReflectionProvider $reflectionProvider, SetAliasesMethodCallExtractor $setAliasesMethodCallExtractor)
{
$this->phpAttributeGroupFactory = $phpAttributeGroupFactory;
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
$this->attributeValueResolver = $attributeValueResolver;
$this->reflectionProvider = $reflectionProvider;
$this->commandHelper = $commandHelper;
$this->setAliasesMethodCallExtractor = $setAliasesMethodCallExtractor;
}
public function provideMinPhpVersion() : int
{
@ -97,7 +104,7 @@ CODE_SAMPLE
if (!$this->isObjectType($node, new ObjectType('Symfony\\Component\\Console\\Command\\Command'))) {
return null;
}
if (!$this->reflectionProvider->hasClass(CommandHelper::ATTRIBUTE)) {
if (!$this->reflectionProvider->hasClass(SymfonyAnnotation::AS_COMMAND)) {
return null;
}
$defaultName = $this->resolveDefaultName($node);
@ -105,26 +112,20 @@ CODE_SAMPLE
return null;
}
$defaultDescription = $this->resolveDefaultDescription($node);
$alisesArray = $this->commandHelper->resolveCommandAliasesFromAttributeOrSetter($node);
$constFetch = $this->commandHelper->getCommandHiddenValueFromAttributeOrSetter($node);
return $this->replaceAsCommandAttribute($node, $this->createAttributeGroupAsCommand($defaultName, $defaultDescription, $alisesArray, $constFetch));
$alisesArray = $this->setAliasesMethodCallExtractor->resolveCommandAliasesFromAttributeOrSetter($node);
return $this->replaceAsCommandAttribute($node, $this->createAttributeGroupAsCommand($defaultName, $defaultDescription, $alisesArray));
}
private function createAttributeGroupAsCommand(string $defaultName, ?string $defaultDescription, ?Array_ $aliasesArray, ?ConstFetch $constFetch) : AttributeGroup
private function createAttributeGroupAsCommand(string $defaultName, ?string $defaultDescription, ?Array_ $aliasesArray) : AttributeGroup
{
$attributeGroup = $this->phpAttributeGroupFactory->createFromClass(CommandHelper::ATTRIBUTE);
$attributeGroup = $this->phpAttributeGroupFactory->createFromClass(SymfonyAnnotation::AS_COMMAND);
$attributeGroup->attrs[0]->args[] = new Arg(new String_($defaultName));
if ($defaultDescription !== null) {
$attributeGroup->attrs[0]->args[] = new Arg(new String_($defaultDescription));
} elseif ($aliasesArray instanceof Array_ || $constFetch instanceof ConstFetch) {
} elseif ($aliasesArray instanceof Array_) {
$attributeGroup->attrs[0]->args[] = new Arg($this->nodeFactory->createNull());
}
if ($aliasesArray instanceof Array_) {
$attributeGroup->attrs[0]->args[] = new Arg($aliasesArray);
} elseif ($constFetch instanceof ConstFetch) {
$attributeGroup->attrs[0]->args[] = new Arg(new Array_());
}
if ($constFetch instanceof ConstFetch) {
$attributeGroup->attrs[0]->args[] = new Arg($constFetch);
}
return $attributeGroup;
}
@ -151,8 +152,8 @@ CODE_SAMPLE
}
}
// Get DefaultName from attribute
if ($defaultName === null && $this->phpAttributeAnalyzer->hasPhpAttribute($class, CommandHelper::ATTRIBUTE)) {
$defaultNameFromArgument = $this->commandHelper->getArgumentValueFromAttribute($class, 0);
if ($defaultName === null && $this->phpAttributeAnalyzer->hasPhpAttribute($class, SymfonyAnnotation::AS_COMMAND)) {
$defaultNameFromArgument = $this->attributeValueResolver->getArgumentValueFromAttribute($class, 0);
if (\is_string($defaultNameFromArgument)) {
$defaultName = $defaultNameFromArgument;
}
@ -173,8 +174,8 @@ CODE_SAMPLE
}
private function resolveDefaultDescriptionFromAttribute(Class_ $class, ?string $defaultDescription) : ?string
{
if ($defaultDescription === null && $this->phpAttributeAnalyzer->hasPhpAttribute($class, CommandHelper::ATTRIBUTE)) {
$defaultDescriptionFromArgument = $this->commandHelper->getArgumentValueFromAttribute($class, 1);
if ($defaultDescription === null && $this->phpAttributeAnalyzer->hasPhpAttribute($class, SymfonyAnnotation::AS_COMMAND)) {
$defaultDescriptionFromArgument = $this->attributeValueResolver->getArgumentValueFromAttribute($class, 1);
if (\is_string($defaultDescriptionFromArgument)) {
$defaultDescription = $defaultDescriptionFromArgument;
}
@ -187,7 +188,7 @@ CODE_SAMPLE
$replacedAsCommandAttribute = \false;
foreach ($class->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attribute) {
if ($this->nodeNameResolver->isName($attribute->name, CommandHelper::ATTRIBUTE)) {
if ($this->nodeNameResolver->isName($attribute->name, SymfonyAnnotation::AS_COMMAND)) {
$hasAsCommandAttribute = \true;
$replacedAsCommandAttribute = $this->replaceArguments($attribute, $createAttributeGroup);
}