Skip to content

Commit 2109214

Browse files
authored
PHPLIB-1522: Deprecate info iterators (#1438)
* PHPLIB-1522: Deprecate info iterators * Remove usages of info iterator interfaces in return types * Deprecate IndexInfo::getNamespace * Use templated return type
1 parent 9f20467 commit 2109214

14 files changed

+51
-13
lines changed

Diff for: psalm-baseline.xml

+26
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@
150150
</TooManyArguments>
151151
</file>
152152
<file src="src/Model/CollectionInfoCommandIterator.php">
153+
<DeprecatedInterface>
154+
<code><![CDATA[CollectionInfoCommandIterator]]></code>
155+
</DeprecatedInterface>
153156
<MixedArrayAssignment>
154157
<code><![CDATA[$info['idIndex']['ns']]]></code>
155158
</MixedArrayAssignment>
@@ -158,6 +161,9 @@
158161
</MixedOperand>
159162
</file>
160163
<file src="src/Model/DatabaseInfoLegacyIterator.php">
164+
<DeprecatedInterface>
165+
<code><![CDATA[DatabaseInfoLegacyIterator]]></code>
166+
</DeprecatedInterface>
161167
<MixedArgument>
162168
<code><![CDATA[current($this->databases)]]></code>
163169
</MixedArgument>
@@ -166,6 +172,11 @@
166172
<code><![CDATA[key($this->databases)]]></code>
167173
</MixedReturnTypeCoercion>
168174
</file>
175+
<file src="src/Model/IndexInfoIteratorIterator.php">
176+
<DeprecatedInterface>
177+
<code><![CDATA[IndexInfoIteratorIterator]]></code>
178+
</DeprecatedInterface>
179+
</file>
169180
<file src="src/Model/IndexInput.php">
170181
<LessSpecificReturnStatement>
171182
<code><![CDATA[(object) $this->index]]></code>
@@ -553,7 +564,22 @@
553564
<code><![CDATA[$document]]></code>
554565
</PossiblyInvalidArgument>
555566
</file>
567+
<file src="src/Operation/ListCollections.php">
568+
<DeprecatedClass>
569+
<code><![CDATA[new CollectionInfoCommandIterator($this->listCollections->execute($server), $this->databaseName)]]></code>
570+
</DeprecatedClass>
571+
</file>
572+
<file src="src/Operation/ListDatabases.php">
573+
<DeprecatedClass>
574+
<code><![CDATA[new DatabaseInfoLegacyIterator($this->listDatabases->execute($server))]]></code>
575+
</DeprecatedClass>
576+
</file>
556577
<file src="src/Operation/ListIndexes.php">
578+
<DeprecatedClass>
579+
<code><![CDATA[IndexInfoIteratorIterator]]></code>
580+
<code><![CDATA[new IndexInfoIteratorIterator($iterator, $this->databaseName . '.' . $this->collectionName)]]></code>
581+
<code><![CDATA[new IndexInfoIteratorIterator(new EmptyIterator())]]></code>
582+
</DeprecatedClass>
557583
<MixedAssignment>
558584
<code><![CDATA[$cmd[$option]]]></code>
559585
<code><![CDATA[$options['session']]]></code>

Diff for: src/Client.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
use MongoDB\Exception\UnsupportedException;
3434
use MongoDB\Model\BSONArray;
3535
use MongoDB\Model\BSONDocument;
36-
use MongoDB\Model\DatabaseInfoIterator;
36+
use MongoDB\Model\DatabaseInfo;
3737
use MongoDB\Operation\DropDatabase;
3838
use MongoDB\Operation\ListDatabaseNames;
3939
use MongoDB\Operation\ListDatabases;
@@ -294,7 +294,7 @@ public function listDatabaseNames(array $options = []): Iterator
294294
* List databases.
295295
*
296296
* @see ListDatabases::__construct() for supported options
297-
* @return DatabaseInfoIterator
297+
* @return Iterator<int, DatabaseInfo>
298298
* @throws UnexpectedValueException if the command response was malformed
299299
* @throws InvalidArgumentException for parameter/option parsing errors
300300
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)

Diff for: src/Collection.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
use MongoDB\Model\BSONArray;
3434
use MongoDB\Model\BSONDocument;
3535
use MongoDB\Model\IndexInfo;
36-
use MongoDB\Model\IndexInfoIterator;
3736
use MongoDB\Operation\Aggregate;
3837
use MongoDB\Operation\BulkWrite;
3938
use MongoDB\Operation\Count;
@@ -882,7 +881,7 @@ public function insertOne($document, array $options = [])
882881
* Returns information for all indexes for the collection.
883882
*
884883
* @see ListIndexes::__construct() for supported options
885-
* @return IndexInfoIterator
884+
* @return Iterator<int, IndexInfo>
886885
* @throws InvalidArgumentException for parameter/option parsing errors
887886
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
888887
*/

Diff for: src/Database.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
use MongoDB\GridFS\Bucket;
3333
use MongoDB\Model\BSONArray;
3434
use MongoDB\Model\BSONDocument;
35-
use MongoDB\Model\CollectionInfoIterator;
35+
use MongoDB\Model\CollectionInfo;
3636
use MongoDB\Operation\Aggregate;
3737
use MongoDB\Operation\CreateCollection;
3838
use MongoDB\Operation\CreateEncryptedCollection;
@@ -473,7 +473,7 @@ public function listCollectionNames(array $options = []): Iterator
473473
* Returns information for all collections in this database.
474474
*
475475
* @see ListCollections::__construct() for supported options
476-
* @return CollectionInfoIterator
476+
* @return Iterator<int, CollectionInfo>
477477
* @throws InvalidArgumentException for parameter/option parsing errors
478478
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
479479
*/

Diff for: src/Model/CollectionInfoCommandIterator.php

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* @see \MongoDB\Database::listCollections()
3131
* @see https://github.com/mongodb/specifications/blob/master/source/enumerate-collections.rst
3232
* @see https://mongodb.com/docs/manual/reference/command/listCollections/
33+
* @deprecated
3334
* @template-extends IteratorIterator<int, array, Traversable<int, array>>
3435
*/
3536
class CollectionInfoCommandIterator extends IteratorIterator implements CollectionInfoIterator

Diff for: src/Model/CollectionInfoIterator.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* This iterator is used for enumerating collections in a database.
2727
*
2828
* @see \MongoDB\Database::listCollections()
29+
* @deprecated
2930
* @template-extends Iterator<int, CollectionInfo>
3031
*/
3132
interface CollectionInfoIterator extends Iterator

Diff for: src/Model/DatabaseInfoIterator.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* This iterator is used for enumerating databases on a server.
2727
*
2828
* @see \MongoDB\Client::listDatabases()
29+
* @deprecated
2930
* @template-extends Iterator<int, DatabaseInfo>
3031
*/
3132
interface DatabaseInfoIterator extends Iterator

Diff for: src/Model/DatabaseInfoLegacyIterator.php

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* @internal
3232
* @see \MongoDB\Client::listDatabases()
3333
* @see https://mongodb.com/docs/manual/reference/command/listDatabases/
34+
* @deprecated
3435
*/
3536
class DatabaseInfoLegacyIterator implements DatabaseInfoIterator
3637
{

Diff for: src/Model/IndexInfo.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,14 @@ public function getName()
9696
/**
9797
* Return the index namespace (e.g. "db.collection").
9898
*
99+
* @deprecated
100+
*
99101
* @return string
100102
*/
101103
public function getNamespace()
102104
{
105+
@trigger_error('MongoDB 4.4 drops support for the namespace in indexes, the method "IndexInfo::getNamespace()" will be removed in a future release', E_USER_DEPRECATED);
106+
103107
return (string) $this->info['ns'];
104108
}
105109

@@ -131,7 +135,7 @@ public function is2dSphere()
131135
*/
132136
public function isGeoHaystack()
133137
{
134-
trigger_error('MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release', E_USER_DEPRECATED);
138+
@trigger_error('MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release', E_USER_DEPRECATED);
135139

136140
return array_search('geoHaystack', $this->getKey(), true) !== false;
137141
}

Diff for: src/Model/IndexInfoIterator.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* This iterator is used for enumerating indexes in a collection.
2727
*
2828
* @see \MongoDB\Collection::listIndexes()
29+
* @deprecated
2930
* @template-extends Iterator<int, IndexInfo>
3031
*/
3132
interface IndexInfoIterator extends Iterator

Diff for: src/Model/IndexInfoIteratorIterator.php

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* @see https://github.com/mongodb/specifications/blob/master/source/enumerate-indexes.rst
3535
* @see https://mongodb.com/docs/manual/reference/command/listIndexes/
3636
* @see https://mongodb.com/docs/manual/reference/system-collections/
37+
* @deprecated
3738
* @template-extends IteratorIterator<int, array, Traversable<int, array>>
3839
*/
3940
class IndexInfoIteratorIterator extends IteratorIterator implements IndexInfoIterator

Diff for: src/Operation/ListCollections.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717

1818
namespace MongoDB\Operation;
1919

20+
use Iterator;
2021
use MongoDB\Command\ListCollections as ListCollectionsCommand;
2122
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
2223
use MongoDB\Driver\Server;
2324
use MongoDB\Exception\InvalidArgumentException;
25+
use MongoDB\Model\CollectionInfo;
2426
use MongoDB\Model\CollectionInfoCommandIterator;
25-
use MongoDB\Model\CollectionInfoIterator;
2627

2728
/**
2829
* Operation for the listCollections command.
@@ -71,7 +72,7 @@ public function __construct(string $databaseName, array $options = [])
7172
* Execute the operation.
7273
*
7374
* @see Executable::execute()
74-
* @return CollectionInfoIterator
75+
* @return Iterator<int, CollectionInfo>
7576
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
7677
*/
7778
public function execute(Server $server)

Diff for: src/Operation/ListDatabases.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717

1818
namespace MongoDB\Operation;
1919

20+
use Iterator;
2021
use MongoDB\Command\ListDatabases as ListDatabasesCommand;
2122
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
2223
use MongoDB\Driver\Server;
2324
use MongoDB\Exception\InvalidArgumentException;
2425
use MongoDB\Exception\UnexpectedValueException;
25-
use MongoDB\Model\DatabaseInfoIterator;
26+
use MongoDB\Model\DatabaseInfo;
2627
use MongoDB\Model\DatabaseInfoLegacyIterator;
2728

2829
/**
@@ -68,7 +69,7 @@ public function __construct(array $options = [])
6869
* Execute the operation.
6970
*
7071
* @see Executable::execute()
71-
* @return DatabaseInfoIterator
72+
* @return Iterator<int, DatabaseInfo>
7273
* @throws UnexpectedValueException if the command response was malformed
7374
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
7475
*/

Diff for: src/Operation/ListIndexes.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
namespace MongoDB\Operation;
1919

2020
use EmptyIterator;
21+
use Iterator;
2122
use MongoDB\Driver\Command;
2223
use MongoDB\Driver\Exception\CommandException;
2324
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
2425
use MongoDB\Driver\Server;
2526
use MongoDB\Driver\Session;
2627
use MongoDB\Exception\InvalidArgumentException;
2728
use MongoDB\Model\CachingIterator;
28-
use MongoDB\Model\IndexInfoIterator;
29+
use MongoDB\Model\IndexInfo;
2930
use MongoDB\Model\IndexInfoIteratorIterator;
3031

3132
use function is_integer;
@@ -85,7 +86,7 @@ public function __construct(string $databaseName, string $collectionName, array
8586
* Execute the operation.
8687
*
8788
* @see Executable::execute()
88-
* @return IndexInfoIterator
89+
* @return Iterator<int, IndexInfo>
8990
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
9091
*/
9192
public function execute(Server $server)

0 commit comments

Comments
 (0)