misc!: change Attributes::ofType return type to array

There was no benefits having the return type as `iterable`, but it would
make it harder to use the result of the method.
This commit is contained in:
Romain Canon 2022-03-17 21:13:10 +01:00
parent fd11177b06
commit 1a599b0bdf
11 changed files with 9 additions and 11 deletions

View File

@ -25,5 +25,5 @@ interface Attributes extends IteratorAggregate, Countable
* @param class-string<T> $className
* @return list<T>
*/
public function ofType(string $className): iterable;
public function ofType(string $className): array;
}

View File

@ -32,7 +32,7 @@ final class AttributesContainer implements Attributes
return false;
}
public function ofType(string $className): iterable
public function ofType(string $className): array
{
return array_values(array_filter(
$this->attributes,

View File

@ -44,7 +44,7 @@ final class CombinedAttributes implements Attributes
return $this->delegate->has($className);
}
public function ofType(string $className): iterable
public function ofType(string $className): array
{
return $this->delegate->ofType($className);
}

View File

@ -32,7 +32,7 @@ final class DoctrineAnnotations implements Attributes
return $this->delegate->has($className);
}
public function ofType(string $className): iterable
public function ofType(string $className): array
{
return $this->delegate->ofType($className);
}

View File

@ -17,7 +17,7 @@ final class EmptyAttributes implements Attributes
return false;
}
public function ofType(string $className): iterable
public function ofType(string $className): array
{
return [];
}

View File

@ -41,7 +41,7 @@ final class NativeAttributes implements Attributes
return $this->delegate->has($className);
}
public function ofType(string $className): iterable
public function ofType(string $className): array
{
return $this->delegate->ofType($className);
}

View File

@ -22,7 +22,6 @@ final class AttributeObjectBuilderFactory implements ObjectBuilderFactory
public function for(ClassDefinition $class, $source): ObjectBuilder
{
/** @var ObjectBuilderFactory[] $attributes */
$attributes = $class->attributes()->ofType(ObjectBuilderFactory::class);
if (count($attributes) === 0) {

View File

@ -11,7 +11,6 @@ final class AttributeShellVisitor implements ShellVisitor
{
public function visit(Shell $shell): Shell
{
/** @var ShellVisitor[] $visitors */
$visitors = $shell->attributes()->ofType(ShellVisitor::class);
foreach ($visitors as $visitor) {

View File

@ -14,7 +14,7 @@ final class FakeAttributes implements Attributes
return false;
}
public function ofType(string $className): iterable
public function ofType(string $className): array
{
return [];
}

View File

@ -14,7 +14,7 @@ final class FakeNonEmptyAttributes implements Attributes
return true;
}
public function ofType(string $className): iterable
public function ofType(string $className): array
{
return [];
}

View File

@ -40,8 +40,8 @@ final class AttributesContainerTest extends TestCase
$attributes = new AttributesContainer($object, $date);
$filteredAttributes = $attributes->ofType(DateTimeInterface::class);
self::assertNotSame($filteredAttributes, $attributes);
self::assertContainsEquals($date, $filteredAttributes);
self::assertNotContains($object, $filteredAttributes);
self::assertSame($date, $filteredAttributes[0]);
}
}