Skip to content

Commit d835fa5

Browse files
committed
TASK: UnionType::getIterator use yield from
1 parent 6a8bd00 commit d835fa5

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/TypeSystem/Type/UnionType/UnionType.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,16 @@ public function is(TypeInterface $other): bool
106106
}
107107
}
108108

109-
/** @return \ArrayIterator<int, TypeInterface> */
110-
public function getIterator(): \ArrayIterator
109+
/** @return \Iterator<int, TypeInterface> */
110+
public function getIterator(): \Iterator
111111
{
112-
return new \ArrayIterator($this->members);
112+
yield from $this->members;
113+
}
114+
115+
/** @return array<int, TypeInterface> */
116+
public function toArray(): array
117+
{
118+
return $this->members;
113119
}
114120

115121
public function count(): int

test/Unit/TypeSystem/Type/UnionType/UnionTypeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public function unionOnlyHoldsDeduplicatedMembers(): void
114114
$this->assertCount(count($unionType), $otherUnionType);
115115

116116
$this->assertEqualsCanonicalizing(
117-
$unionType->getIterator()->getArrayCopy(),
118-
$otherUnionType->getIterator()->getArrayCopy()
117+
$unionType->toArray(),
118+
$otherUnionType->toArray()
119119
);
120120
}
121121

0 commit comments

Comments
 (0)