Skip to content

Commit

Permalink
Merge pull request #301 from phpDocumentor/feature/add-support-for-us…
Browse files Browse the repository at this point in the history
…ing-traits-in-enums

Add support for using traits in enums
  • Loading branch information
jaapio committed Dec 4, 2022
2 parents 9fac0fb + 8021b36 commit 8ccd850
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/phpDocumentor/Reflection/Php/Factory/TraitUse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use InvalidArgumentException;
use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\Php\Class_;
use phpDocumentor\Reflection\Php\Enum_;
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
use phpDocumentor\Reflection\Php\StrategyContainer;
use phpDocumentor\Reflection\Php\Trait_;
Expand All @@ -31,8 +32,12 @@ public function create(ContextStack $context, object $object, StrategyContainer

$class = $context->peek();

if ($class instanceof Class_ === false && $class instanceof Trait_ === false) {
throw new InvalidArgumentException('Traits can only be used in class or trait');
if (
$class instanceof Class_ === false
&& $class instanceof Trait_ === false
&& $class instanceof Enum_ === false
) {
throw new InvalidArgumentException('Traits can only be used in classes, enums or other traits');
}

foreach ($object->traits as $trait) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use phpDocumentor\Reflection\Element;
use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\Php\Class_ as Class_Element;
use phpDocumentor\Reflection\Php\Enum_ as Enum_Element;
use phpDocumentor\Reflection\Php\Interface_;
use phpDocumentor\Reflection\Php\ProjectFactoryStrategies;
use phpDocumentor\Reflection\Php\Trait_ as Trait_Element;
Expand All @@ -26,6 +27,7 @@ public function consumerProvider(): array
return [
[new Class_Element(new Fqsen('\MyClass'))],
[new Trait_Element(new Fqsen('\MyTrait'))],
[new Enum_Element(new Fqsen('\MyEnum'), null)],
];
}

Expand Down

0 comments on commit 8ccd850

Please sign in to comment.