Skip to content

Commit d6185ec

Browse files
authored
Merge pull request #7101 from morozov/object-set-as-traversable
Implement IteratorAggregate in ObjectSet subclasses
2 parents af03149 + d739bd8 commit d6185ec

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

src/Schema/Collections/ObjectSet.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
use Doctrine\DBAL\Schema\Collections\Exception\ObjectAlreadyExists;
88
use Doctrine\DBAL\Schema\Collections\Exception\ObjectDoesNotExist;
99
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
10+
use IteratorAggregate;
1011

1112
/**
1213
* A set of objects where each object is uniquely identified by its {@link UnqualifiedName}.
1314
*
1415
* @internal
1516
*
1617
* @template E of object
18+
* @template-extends IteratorAggregate<int, E>
1719
*/
18-
interface ObjectSet
20+
interface ObjectSet extends IteratorAggregate
1921
{
2022
/**
2123
* Checks if the set is empty.

src/Schema/Collections/OptionallyUnqualifiedNamedObjectSet.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Schema\Collections\Exception\ObjectDoesNotExist;
99
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
1010
use Doctrine\DBAL\Schema\OptionallyNamedObject;
11+
use Traversable;
1112

1213
use function array_splice;
1314
use function count;
@@ -110,6 +111,12 @@ public function toList(): array
110111
return $this->elements;
111112
}
112113

114+
/** {@inheritDoc} */
115+
public function getIterator(): Traversable
116+
{
117+
yield from $this->elements;
118+
}
119+
113120
/**
114121
* Replaces the element corresponding to the old key with the provided element.
115122
*

src/Schema/Collections/UnqualifiedNamedObjectSet.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Schema\Collections\Exception\ObjectDoesNotExist;
99
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
1010
use Doctrine\DBAL\Schema\NamedObject;
11+
use Traversable;
1112

1213
use function array_combine;
1314
use function array_keys;
@@ -97,6 +98,14 @@ public function toList(): array
9798
return array_values($this->elements);
9899
}
99100

101+
/** {@inheritDoc} */
102+
public function getIterator(): Traversable
103+
{
104+
foreach ($this->elements as $element) {
105+
yield $element;
106+
}
107+
}
108+
100109
/**
101110
* Replaces the element corresponding to the old key with the provided element. The position of the element in the
102111
* set is preserved.

src/Schema/TableEditor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function renameColumn(UnqualifiedName $oldColumnName, UnqualifiedName $ne
156156

157157
private function renameColumnInIndexes(UnqualifiedName $oldColumnName, UnqualifiedName $newColumnName): void
158158
{
159-
foreach ($this->indexes->toList() as $index) {
159+
foreach ($this->indexes as $index) {
160160
$modified = false;
161161
$columns = [];
162162

@@ -264,7 +264,7 @@ private function renameColumnInConstraints(
264264
$constraints = [];
265265
$anyModified = false;
266266

267-
foreach ($collection->toList() as $constraint) {
267+
foreach ($collection as $constraint) {
268268
$newColumnNames = [];
269269
$modified = false;
270270

0 commit comments

Comments
 (0)