Skip to content

Commit 3d46eaf

Browse files
authored
Remove deprecated functionality (#1439)
* PHPLIB-360: Make ChangeStream::CURSOR_NOT_FOUND private * PHPLIB-818: Remove Watch::FULL_DOCUMENT_DEFAULT constant * PHPLIB-1512: Remove IndexInfo::isGeoHaystack() method * PHPLIB-1511: Remove deprecated query options * PHPLIB-1517: Remove Executable interface * PHPLIB-1523: Remove iterators for database, collection, and index enumeration * PHPLIB-1513: Remove the mapReduce helper * Address code review
1 parent d8b7877 commit 3d46eaf

File tree

80 files changed

+166
-1979
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+166
-1979
lines changed

UPGRADE-2.0.md

+19
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@ UPGRADE FROM 1.x to 2.0
33

44
* Classes in the namespace `MongoDB\Operation\` are `final`.
55
* All methods in interfaces and classes now define a return type.
6+
* The `MongoDB\ChangeStream::CURSOR_NOT_FOUND` constant is now private.
7+
* The `MongoDB\Operation\Watch::FULL_DOCUMENT_DEFAULT` constant has been
8+
removed.
9+
* The `getNamespace` and `isGeoHaystack` methods have been removed from the
10+
`MongoDB\Model\IndexInfo` class.
11+
* The `maxScan`, `modifiers`, `oplogReplay`, and `snapshot` options for `find`
12+
and `findOne` operations have been removed.
13+
* The `MongoDB\Collection::mapReduce` method has been removed. Use
14+
[aggregation pipeline](https://www.mongodb.com/docs/manual/reference/map-reduce-to-aggregation-pipeline/)
15+
instead.
16+
* The following classes and interfaces have been removed without replacement:
17+
* `MongoDB\MapReduceResult`
18+
* `MongoDB\Model\CollectionInfoCommandIterator`
19+
* `MongoDB\Model\CollectionInfoIterator`
20+
* `MongoDB\Model\DatabaseInfoIterator`
21+
* `MongoDB\Model\DatabaseInfoLegacyIterator`
22+
* `MongoDB\Model\IndexInfoIterator`
23+
* `MongoDB\Model\IndexInfoIteratorIterator`
24+
* `MongoDB\Operation\Executable`
625

726
GridFS
827
------

psalm-baseline.xml

-117
Original file line numberDiff line numberDiff line change
@@ -179,28 +179,14 @@
179179
count($queriesOrArrayOfQueries[0]) > 0]]></code>
180180
</RedundantConditionGivenDocblockType>
181181
</file>
182-
<file src="src/ChangeStream.php">
183-
<DeprecatedConstant>
184-
<code><![CDATA[self::CURSOR_NOT_FOUND]]></code>
185-
</DeprecatedConstant>
186-
</file>
187182
<file src="src/Client.php">
188-
<DeprecatedInterface>
189-
<code><![CDATA[DatabaseInfoIterator]]></code>
190-
</DeprecatedInterface>
191-
<MismatchingDocblockReturnType>
192-
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
193-
</MismatchingDocblockReturnType>
194183
<MixedArgument>
195184
<code><![CDATA[$driverOptions['driver'] ?? []]]></code>
196185
<code><![CDATA[$pipeline]]></code>
197186
</MixedArgument>
198187
<MixedAssignment>
199188
<code><![CDATA[$mergedDriver['platform']]]></code>
200189
</MixedAssignment>
201-
<MixedInferredReturnType>
202-
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
203-
</MixedInferredReturnType>
204190
<MixedPropertyTypeCoercion>
205191
<code><![CDATA[$driverOptions['builderEncoder'] ?? new BuilderEncoder()]]></code>
206192
</MixedPropertyTypeCoercion>
@@ -232,19 +218,10 @@
232218
</MixedArgumentTypeCoercion>
233219
</file>
234220
<file src="src/Collection.php">
235-
<DeprecatedInterface>
236-
<code><![CDATA[IndexInfoIterator]]></code>
237-
</DeprecatedInterface>
238-
<MismatchingDocblockReturnType>
239-
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
240-
</MismatchingDocblockReturnType>
241221
<MixedArgument>
242222
<code><![CDATA[$pipeline]]></code>
243223
<code><![CDATA[$pipeline]]></code>
244224
</MixedArgument>
245-
<MixedInferredReturnType>
246-
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
247-
</MixedInferredReturnType>
248225
<MixedPropertyTypeCoercion>
249226
<code><![CDATA[$options['builderEncoder'] ?? new BuilderEncoder()]]></code>
250227
</MixedPropertyTypeCoercion>
@@ -271,19 +248,10 @@
271248
</MixedAssignment>
272249
</file>
273250
<file src="src/Database.php">
274-
<DeprecatedInterface>
275-
<code><![CDATA[CollectionInfoIterator]]></code>
276-
</DeprecatedInterface>
277-
<MismatchingDocblockReturnType>
278-
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
279-
</MismatchingDocblockReturnType>
280251
<MixedArgument>
281252
<code><![CDATA[$pipeline]]></code>
282253
<code><![CDATA[$pipeline]]></code>
283254
</MixedArgument>
284-
<MixedInferredReturnType>
285-
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
286-
</MixedInferredReturnType>
287255
<MixedPropertyTypeCoercion>
288256
<code><![CDATA[$options['builderEncoder'] ?? new BuilderEncoder()]]></code>
289257
</MixedPropertyTypeCoercion>
@@ -388,34 +356,6 @@
388356
<code><![CDATA[$this->current()]]></code>
389357
</PossiblyNullArgument>
390358
</file>
391-
<file src="src/Model/CollectionInfoCommandIterator.php">
392-
<DeprecatedInterface>
393-
<code><![CDATA[CollectionInfoCommandIterator]]></code>
394-
</DeprecatedInterface>
395-
<MixedArrayAssignment>
396-
<code><![CDATA[$info['idIndex']['ns']]]></code>
397-
</MixedArrayAssignment>
398-
<MixedOperand>
399-
<code><![CDATA[$info['name']]]></code>
400-
</MixedOperand>
401-
</file>
402-
<file src="src/Model/DatabaseInfoLegacyIterator.php">
403-
<DeprecatedInterface>
404-
<code><![CDATA[DatabaseInfoLegacyIterator]]></code>
405-
</DeprecatedInterface>
406-
<MixedArgument>
407-
<code><![CDATA[current($this->databases)]]></code>
408-
</MixedArgument>
409-
<MixedReturnTypeCoercion>
410-
<code><![CDATA[int]]></code>
411-
<code><![CDATA[key($this->databases)]]></code>
412-
</MixedReturnTypeCoercion>
413-
</file>
414-
<file src="src/Model/IndexInfoIteratorIterator.php">
415-
<DeprecatedInterface>
416-
<code><![CDATA[IndexInfoIteratorIterator]]></code>
417-
</DeprecatedInterface>
418-
</file>
419359
<file src="src/Model/IndexInput.php">
420360
<LessSpecificReturnStatement>
421361
<code><![CDATA[(object) $this->index]]></code>
@@ -713,11 +653,7 @@
713653
<code><![CDATA[$this->options['codec']]]></code>
714654
<code><![CDATA[$this->options['typeMap']]]></code>
715655
</MixedArgument>
716-
<MixedArrayAccess>
717-
<code><![CDATA[$options['modifiers'][$modifier[1]]]]></code>
718-
</MixedArrayAccess>
719656
<MixedAssignment>
720-
<code><![CDATA[$options[$modifier[0]]]]></code>
721657
<code><![CDATA[$options[$option]]]></code>
722658
<code><![CDATA[$options['readPreference']]]></code>
723659
<code><![CDATA[$options['session']]]></code>
@@ -802,64 +738,11 @@
802738
<code><![CDATA[$document]]></code>
803739
</PossiblyInvalidArgument>
804740
</file>
805-
<file src="src/Operation/ListCollections.php">
806-
<DeprecatedInterface>
807-
<code><![CDATA[CollectionInfoIterator]]></code>
808-
</DeprecatedInterface>
809-
<MismatchingDocblockReturnType>
810-
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
811-
</MismatchingDocblockReturnType>
812-
<MixedInferredReturnType>
813-
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
814-
</MixedInferredReturnType>
815-
</file>
816-
<file src="src/Operation/ListDatabases.php">
817-
<DeprecatedInterface>
818-
<code><![CDATA[DatabaseInfoIterator]]></code>
819-
</DeprecatedInterface>
820-
<MismatchingDocblockReturnType>
821-
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
822-
</MismatchingDocblockReturnType>
823-
<MixedInferredReturnType>
824-
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
825-
</MixedInferredReturnType>
826-
</file>
827741
<file src="src/Operation/ListIndexes.php">
828-
<DeprecatedClass>
829-
<code><![CDATA[IndexInfoIteratorIterator]]></code>
830-
<code><![CDATA[new IndexInfoIteratorIterator($iterator, $this->databaseName . '.' . $this->collectionName)]]></code>
831-
<code><![CDATA[new IndexInfoIteratorIterator(new EmptyIterator())]]></code>
832-
</DeprecatedClass>
833-
<DeprecatedInterface>
834-
<code><![CDATA[IndexInfoIterator]]></code>
835-
</DeprecatedInterface>
836-
<MismatchingDocblockReturnType>
837-
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
838-
</MismatchingDocblockReturnType>
839-
<MixedAssignment>
840-
<code><![CDATA[$cmd[$option]]]></code>
841-
<code><![CDATA[$options['session']]]></code>
842-
</MixedAssignment>
843-
<MixedInferredReturnType>
844-
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
845-
</MixedInferredReturnType>
846-
</file>
847-
<file src="src/Operation/MapReduce.php">
848-
<MixedArgument>
849-
<code><![CDATA[$result->result->collection]]></code>
850-
<code><![CDATA[$result->result->db]]></code>
851-
<code><![CDATA[$this->options['typeMap']]]></code>
852-
</MixedArgument>
853742
<MixedAssignment>
854743
<code><![CDATA[$cmd[$option]]]></code>
855-
<code><![CDATA[$options['readConcern']]]></code>
856-
<code><![CDATA[$options['readPreference']]]></code>
857744
<code><![CDATA[$options['session']]]></code>
858-
<code><![CDATA[$options['writeConcern']]]></code>
859745
</MixedAssignment>
860-
<MixedMethodCall>
861-
<code><![CDATA[isInTransaction]]></code>
862-
</MixedMethodCall>
863746
</file>
864747
<file src="src/Operation/ModifyCollection.php">
865748
<MixedArgument>

src/ChangeStream.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@
4343
*/
4444
class ChangeStream implements Iterator
4545
{
46-
/**
47-
* @deprecated 1.4
48-
* @todo make this constant private in 2.0 (see: PHPLIB-360)
49-
*/
50-
public const CURSOR_NOT_FOUND = 43;
46+
private const CURSOR_NOT_FOUND = 43;
5147

5248
private const RESUMABLE_ERROR_CODES = [
5349
6, // HostUnreachable

src/Client.php

+2-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;
@@ -290,6 +289,7 @@ public function getWriteConcern(): WriteConcern
290289
* List database names.
291290
*
292291
* @see ListDatabaseNames::__construct() for supported options
292+
* @return Iterator<int, string>
293293
* @throws UnexpectedValueException if the command response was malformed
294294
* @throws InvalidArgumentException for parameter/option parsing errors
295295
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -311,7 +311,7 @@ public function listDatabaseNames(array $options = []): Iterator
311311
* @throws InvalidArgumentException for parameter/option parsing errors
312312
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
313313
*/
314-
public function listDatabases(array $options = []): DatabaseInfoIterator
314+
public function listDatabases(array $options = []): Iterator
315315
{
316316
$operation = new ListDatabases($options);
317317
$server = select_server($this->manager, $options);

src/Collection.php

+1-50
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Countable;
2121
use Iterator;
2222
use MongoDB\BSON\Document;
23-
use MongoDB\BSON\JavascriptInterface;
2423
use MongoDB\BSON\PackedArray;
2524
use MongoDB\Builder\BuilderEncoder;
2625
use MongoDB\Builder\Pipeline;
@@ -38,7 +37,6 @@
3837
use MongoDB\Model\BSONArray;
3938
use MongoDB\Model\BSONDocument;
4039
use MongoDB\Model\IndexInfo;
41-
use MongoDB\Model\IndexInfoIterator;
4240
use MongoDB\Operation\Aggregate;
4341
use MongoDB\Operation\BulkWrite;
4442
use MongoDB\Operation\Count;
@@ -64,7 +62,6 @@
6462
use MongoDB\Operation\InsertOne;
6563
use MongoDB\Operation\ListIndexes;
6664
use MongoDB\Operation\ListSearchIndexes;
67-
use MongoDB\Operation\MapReduce;
6865
use MongoDB\Operation\RenameCollection;
6966
use MongoDB\Operation\ReplaceOne;
7067
use MongoDB\Operation\UpdateMany;
@@ -78,11 +75,7 @@
7875
use function array_key_exists;
7976
use function current;
8077
use function is_array;
81-
use function sprintf;
8278
use function strlen;
83-
use function trigger_error;
84-
85-
use const E_USER_DEPRECATED;
8679

8780
class Collection
8881
{
@@ -884,7 +877,7 @@ public function insertOne(array|object $document, array $options = []): InsertOn
884877
* @throws InvalidArgumentException for parameter/option parsing errors
885878
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
886879
*/
887-
public function listIndexes(array $options = []): IndexInfoIterator
880+
public function listIndexes(array $options = []): Iterator
888881
{
889882
$operation = new ListIndexes($this->databaseName, $this->collectionName, $options);
890883

@@ -909,48 +902,6 @@ public function listSearchIndexes(array $options = []): Iterator
909902
return $operation->execute($server);
910903
}
911904

912-
/**
913-
* Executes a map-reduce aggregation on the collection.
914-
*
915-
* @see MapReduce::__construct() for supported options
916-
* @see https://mongodb.com/docs/manual/reference/command/mapReduce/
917-
* @param JavascriptInterface $map Map function
918-
* @param JavascriptInterface $reduce Reduce function
919-
* @param string|array|object $out Output specification
920-
* @param array $options Command options
921-
* @throws UnsupportedException if options are not supported by the selected server
922-
* @throws InvalidArgumentException for parameter/option parsing errors
923-
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
924-
* @throws UnexpectedValueException if the command response was malformed
925-
*/
926-
public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, string|array|object $out, array $options = []): MapReduceResult
927-
{
928-
@trigger_error(sprintf('The %s method is deprecated and will be removed in a version 2.0.', __METHOD__), E_USER_DEPRECATED);
929-
930-
$hasOutputCollection = ! is_mapreduce_output_inline($out);
931-
932-
// Check if the out option is inline because we will want to coerce a primary read preference if not
933-
if ($hasOutputCollection) {
934-
$options['readPreference'] = new ReadPreference(ReadPreference::PRIMARY);
935-
} else {
936-
$options = $this->inheritReadPreference($options);
937-
}
938-
939-
/* A "majority" read concern is not compatible with inline output, so
940-
* avoid providing the Collection's read concern if it would conflict.
941-
*/
942-
if (! $hasOutputCollection || $this->readConcern->getLevel() !== ReadConcern::MAJORITY) {
943-
$options = $this->inheritReadConcern($options);
944-
}
945-
946-
$options = $this->inheritWriteOptions($options);
947-
$options = $this->inheritTypeMap($options);
948-
949-
$operation = new MapReduce($this->databaseName, $this->collectionName, $map, $reduce, $out, $options);
950-
951-
return $operation->execute(select_server_for_write($this->manager, $options));
952-
}
953-
954905
/**
955906
* Renames the collection.
956907
*

src/Command/ListCollections.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -18,13 +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;
27-
use MongoDB\Operation\Executable;
2826

2927
use function is_bool;
3028
use function is_integer;
@@ -36,7 +34,7 @@
3634
* @internal
3735
* @see https://mongodb.com/docs/manual/reference/command/listCollections/
3836
*/
39-
final class ListCollections implements Executable
37+
final class ListCollections
4038
{
4139
/**
4240
* Constructs a listCollections command.
@@ -93,17 +91,16 @@ public function __construct(private string $databaseName, private array $options
9391
/**
9492
* Execute the operation.
9593
*
96-
* @return CachingIterator<int, array>
97-
* @see Executable::execute()
94+
* @return CursorInterface<array>
9895
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
9996
*/
100-
public function execute(Server $server): CachingIterator
97+
public function execute(Server $server): CursorInterface
10198
{
102-
/** @var Cursor<array> $cursor */
99+
/** @var CursorInterface<array> $cursor */
103100
$cursor = $server->executeReadCommand($this->databaseName, $this->createCommand(), $this->createOptions());
104101
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
105102

106-
return new CachingIterator($cursor);
103+
return $cursor;
107104
}
108105

109106
/**

0 commit comments

Comments
 (0)