Skip to content

Commit 1837a75

Browse files
authored
Deprecate functionality to be removed (#1441)
* Remove duplicate deprecation notices for query options * PHPLIB-1533: Mark Collection::mapReduce as deprecated * Update deprecation notice language
1 parent 355779b commit 1837a75

File tree

7 files changed

+16
-35
lines changed

7 files changed

+16
-35
lines changed

src/Collection.php

+6
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@
7777
use function array_key_exists;
7878
use function current;
7979
use function is_array;
80+
use function sprintf;
8081
use function strlen;
82+
use function trigger_error;
83+
84+
use const E_USER_DEPRECATED;
8185

8286
class Collection
8387
{
@@ -952,6 +956,8 @@ public function listSearchIndexes(array $options = []): Iterator
952956
*/
953957
public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce, string|array|object $out, array $options = [])
954958
{
959+
@trigger_error(sprintf('The %s method is deprecated and will be removed in a version 2.0.', __METHOD__), E_USER_DEPRECATED);
960+
955961
$hasOutputCollection = ! is_mapreduce_output_inline($out);
956962

957963
// Check if the out option is inline because we will want to coerce a primary read preference if not

src/Model/IndexInfo.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function getName()
9999
*/
100100
public function getNamespace()
101101
{
102-
@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);
102+
@trigger_error('MongoDB 4.4 drops support for the namespace in indexes, the method "IndexInfo::getNamespace()" will be removed in version 2.0', E_USER_DEPRECATED);
103103

104104
return (string) $this->info['ns'];
105105
}
@@ -132,7 +132,7 @@ public function is2dSphere()
132132
*/
133133
public function isGeoHaystack()
134134
{
135-
@trigger_error('MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release', E_USER_DEPRECATED);
135+
@trigger_error('MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in version 2.0', E_USER_DEPRECATED);
136136

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

src/Operation/CreateCollection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public function __construct(private string $databaseName, private string $collec
230230
}
231231

232232
if (isset($this->options['autoIndexId'])) {
233-
trigger_error('The "autoIndexId" option is deprecated and will be removed in a future release', E_USER_DEPRECATED);
233+
trigger_error('The "autoIndexId" option is deprecated and will be removed in version 2.0', E_USER_DEPRECATED);
234234
}
235235

236236
if (isset($this->options['pipeline']) && ! is_pipeline($this->options['pipeline'], true /* allowEmpty */)) {

src/Operation/Find.php

-11
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
use function is_string;
3838
use function MongoDB\document_to_array;
3939
use function MongoDB\is_document;
40-
use function trigger_error;
41-
42-
use const E_USER_DEPRECATED;
4340

4441
/**
4542
* Operation for the find command.
@@ -285,14 +282,6 @@ public function __construct(private string $databaseName, private string $collec
285282
unset($this->options['readConcern']);
286283
}
287284

288-
if (isset($this->options['snapshot'])) {
289-
trigger_error('The "snapshot" option is deprecated and will be removed in a future release', E_USER_DEPRECATED);
290-
}
291-
292-
if (isset($this->options['maxScan'])) {
293-
trigger_error('The "maxScan" option is deprecated and will be removed in a future release', E_USER_DEPRECATED);
294-
}
295-
296285
if (isset($this->options['codec']) && isset($this->options['typeMap'])) {
297286
throw InvalidArgumentException::cannotCombineCodecAndTypeMap();
298287
}

tests/Collection/CollectionFunctionalTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,9 @@ public function testMapReduce(): void
433433
$reduce = new Javascript('function(key, values) { return Array.sum(values); }');
434434
$out = ['inline' => 1];
435435

436-
$result = $this->collection->mapReduce($map, $reduce, $out);
436+
$result = $this->assertDeprecated(
437+
fn () => $this->collection->mapReduce($map, $reduce, $out),
438+
);
437439

438440
$this->assertInstanceOf(MapReduceResult::class, $result);
439441
$expected = [

tests/Operation/FindTest.php

-18
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,6 @@ public static function provideInvalidConstructorOptions()
5555
]);
5656
}
5757

58-
public function testSnapshotOptionIsDeprecated(): void
59-
{
60-
$this->assertDeprecated(function (): void {
61-
new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['snapshot' => true]);
62-
});
63-
64-
$this->assertDeprecated(function (): void {
65-
new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['snapshot' => false]);
66-
});
67-
}
68-
69-
public function testMaxScanOptionIsDeprecated(): void
70-
{
71-
$this->assertDeprecated(function (): void {
72-
new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['maxScan' => 1]);
73-
});
74-
}
75-
7658
/** @dataProvider provideInvalidConstructorCursorTypeOptions */
7759
public function testConstructorCursorTypeOption($cursorType): void
7860
{

tests/TestCase.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ final public static function provideInvalidStringValues(): array
161161
return self::wrapValuesForDataProvider(self::getInvalidStringValues());
162162
}
163163

164-
protected function assertDeprecated(callable $execution): void
164+
protected function assertDeprecated(callable $execution)
165165
{
166166
$errors = [];
167167

@@ -170,12 +170,14 @@ protected function assertDeprecated(callable $execution): void
170170
}, E_USER_DEPRECATED | E_DEPRECATED);
171171

172172
try {
173-
call_user_func($execution);
173+
$result = call_user_func($execution);
174174
} finally {
175175
restore_error_handler();
176176
}
177177

178178
$this->assertCount(1, $errors);
179+
180+
return $result;
179181
}
180182

181183
protected static function createOptionDataProvider(array $options): array

0 commit comments

Comments
 (0)