diff --git a/src/Traits/AttributeResolverTrait.php b/src/Traits/AttributeResolverTrait.php index 1065eff..d66ebfe 100644 --- a/src/Traits/AttributeResolverTrait.php +++ b/src/Traits/AttributeResolverTrait.php @@ -13,13 +13,6 @@ namespace Go\ParserReflection\Traits; use Go\ParserReflection\ReflectionAttribute; -use Go\ParserReflection\ReflectionException; -use PhpParser\Node\Param; -use PhpParser\Node\Stmt\Class_; -use PhpParser\Node\Stmt\ClassConst; -use PhpParser\Node\Stmt\ClassMethod; -use PhpParser\Node\Stmt\Function_; -use PhpParser\Node\Stmt\Property; trait AttributeResolverTrait { @@ -30,32 +23,12 @@ public function getAttributes(?string $name = null, int $flags = 0): array { $attributes = []; - /** @var Class_|ClassMethod|Property|ClassConst|Function_|Param $node */ - $node = $this->getNode(); - - foreach ($node->attrGroups as $attrGroup) { - foreach ($attrGroup->attrs as $attr) { - $attributeName = $name === null - ? $attr->name->toString() - : $name; - - $attributes[] = new ReflectionAttribute($attributeName, $this, $flags, $attr->args, $this->resolveTarget($attributeName, $flags)); - } - } - - return $attributes; - } - - private function resolveTarget(string $name, int $flags): int - { $originalAttributes = parent::getAttributes($name, $flags); - foreach ($originalAttributes as $originalAttribute) { - if ($originalAttribute->getName() === $name) { - return $originalAttribute->getTarget(); - } + $attributeName = $originalAttribute->getName(); + $attributes[] = new ReflectionAttribute($attributeName, $this, $flags, $originalAttribute->getArguments(), $originalAttribute->getTarget()); } - throw new ReflectionException(sprintf('target not found on attribute %s', $name)); + return $attributes; } }