From 0fcff83eac747be8233444896a70043a4a045932 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 17 Nov 2023 21:59:29 -0500 Subject: [PATCH] - Fixed missing tags from traits --- src/AnnotationReader.php | 6 +++--- src/ObjectReflection.php | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/AnnotationReader.php b/src/AnnotationReader.php index c1fd360..5d30232 100644 --- a/src/AnnotationReader.php +++ b/src/AnnotationReader.php @@ -34,12 +34,12 @@ class AnnotationReader return $this->parseDocComment($method); } - protected function parseDocComment(Reflector $reflect) + protected function parseDocComment(\Reflector $reflect) { $tags = []; - if ( $reflect->getAttributes() ) { - foreach($reflect->getAttributes() as $attr) { + if ( $attributes = $reflect->getAttributes() ) { + foreach($attributes as $attr) { try { $tags[] = [ 'tag' => substr(strrchr($attr->getName(), "\\"), 1), diff --git a/src/ObjectReflection.php b/src/ObjectReflection.php index e6f8d08..8e71dae 100644 --- a/src/ObjectReflection.php +++ b/src/ObjectReflection.php @@ -65,13 +65,13 @@ class ObjectReflection { if ( $traits = $this->classReflection->getTraits() ) { foreach($traits as $key => $value) { - $traitTags = static::fromClass($key)->gatherClass(true); + $traitTags = array_merge_recursive($traitTags ?? [], static::fromClass($key)->gatherClass(true)); } } if ( $interfaces = $this->classReflection->getInterfaces() ) { foreach($interfaces as $key => $value) { - $interfaceTags = static::fromClass($key)->gatherClass(true); + $interfaceTags = array_merge_recursive($interfaceTags ?? [], static::fromClass($key)->gatherClass(true)); } } @@ -81,11 +81,11 @@ class ObjectReflection { } return array_merge_recursive($class ?? [], $traitTags ?? [], $interfaceTags ?? [], [ - 'tags' => $this->annotationReader->getClass($this->classReflection) - ] + ( ! $full ? [] : [ - 'traits' => array_map($itemName, $traits), - 'interfaces' => array_map($itemName, $interfaces), - ] )); + 'tags' => $this->annotationReader->getClass($this->classReflection) + ] + ( ! $full ? [] : [ + 'traits' => array_map($itemName, $traits), + 'interfaces' => array_map($itemName, $interfaces), + ] )); } public function gatherProperties(bool $full = true, int $filter =