From 2109214059ba43b9c3abcd387ec76dbd8f37392c Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 23 Sep 2024 15:46:23 +0200 Subject: [PATCH] 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 --- psalm-baseline.xml | 26 +++++++++++++++++++++ src/Client.php | 4 ++-- src/Collection.php | 3 +-- src/Database.php | 4 ++-- src/Model/CollectionInfoCommandIterator.php | 1 + src/Model/CollectionInfoIterator.php | 1 + src/Model/DatabaseInfoIterator.php | 1 + src/Model/DatabaseInfoLegacyIterator.php | 1 + src/Model/IndexInfo.php | 6 ++++- src/Model/IndexInfoIterator.php | 1 + src/Model/IndexInfoIteratorIterator.php | 1 + src/Operation/ListCollections.php | 5 ++-- src/Operation/ListDatabases.php | 5 ++-- src/Operation/ListIndexes.php | 5 ++-- 14 files changed, 51 insertions(+), 13 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 778bd91a1..78d53e4ef 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -150,6 +150,9 @@ + + + @@ -158,6 +161,9 @@ + + + databases)]]> @@ -166,6 +172,11 @@ databases)]]> + + + + + index]]> @@ -553,7 +564,22 @@ + + + listCollections->execute($server), $this->databaseName)]]> + + + + + listDatabases->execute($server))]]> + + + + + databaseName . '.' . $this->collectionName)]]> + + diff --git a/src/Client.php b/src/Client.php index b5fc18246..60f2f4567 100644 --- a/src/Client.php +++ b/src/Client.php @@ -33,7 +33,7 @@ use MongoDB\Exception\UnsupportedException; use MongoDB\Model\BSONArray; use MongoDB\Model\BSONDocument; -use MongoDB\Model\DatabaseInfoIterator; +use MongoDB\Model\DatabaseInfo; use MongoDB\Operation\DropDatabase; use MongoDB\Operation\ListDatabaseNames; use MongoDB\Operation\ListDatabases; @@ -294,7 +294,7 @@ public function listDatabaseNames(array $options = []): Iterator * List databases. * * @see ListDatabases::__construct() for supported options - * @return DatabaseInfoIterator + * @return Iterator * @throws UnexpectedValueException if the command response was malformed * @throws InvalidArgumentException for parameter/option parsing errors * @throws DriverRuntimeException for other driver errors (e.g. connection errors) diff --git a/src/Collection.php b/src/Collection.php index d09156400..81a0c7969 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -33,7 +33,6 @@ use MongoDB\Model\BSONArray; use MongoDB\Model\BSONDocument; use MongoDB\Model\IndexInfo; -use MongoDB\Model\IndexInfoIterator; use MongoDB\Operation\Aggregate; use MongoDB\Operation\BulkWrite; use MongoDB\Operation\Count; @@ -882,7 +881,7 @@ public function insertOne($document, array $options = []) * Returns information for all indexes for the collection. * * @see ListIndexes::__construct() for supported options - * @return IndexInfoIterator + * @return Iterator * @throws InvalidArgumentException for parameter/option parsing errors * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ diff --git a/src/Database.php b/src/Database.php index 95933df8a..dbaff6709 100644 --- a/src/Database.php +++ b/src/Database.php @@ -32,7 +32,7 @@ use MongoDB\GridFS\Bucket; use MongoDB\Model\BSONArray; use MongoDB\Model\BSONDocument; -use MongoDB\Model\CollectionInfoIterator; +use MongoDB\Model\CollectionInfo; use MongoDB\Operation\Aggregate; use MongoDB\Operation\CreateCollection; use MongoDB\Operation\CreateEncryptedCollection; @@ -473,7 +473,7 @@ public function listCollectionNames(array $options = []): Iterator * Returns information for all collections in this database. * * @see ListCollections::__construct() for supported options - * @return CollectionInfoIterator + * @return Iterator * @throws InvalidArgumentException for parameter/option parsing errors * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ diff --git a/src/Model/CollectionInfoCommandIterator.php b/src/Model/CollectionInfoCommandIterator.php index 9a70b4c1d..72106eabd 100644 --- a/src/Model/CollectionInfoCommandIterator.php +++ b/src/Model/CollectionInfoCommandIterator.php @@ -30,6 +30,7 @@ * @see \MongoDB\Database::listCollections() * @see https://github.com/mongodb/specifications/blob/master/source/enumerate-collections.rst * @see https://mongodb.com/docs/manual/reference/command/listCollections/ + * @deprecated * @template-extends IteratorIterator> */ class CollectionInfoCommandIterator extends IteratorIterator implements CollectionInfoIterator diff --git a/src/Model/CollectionInfoIterator.php b/src/Model/CollectionInfoIterator.php index 1a68cf905..e7ebf4984 100644 --- a/src/Model/CollectionInfoIterator.php +++ b/src/Model/CollectionInfoIterator.php @@ -26,6 +26,7 @@ * This iterator is used for enumerating collections in a database. * * @see \MongoDB\Database::listCollections() + * @deprecated * @template-extends Iterator */ interface CollectionInfoIterator extends Iterator diff --git a/src/Model/DatabaseInfoIterator.php b/src/Model/DatabaseInfoIterator.php index b6052e8e5..72199bd32 100644 --- a/src/Model/DatabaseInfoIterator.php +++ b/src/Model/DatabaseInfoIterator.php @@ -26,6 +26,7 @@ * This iterator is used for enumerating databases on a server. * * @see \MongoDB\Client::listDatabases() + * @deprecated * @template-extends Iterator */ interface DatabaseInfoIterator extends Iterator diff --git a/src/Model/DatabaseInfoLegacyIterator.php b/src/Model/DatabaseInfoLegacyIterator.php index 4bbf46a42..cfbcedb38 100644 --- a/src/Model/DatabaseInfoLegacyIterator.php +++ b/src/Model/DatabaseInfoLegacyIterator.php @@ -31,6 +31,7 @@ * @internal * @see \MongoDB\Client::listDatabases() * @see https://mongodb.com/docs/manual/reference/command/listDatabases/ + * @deprecated */ class DatabaseInfoLegacyIterator implements DatabaseInfoIterator { diff --git a/src/Model/IndexInfo.php b/src/Model/IndexInfo.php index a5df7111c..601a0a75f 100644 --- a/src/Model/IndexInfo.php +++ b/src/Model/IndexInfo.php @@ -96,10 +96,14 @@ public function getName() /** * Return the index namespace (e.g. "db.collection"). * + * @deprecated + * * @return string */ public function getNamespace() { + @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); + return (string) $this->info['ns']; } @@ -131,7 +135,7 @@ public function is2dSphere() */ public function isGeoHaystack() { - trigger_error('MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release', E_USER_DEPRECATED); + @trigger_error('MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release', E_USER_DEPRECATED); return array_search('geoHaystack', $this->getKey(), true) !== false; } diff --git a/src/Model/IndexInfoIterator.php b/src/Model/IndexInfoIterator.php index af6750e00..b7929c20f 100644 --- a/src/Model/IndexInfoIterator.php +++ b/src/Model/IndexInfoIterator.php @@ -26,6 +26,7 @@ * This iterator is used for enumerating indexes in a collection. * * @see \MongoDB\Collection::listIndexes() + * @deprecated * @template-extends Iterator */ interface IndexInfoIterator extends Iterator diff --git a/src/Model/IndexInfoIteratorIterator.php b/src/Model/IndexInfoIteratorIterator.php index 3bbbcd53f..e605f9276 100644 --- a/src/Model/IndexInfoIteratorIterator.php +++ b/src/Model/IndexInfoIteratorIterator.php @@ -34,6 +34,7 @@ * @see https://github.com/mongodb/specifications/blob/master/source/enumerate-indexes.rst * @see https://mongodb.com/docs/manual/reference/command/listIndexes/ * @see https://mongodb.com/docs/manual/reference/system-collections/ + * @deprecated * @template-extends IteratorIterator> */ class IndexInfoIteratorIterator extends IteratorIterator implements IndexInfoIterator diff --git a/src/Operation/ListCollections.php b/src/Operation/ListCollections.php index 36d0bc446..4dfb15a6c 100644 --- a/src/Operation/ListCollections.php +++ b/src/Operation/ListCollections.php @@ -17,12 +17,13 @@ namespace MongoDB\Operation; +use Iterator; use MongoDB\Command\ListCollections as ListCollectionsCommand; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Server; use MongoDB\Exception\InvalidArgumentException; +use MongoDB\Model\CollectionInfo; use MongoDB\Model\CollectionInfoCommandIterator; -use MongoDB\Model\CollectionInfoIterator; /** * Operation for the listCollections command. @@ -71,7 +72,7 @@ public function __construct(string $databaseName, array $options = []) * Execute the operation. * * @see Executable::execute() - * @return CollectionInfoIterator + * @return Iterator * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ public function execute(Server $server) diff --git a/src/Operation/ListDatabases.php b/src/Operation/ListDatabases.php index ee90cca65..00834b248 100644 --- a/src/Operation/ListDatabases.php +++ b/src/Operation/ListDatabases.php @@ -17,12 +17,13 @@ namespace MongoDB\Operation; +use Iterator; use MongoDB\Command\ListDatabases as ListDatabasesCommand; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; use MongoDB\Driver\Server; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\UnexpectedValueException; -use MongoDB\Model\DatabaseInfoIterator; +use MongoDB\Model\DatabaseInfo; use MongoDB\Model\DatabaseInfoLegacyIterator; /** @@ -68,7 +69,7 @@ public function __construct(array $options = []) * Execute the operation. * * @see Executable::execute() - * @return DatabaseInfoIterator + * @return Iterator * @throws UnexpectedValueException if the command response was malformed * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ diff --git a/src/Operation/ListIndexes.php b/src/Operation/ListIndexes.php index 1a5723d70..130a53a16 100644 --- a/src/Operation/ListIndexes.php +++ b/src/Operation/ListIndexes.php @@ -18,6 +18,7 @@ namespace MongoDB\Operation; use EmptyIterator; +use Iterator; use MongoDB\Driver\Command; use MongoDB\Driver\Exception\CommandException; use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; @@ -25,7 +26,7 @@ use MongoDB\Driver\Session; use MongoDB\Exception\InvalidArgumentException; use MongoDB\Model\CachingIterator; -use MongoDB\Model\IndexInfoIterator; +use MongoDB\Model\IndexInfo; use MongoDB\Model\IndexInfoIteratorIterator; use function is_integer; @@ -85,7 +86,7 @@ public function __construct(string $databaseName, string $collectionName, array * Execute the operation. * * @see Executable::execute() - * @return IndexInfoIterator + * @return Iterator * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ public function execute(Server $server)