Skip to content

Commit e9331d2

Browse files
committed
PHPLIB-1523: Remove iterators for database, collection, and index enumeration
1 parent f4cc84e commit e9331d2

26 files changed

+93
-529
lines changed

UPGRADE-2.0.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ UPGRADE FROM 1.x to 2.0
66
* The `MongoDB\ChangeStream::CURSOR_NOT_FOUND` constant is now private.
77
* The `MongoDB\Operation\Watch::FULL_DOCUMENT_DEFAULT` constant has been
88
removed.
9-
* The `MongoDB\Model\IndexInfo::isGeoHaystack` method has been removed.
9+
* The `getNamespace` and `isGeoHaystack` methods hav been removed from the
10+
`MongoDB\Model\IndexInfo` class.
1011
* The `maxScan`, `modifiers`, `oplogReplay`, and `snapshot` options for `find`
1112
and `findOne` operations have been removed.
12-
* The `MongoDB\Operation\Executable` interface has been removed.
13+
* The following classes and interfaces have been removed without replacement:
14+
* `MongoDB\Operation\Executable`
15+
* `MongoDB\Model\CollectionInfoCommandIterator`
16+
* `MongoDB\Model\CollectionInfoIterator`
17+
* `MongoDB\Model\DatabaseInfoIterator`
18+
* `MongoDB\Model\DatabaseInfoLegacyIterator`
19+
* `MongoDB\Model\IndexInfoIterator`
20+
* `MongoDB\Model\IndexInfoIteratorIterator`
1321

1422
GridFS
1523
------

psalm-baseline.xml

-91
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,13 @@
180180
</RedundantConditionGivenDocblockType>
181181
</file>
182182
<file src="src/Client.php">
183-
<DeprecatedInterface>
184-
<code><![CDATA[DatabaseInfoIterator]]></code>
185-
</DeprecatedInterface>
186-
<MismatchingDocblockReturnType>
187-
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
188-
</MismatchingDocblockReturnType>
189183
<MixedArgument>
190184
<code><![CDATA[$driverOptions['driver'] ?? []]]></code>
191185
<code><![CDATA[$pipeline]]></code>
192186
</MixedArgument>
193187
<MixedAssignment>
194188
<code><![CDATA[$mergedDriver['platform']]]></code>
195189
</MixedAssignment>
196-
<MixedInferredReturnType>
197-
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
198-
</MixedInferredReturnType>
199190
<MixedPropertyTypeCoercion>
200191
<code><![CDATA[$driverOptions['builderEncoder'] ?? new BuilderEncoder()]]></code>
201192
</MixedPropertyTypeCoercion>
@@ -227,19 +218,10 @@
227218
</MixedArgumentTypeCoercion>
228219
</file>
229220
<file src="src/Collection.php">
230-
<DeprecatedInterface>
231-
<code><![CDATA[IndexInfoIterator]]></code>
232-
</DeprecatedInterface>
233-
<MismatchingDocblockReturnType>
234-
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
235-
</MismatchingDocblockReturnType>
236221
<MixedArgument>
237222
<code><![CDATA[$pipeline]]></code>
238223
<code><![CDATA[$pipeline]]></code>
239224
</MixedArgument>
240-
<MixedInferredReturnType>
241-
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
242-
</MixedInferredReturnType>
243225
<MixedPropertyTypeCoercion>
244226
<code><![CDATA[$options['builderEncoder'] ?? new BuilderEncoder()]]></code>
245227
</MixedPropertyTypeCoercion>
@@ -266,19 +248,10 @@
266248
</MixedAssignment>
267249
</file>
268250
<file src="src/Database.php">
269-
<DeprecatedInterface>
270-
<code><![CDATA[CollectionInfoIterator]]></code>
271-
</DeprecatedInterface>
272-
<MismatchingDocblockReturnType>
273-
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
274-
</MismatchingDocblockReturnType>
275251
<MixedArgument>
276252
<code><![CDATA[$pipeline]]></code>
277253
<code><![CDATA[$pipeline]]></code>
278254
</MixedArgument>
279-
<MixedInferredReturnType>
280-
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
281-
</MixedInferredReturnType>
282255
<MixedPropertyTypeCoercion>
283256
<code><![CDATA[$options['builderEncoder'] ?? new BuilderEncoder()]]></code>
284257
</MixedPropertyTypeCoercion>
@@ -383,34 +356,6 @@
383356
<code><![CDATA[$this->current()]]></code>
384357
</PossiblyNullArgument>
385358
</file>
386-
<file src="src/Model/CollectionInfoCommandIterator.php">
387-
<DeprecatedInterface>
388-
<code><![CDATA[CollectionInfoCommandIterator]]></code>
389-
</DeprecatedInterface>
390-
<MixedArrayAssignment>
391-
<code><![CDATA[$info['idIndex']['ns']]]></code>
392-
</MixedArrayAssignment>
393-
<MixedOperand>
394-
<code><![CDATA[$info['name']]]></code>
395-
</MixedOperand>
396-
</file>
397-
<file src="src/Model/DatabaseInfoLegacyIterator.php">
398-
<DeprecatedInterface>
399-
<code><![CDATA[DatabaseInfoLegacyIterator]]></code>
400-
</DeprecatedInterface>
401-
<MixedArgument>
402-
<code><![CDATA[current($this->databases)]]></code>
403-
</MixedArgument>
404-
<MixedReturnTypeCoercion>
405-
<code><![CDATA[int]]></code>
406-
<code><![CDATA[key($this->databases)]]></code>
407-
</MixedReturnTypeCoercion>
408-
</file>
409-
<file src="src/Model/IndexInfoIteratorIterator.php">
410-
<DeprecatedInterface>
411-
<code><![CDATA[IndexInfoIteratorIterator]]></code>
412-
</DeprecatedInterface>
413-
</file>
414359
<file src="src/Model/IndexInput.php">
415360
<LessSpecificReturnStatement>
416361
<code><![CDATA[(object) $this->index]]></code>
@@ -793,47 +738,11 @@
793738
<code><![CDATA[$document]]></code>
794739
</PossiblyInvalidArgument>
795740
</file>
796-
<file src="src/Operation/ListCollections.php">
797-
<DeprecatedInterface>
798-
<code><![CDATA[CollectionInfoIterator]]></code>
799-
</DeprecatedInterface>
800-
<MismatchingDocblockReturnType>
801-
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
802-
</MismatchingDocblockReturnType>
803-
<MixedInferredReturnType>
804-
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
805-
</MixedInferredReturnType>
806-
</file>
807-
<file src="src/Operation/ListDatabases.php">
808-
<DeprecatedInterface>
809-
<code><![CDATA[DatabaseInfoIterator]]></code>
810-
</DeprecatedInterface>
811-
<MismatchingDocblockReturnType>
812-
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
813-
</MismatchingDocblockReturnType>
814-
<MixedInferredReturnType>
815-
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
816-
</MixedInferredReturnType>
817-
</file>
818741
<file src="src/Operation/ListIndexes.php">
819-
<DeprecatedClass>
820-
<code><![CDATA[IndexInfoIteratorIterator]]></code>
821-
<code><![CDATA[new IndexInfoIteratorIterator($iterator, $this->databaseName . '.' . $this->collectionName)]]></code>
822-
<code><![CDATA[new IndexInfoIteratorIterator(new EmptyIterator())]]></code>
823-
</DeprecatedClass>
824-
<DeprecatedInterface>
825-
<code><![CDATA[IndexInfoIterator]]></code>
826-
</DeprecatedInterface>
827-
<MismatchingDocblockReturnType>
828-
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
829-
</MismatchingDocblockReturnType>
830742
<MixedAssignment>
831743
<code><![CDATA[$cmd[$option]]]></code>
832744
<code><![CDATA[$options['session']]]></code>
833745
</MixedAssignment>
834-
<MixedInferredReturnType>
835-
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
836-
</MixedInferredReturnType>
837746
</file>
838747
<file src="src/Operation/MapReduce.php">
839748
<MixedArgument>

src/Client.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
use MongoDB\Model\BSONArray;
4040
use MongoDB\Model\BSONDocument;
4141
use MongoDB\Model\DatabaseInfo;
42-
use MongoDB\Model\DatabaseInfoIterator;
4342
use MongoDB\Operation\DropDatabase;
4443
use MongoDB\Operation\ListDatabaseNames;
4544
use MongoDB\Operation\ListDatabases;
@@ -305,7 +304,7 @@ public function listDatabaseNames(array $options = []): Iterator
305304
* @throws InvalidArgumentException for parameter/option parsing errors
306305
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
307306
*/
308-
public function listDatabases(array $options = []): DatabaseInfoIterator
307+
public function listDatabases(array $options = []): Iterator
309308
{
310309
$operation = new ListDatabases($options);
311310
$server = select_server($this->manager, $options);

src/Collection.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
use MongoDB\Model\BSONArray;
3939
use MongoDB\Model\BSONDocument;
4040
use MongoDB\Model\IndexInfo;
41-
use MongoDB\Model\IndexInfoIterator;
4241
use MongoDB\Operation\Aggregate;
4342
use MongoDB\Operation\BulkWrite;
4443
use MongoDB\Operation\Count;
@@ -884,7 +883,7 @@ public function insertOne(array|object $document, array $options = []): InsertOn
884883
* @throws InvalidArgumentException for parameter/option parsing errors
885884
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
886885
*/
887-
public function listIndexes(array $options = []): IndexInfoIterator
886+
public function listIndexes(array $options = []): Iterator
888887
{
889888
$operation = new ListIndexes($this->databaseName, $this->collectionName, $options);
890889

src/Command/ListCollections.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
namespace MongoDB\Command;
1919

2020
use MongoDB\Driver\Command;
21-
use MongoDB\Driver\Cursor;
21+
use MongoDB\Driver\CursorInterface;
2222
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
2323
use MongoDB\Driver\Server;
2424
use MongoDB\Driver\Session;
2525
use MongoDB\Exception\InvalidArgumentException;
26-
use MongoDB\Model\CachingIterator;
2726

2827
use function is_bool;
2928
use function is_integer;
@@ -92,16 +91,16 @@ public function __construct(private string $databaseName, private array $options
9291
/**
9392
* Execute the operation.
9493
*
95-
* @return CachingIterator<int, array>
94+
* @return CursorInterface<array>
9695
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
9796
*/
98-
public function execute(Server $server): CachingIterator
97+
public function execute(Server $server): CursorInterface
9998
{
100-
/** @var Cursor<array> $cursor */
99+
/** @var CursorInterface<array> $cursor */
101100
$cursor = $server->executeReadCommand($this->databaseName, $this->createCommand(), $this->createOptions());
102101
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
103102

104-
return new CachingIterator($cursor);
103+
return $cursor;
105104
}
106105

107106
/**

src/Command/ListDatabases.php

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public function execute(Server $server): array
100100
{
101101
$cursor = $server->executeReadCommand('admin', $this->createCommand(), $this->createOptions());
102102
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
103+
103104
$result = current($cursor->toArray());
104105

105106
if (! isset($result['databases']) || ! is_array($result['databases'])) {

src/Database.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
use MongoDB\Model\BSONArray;
3939
use MongoDB\Model\BSONDocument;
4040
use MongoDB\Model\CollectionInfo;
41-
use MongoDB\Model\CollectionInfoIterator;
4241
use MongoDB\Operation\Aggregate;
4342
use MongoDB\Operation\CreateCollection;
4443
use MongoDB\Operation\CreateEncryptedCollection;
@@ -479,7 +478,7 @@ public function listCollectionNames(array $options = []): Iterator
479478
* @throws InvalidArgumentException for parameter/option parsing errors
480479
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
481480
*/
482-
public function listCollections(array $options = []): CollectionInfoIterator
481+
public function listCollections(array $options = []): Iterator
483482
{
484483
$operation = new ListCollections($this->databaseName, $options);
485484
$server = select_server($this->manager, $options);

src/Model/CallbackIterator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* @internal
3030
*
31-
* @template TKey
31+
* @template TKey of array-key
3232
* @template TValue
3333
* @template TCallbackValue
3434
* @template-implements Iterator<TKey, TCallbackValue>

src/Model/CollectionInfoCommandIterator.php

-60
This file was deleted.

src/Model/CollectionInfoIterator.php

-37
This file was deleted.

0 commit comments

Comments
 (0)