diff --git a/rules/TYPO312/v4/CommandConfigurationToAttributeRector.php b/rules/TYPO312/v4/CommandConfigurationToAttributeRector.php index 82bd77fd5..b5edcccdc 100644 --- a/rules/TYPO312/v4/CommandConfigurationToAttributeRector.php +++ b/rules/TYPO312/v4/CommandConfigurationToAttributeRector.php @@ -19,10 +19,10 @@ use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory; use Rector\Rector\AbstractRector; use Rector\Symfony\Enum\SymfonyAnnotation; -use Rector\Symfony\NodeAnalyzer\Command\AttributeValueResolver; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Ssch\TYPO3Rector\Helper\ServiceDefinitionHelper; +use Ssch\TYPO3Rector\NodeAnalyzer\AttributeValueResolver; use Ssch\TYPO3Rector\NodeAnalyzer\SetAliasesMethodCallExtractor; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/NodeAnalyzer/AttributeValueResolver.php b/src/NodeAnalyzer/AttributeValueResolver.php new file mode 100644 index 000000000..b4c09917d --- /dev/null +++ b/src/NodeAnalyzer/AttributeValueResolver.php @@ -0,0 +1,54 @@ +nodeNameResolver = $nodeNameResolver; + } + + /** + * @return Expr|Array_|ConstFetch|null|string + */ + 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; + } +} diff --git a/src/NodeAnalyzer/SetAliasesMethodCallExtractor.php b/src/NodeAnalyzer/SetAliasesMethodCallExtractor.php index 95ccfed34..e7f86ee1f 100644 --- a/src/NodeAnalyzer/SetAliasesMethodCallExtractor.php +++ b/src/NodeAnalyzer/SetAliasesMethodCallExtractor.php @@ -16,7 +16,6 @@ use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser; use Rector\Symfony\Enum\SymfonyAnnotation; -use Rector\Symfony\NodeAnalyzer\Command\AttributeValueResolver; final class SetAliasesMethodCallExtractor {