Skip to content

Commit

Permalink
PHPLIB-1523: Remove iterators for database, collection, and index enu…
Browse files Browse the repository at this point in the history
…meration
  • Loading branch information
alcaeus committed Sep 26, 2024
1 parent f4cc84e commit f95d1cb
Show file tree
Hide file tree
Showing 26 changed files with 93 additions and 529 deletions.
12 changes: 10 additions & 2 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ UPGRADE FROM 1.x to 2.0
* The `MongoDB\ChangeStream::CURSOR_NOT_FOUND` constant is now private.
* The `MongoDB\Operation\Watch::FULL_DOCUMENT_DEFAULT` constant has been
removed.
* The `MongoDB\Model\IndexInfo::isGeoHaystack` method has been removed.
* The `getNamespace` and `isGeoHaystack` methods hav been removed from the
`MongoDB\Model\IndexInfo` class.
* The `maxScan`, `modifiers`, `oplogReplay`, and `snapshot` options for `find`
and `findOne` operations have been removed.
* The `MongoDB\Operation\Executable` interface has been removed.
* The following classes and interfaces have been removed without replacement:
* `MongoDB\Operation\Executable`
* `MongoDB\Model\CollectionInfoCommandIterator`
* `MongoDB\Model\CollectionInfoIterator`
* `MongoDB\Model\DatabaseInfoIterator`
* `MongoDB\Model\DatabaseInfoLegacyIterator`
* `MongoDB\Model\IndexInfoIterator`
* `MongoDB\Model\IndexInfoIteratorIterator`

GridFS
------
Expand Down
91 changes: 0 additions & 91 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,13 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Client.php">
<DeprecatedInterface>
<code><![CDATA[DatabaseInfoIterator]]></code>
</DeprecatedInterface>
<MismatchingDocblockReturnType>
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
</MismatchingDocblockReturnType>
<MixedArgument>
<code><![CDATA[$driverOptions['driver'] ?? []]]></code>
<code><![CDATA[$pipeline]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$mergedDriver['platform']]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
</MixedInferredReturnType>
<MixedPropertyTypeCoercion>
<code><![CDATA[$driverOptions['builderEncoder'] ?? new BuilderEncoder()]]></code>
</MixedPropertyTypeCoercion>
Expand Down Expand Up @@ -227,19 +218,10 @@
</MixedArgumentTypeCoercion>
</file>
<file src="src/Collection.php">
<DeprecatedInterface>
<code><![CDATA[IndexInfoIterator]]></code>
</DeprecatedInterface>
<MismatchingDocblockReturnType>
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
</MismatchingDocblockReturnType>
<MixedArgument>
<code><![CDATA[$pipeline]]></code>
<code><![CDATA[$pipeline]]></code>
</MixedArgument>
<MixedInferredReturnType>
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
</MixedInferredReturnType>
<MixedPropertyTypeCoercion>
<code><![CDATA[$options['builderEncoder'] ?? new BuilderEncoder()]]></code>
</MixedPropertyTypeCoercion>
Expand All @@ -266,19 +248,10 @@
</MixedAssignment>
</file>
<file src="src/Database.php">
<DeprecatedInterface>
<code><![CDATA[CollectionInfoIterator]]></code>
</DeprecatedInterface>
<MismatchingDocblockReturnType>
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
</MismatchingDocblockReturnType>
<MixedArgument>
<code><![CDATA[$pipeline]]></code>
<code><![CDATA[$pipeline]]></code>
</MixedArgument>
<MixedInferredReturnType>
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
</MixedInferredReturnType>
<MixedPropertyTypeCoercion>
<code><![CDATA[$options['builderEncoder'] ?? new BuilderEncoder()]]></code>
</MixedPropertyTypeCoercion>
Expand Down Expand Up @@ -383,34 +356,6 @@
<code><![CDATA[$this->current()]]></code>
</PossiblyNullArgument>
</file>
<file src="src/Model/CollectionInfoCommandIterator.php">
<DeprecatedInterface>
<code><![CDATA[CollectionInfoCommandIterator]]></code>
</DeprecatedInterface>
<MixedArrayAssignment>
<code><![CDATA[$info['idIndex']['ns']]]></code>
</MixedArrayAssignment>
<MixedOperand>
<code><![CDATA[$info['name']]]></code>
</MixedOperand>
</file>
<file src="src/Model/DatabaseInfoLegacyIterator.php">
<DeprecatedInterface>
<code><![CDATA[DatabaseInfoLegacyIterator]]></code>
</DeprecatedInterface>
<MixedArgument>
<code><![CDATA[current($this->databases)]]></code>
</MixedArgument>
<MixedReturnTypeCoercion>
<code><![CDATA[int]]></code>
<code><![CDATA[key($this->databases)]]></code>
</MixedReturnTypeCoercion>
</file>
<file src="src/Model/IndexInfoIteratorIterator.php">
<DeprecatedInterface>
<code><![CDATA[IndexInfoIteratorIterator]]></code>
</DeprecatedInterface>
</file>
<file src="src/Model/IndexInput.php">
<LessSpecificReturnStatement>
<code><![CDATA[(object) $this->index]]></code>
Expand Down Expand Up @@ -793,47 +738,11 @@
<code><![CDATA[$document]]></code>
</PossiblyInvalidArgument>
</file>
<file src="src/Operation/ListCollections.php">
<DeprecatedInterface>
<code><![CDATA[CollectionInfoIterator]]></code>
</DeprecatedInterface>
<MismatchingDocblockReturnType>
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
</MismatchingDocblockReturnType>
<MixedInferredReturnType>
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
</MixedInferredReturnType>
</file>
<file src="src/Operation/ListDatabases.php">
<DeprecatedInterface>
<code><![CDATA[DatabaseInfoIterator]]></code>
</DeprecatedInterface>
<MismatchingDocblockReturnType>
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
</MismatchingDocblockReturnType>
<MixedInferredReturnType>
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
</MixedInferredReturnType>
</file>
<file src="src/Operation/ListIndexes.php">
<DeprecatedClass>
<code><![CDATA[IndexInfoIteratorIterator]]></code>
<code><![CDATA[new IndexInfoIteratorIterator($iterator, $this->databaseName . '.' . $this->collectionName)]]></code>
<code><![CDATA[new IndexInfoIteratorIterator(new EmptyIterator())]]></code>
</DeprecatedClass>
<DeprecatedInterface>
<code><![CDATA[IndexInfoIterator]]></code>
</DeprecatedInterface>
<MismatchingDocblockReturnType>
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
</MismatchingDocblockReturnType>
<MixedAssignment>
<code><![CDATA[$cmd[$option]]]></code>
<code><![CDATA[$options['session']]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
</MixedInferredReturnType>
</file>
<file src="src/Operation/MapReduce.php">
<MixedArgument>
Expand Down
3 changes: 1 addition & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument;
use MongoDB\Model\DatabaseInfo;
use MongoDB\Model\DatabaseInfoIterator;
use MongoDB\Operation\DropDatabase;
use MongoDB\Operation\ListDatabaseNames;
use MongoDB\Operation\ListDatabases;
Expand Down Expand Up @@ -305,7 +304,7 @@ public function listDatabaseNames(array $options = []): Iterator
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function listDatabases(array $options = []): DatabaseInfoIterator
public function listDatabases(array $options = []): Iterator
{
$operation = new ListDatabases($options);
$server = select_server($this->manager, $options);
Expand Down
3 changes: 1 addition & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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;
Expand Down Expand Up @@ -884,7 +883,7 @@ public function insertOne(array|object $document, array $options = []): InsertOn
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function listIndexes(array $options = []): IndexInfoIterator
public function listIndexes(array $options = []): Iterator
{
$operation = new ListIndexes($this->databaseName, $this->collectionName, $options);

Expand Down
11 changes: 5 additions & 6 deletions src/Command/ListCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
namespace MongoDB\Command;

use MongoDB\Driver\Command;
use MongoDB\Driver\Cursor;
use MongoDB\Driver\CursorInterface;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Driver\Session;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\CachingIterator;

use function is_bool;
use function is_integer;
Expand Down Expand Up @@ -92,16 +91,16 @@ public function __construct(private string $databaseName, private array $options
/**
* Execute the operation.
*
* @return CachingIterator<int, array>
* @return CursorInterface<array>
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function execute(Server $server): CachingIterator
public function execute(Server $server): CursorInterface
{
/** @var Cursor<array> $cursor */
/** @var CursorInterface<array> $cursor */
$cursor = $server->executeReadCommand($this->databaseName, $this->createCommand(), $this->createOptions());
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);

return new CachingIterator($cursor);
return $cursor;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Command/ListDatabases.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function execute(Server $server): array
{
$cursor = $server->executeReadCommand('admin', $this->createCommand(), $this->createOptions());
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);

$result = current($cursor->toArray());

if (! isset($result['databases']) || ! is_array($result['databases'])) {
Expand Down
3 changes: 1 addition & 2 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument;
use MongoDB\Model\CollectionInfo;
use MongoDB\Model\CollectionInfoIterator;
use MongoDB\Operation\Aggregate;
use MongoDB\Operation\CreateCollection;
use MongoDB\Operation\CreateEncryptedCollection;
Expand Down Expand Up @@ -479,7 +478,7 @@ public function listCollectionNames(array $options = []): Iterator
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function listCollections(array $options = []): CollectionInfoIterator
public function listCollections(array $options = []): Iterator
{
$operation = new ListCollections($this->databaseName, $options);
$server = select_server($this->manager, $options);
Expand Down
2 changes: 1 addition & 1 deletion src/Model/CallbackIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @internal
*
* @template TKey
* @template TKey of array-key
* @template TValue
* @template TCallbackValue
* @template-implements Iterator<TKey, TCallbackValue>
Expand Down
60 changes: 0 additions & 60 deletions src/Model/CollectionInfoCommandIterator.php

This file was deleted.

37 changes: 0 additions & 37 deletions src/Model/CollectionInfoIterator.php

This file was deleted.

Loading

0 comments on commit f95d1cb

Please sign in to comment.