Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Fix missing class #4290

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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