Skip to content

Commit

Permalink
[BUGFIX] Fix missing class (#4290)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Jul 16, 2024
1 parent ea8c182 commit 579c345
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rules/TYPO312/v4/CommandConfigurationToAttributeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
54 changes: 54 additions & 0 deletions src/NodeAnalyzer/AttributeValueResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\NodeAnalyzer;

use PhpParser\Node\Expr;
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
*/
private NodeNameResolver $nodeNameResolver;

public function __construct(
NodeNameResolver $nodeNameResolver
) {
$this->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;
}
}
1 change: 0 additions & 1 deletion src/NodeAnalyzer/SetAliasesMethodCallExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 579c345

Please sign in to comment.