Skip to content

Commit

Permalink
fix: return indexed list of attributes when filtering on type
Browse files Browse the repository at this point in the history
  • Loading branch information
fred-jan authored Jan 26, 2022
1 parent 718d3c1 commit 66aa4d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Definition/AttributesContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Traversable;

use function array_filter;
use function array_values;
use function count;

/** @internal */
Expand All @@ -33,10 +34,10 @@ public function has(string $className): bool

public function ofType(string $className): iterable
{
return array_filter(
return array_values(array_filter(
$this->attributes,
static fn (object $attribute): bool => $attribute instanceof $className
);
));
}

public function count(): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public function test_repeated_object_builder_factory_attributes_throws_exception
}
}

/**
* @Annotation
*/
#[Attribute(Attribute::TARGET_CLASS)]
final class ForeignAttribute
{
}

/**
* @Annotation
*/
Expand All @@ -54,8 +62,10 @@ public function for(ClassDefinition $class, $source): ObjectBuilder
}

/**
* @ForeignAttribute
* @StaticMethodConstructor("create")
*/
#[ForeignAttribute]
#[StaticMethodConstructor('create')]
final class ObjectWithBuilderStrategyAttribute
{
Expand Down

0 comments on commit 66aa4d6

Please sign in to comment.