fix: return indexed list of attributes when filtering on type

This commit is contained in:
Fred-Jan van der Eijken 2022-01-26 18:59:57 +01:00 committed by GitHub
parent 718d3c1bc2
commit 66aa4d688a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -7,6 +7,7 @@ namespace CuyZ\Valinor\Definition;
use Traversable;
use function array_filter;
use function array_values;
use function count;
/** @internal */
@ -33,10 +34,10 @@ final class AttributesContainer implements Attributes
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

View File

@ -41,6 +41,14 @@ final class ObjectBuilderStrategyMappingTest extends IntegrationTest
}
}
/**
* @Annotation
*/
#[Attribute(Attribute::TARGET_CLASS)]
final class ForeignAttribute
{
}
/**
* @Annotation
*/
@ -54,8 +62,10 @@ final class ObjectBuilderStrategyAttribute implements ObjectBuilderFactory
}
/**
* @ForeignAttribute
* @StaticMethodConstructor("create")
*/
#[ForeignAttribute]
#[StaticMethodConstructor('create')]
final class ObjectWithBuilderStrategyAttribute
{