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

Add support for using traits in enums #301

Merged
merged 1 commit into from
Dec 4, 2022
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
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