Skip to content

Commit 6f2085c

Browse files
committed
PHPLIB-1227 Use void return types for operations without meaningful result document
1 parent f584124 commit 6f2085c

23 files changed

+132
-223
lines changed

psalm-baseline.xml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,6 @@
579579
</MixedMethodCall>
580580
</file>
581581
<file src="src/Operation/CreateCollection.php">
582-
<MixedArgument>
583-
<code><![CDATA[$this->options['typeMap']]]></code>
584-
</MixedArgument>
585582
<MixedAssignment>
586583
<code><![CDATA[$cmd[$option]]]></code>
587584
<code><![CDATA[$options['session']]]></code>
@@ -653,9 +650,6 @@
653650
</MixedMethodCall>
654651
</file>
655652
<file src="src/Operation/DropCollection.php">
656-
<MixedArgument>
657-
<code><![CDATA[$this->options['typeMap']]]></code>
658-
</MixedArgument>
659653
<MixedAssignment>
660654
<code><![CDATA[$cmd['comment']]]></code>
661655
<code><![CDATA[$options['session']]]></code>
@@ -666,9 +660,6 @@
666660
</MixedMethodCall>
667661
</file>
668662
<file src="src/Operation/DropDatabase.php">
669-
<MixedArgument>
670-
<code><![CDATA[$this->options['typeMap']]]></code>
671-
</MixedArgument>
672663
<MixedAssignment>
673664
<code><![CDATA[$cmd['comment']]]></code>
674665
<code><![CDATA[$options['session']]]></code>
@@ -681,9 +672,6 @@
681672
</MixedArgument>
682673
</file>
683674
<file src="src/Operation/DropIndexes.php">
684-
<MixedArgument>
685-
<code><![CDATA[$this->options['typeMap']]]></code>
686-
</MixedArgument>
687675
<MixedAssignment>
688676
<code><![CDATA[$cmd[$option]]]></code>
689677
<code><![CDATA[$options['session']]]></code>
@@ -862,19 +850,13 @@
862850
</MixedMethodCall>
863851
</file>
864852
<file src="src/Operation/ModifyCollection.php">
865-
<MixedArgument>
866-
<code><![CDATA[$this->options['typeMap']]]></code>
867-
</MixedArgument>
868853
<MixedAssignment>
869854
<code><![CDATA[$cmd['comment']]]></code>
870855
<code><![CDATA[$options['session']]]></code>
871856
<code><![CDATA[$options['writeConcern']]]></code>
872857
</MixedAssignment>
873858
</file>
874859
<file src="src/Operation/RenameCollection.php">
875-
<MixedArgument>
876-
<code><![CDATA[$this->options['typeMap']]]></code>
877-
</MixedArgument>
878860
<MixedAssignment>
879861
<code><![CDATA[$cmd[$option]]]></code>
880862
<code><![CDATA[$options['session']]]></code>

src/Client.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,12 @@ public function createClientEncryption(array $options): ClientEncryption
214214
* @see DropDatabase::__construct() for supported options
215215
* @param string $databaseName Database name
216216
* @param array $options Additional options
217-
* @return array|object Command result document
218217
* @throws UnsupportedException if options are unsupported on the selected server
219218
* @throws InvalidArgumentException for parameter/option parsing errors
220219
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
221220
*/
222-
public function dropDatabase(string $databaseName, array $options = []): array|object
221+
public function dropDatabase(string $databaseName, array $options = []): void
223222
{
224-
if (! isset($options['typeMap'])) {
225-
$options['typeMap'] = $this->typeMap;
226-
}
227-
228223
$server = select_server_for_write($this->manager, $options);
229224

230225
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
@@ -233,7 +228,7 @@ public function dropDatabase(string $databaseName, array $options = []): array|o
233228

234229
$operation = new DropDatabase($databaseName, $options);
235230

236-
return $operation->execute($server);
231+
$operation->execute($server);
237232
}
238233

239234
/**

src/Collection.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -508,15 +508,13 @@ public function distinct(string $fieldName, array|object $filter = [], array $op
508508
*
509509
* @see DropCollection::__construct() for supported options
510510
* @param array $options Additional options
511-
* @return array|object Command result document
512511
* @throws UnsupportedException if options are not supported by the selected server
513512
* @throws InvalidArgumentException for parameter/option parsing errors
514513
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
515514
*/
516-
public function drop(array $options = []): array|object
515+
public function drop(array $options = []): void
517516
{
518517
$options = $this->inheritWriteOptions($options);
519-
$options = $this->inheritTypeMap($options);
520518

521519
$server = select_server_for_write($this->manager, $options);
522520

@@ -529,7 +527,7 @@ public function drop(array $options = []): array|object
529527
? new DropEncryptedCollection($this->databaseName, $this->collectionName, $options)
530528
: new DropCollection($this->databaseName, $this->collectionName, $options);
531529

532-
return $operation->execute($server);
530+
$operation->execute($server);
533531
}
534532

535533
/**
@@ -538,12 +536,11 @@ public function drop(array $options = []): array|object
538536
* @see DropIndexes::__construct() for supported options
539537
* @param string|IndexInfo $indexName Index name or model object
540538
* @param array $options Additional options
541-
* @return array|object Command result document
542539
* @throws UnsupportedException if options are not supported by the selected server
543540
* @throws InvalidArgumentException for parameter/option parsing errors
544541
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
545542
*/
546-
public function dropIndex(string|IndexInfo $indexName, array $options = []): array|object
543+
public function dropIndex(string|IndexInfo $indexName, array $options = []): void
547544
{
548545
$indexName = (string) $indexName;
549546

@@ -552,31 +549,28 @@ public function dropIndex(string|IndexInfo $indexName, array $options = []): arr
552549
}
553550

554551
$options = $this->inheritWriteOptions($options);
555-
$options = $this->inheritTypeMap($options);
556552

557553
$operation = new DropIndexes($this->databaseName, $this->collectionName, $indexName, $options);
558554

559-
return $operation->execute(select_server_for_write($this->manager, $options));
555+
$operation->execute(select_server_for_write($this->manager, $options));
560556
}
561557

562558
/**
563559
* Drop all indexes in the collection.
564560
*
565561
* @see DropIndexes::__construct() for supported options
566562
* @param array $options Additional options
567-
* @return array|object Command result document
568563
* @throws UnsupportedException if options are not supported by the selected server
569564
* @throws InvalidArgumentException for parameter/option parsing errors
570565
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
571566
*/
572-
public function dropIndexes(array $options = []): array|object
567+
public function dropIndexes(array $options = []): void
573568
{
574569
$options = $this->inheritWriteOptions($options);
575-
$options = $this->inheritTypeMap($options);
576570

577571
$operation = new DropIndexes($this->databaseName, $this->collectionName, '*', $options);
578572

579-
return $operation->execute(select_server_for_write($this->manager, $options));
573+
$operation->execute(select_server_for_write($this->manager, $options));
580574
}
581575

582576
/**
@@ -958,23 +952,21 @@ public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce,
958952
* @param string $toCollectionName New name of the collection
959953
* @param string|null $toDatabaseName New database name of the collection. Defaults to the original database.
960954
* @param array $options Additional options
961-
* @return array|object Command result document
962955
* @throws UnsupportedException if options are not supported by the selected server
963956
* @throws InvalidArgumentException for parameter/option parsing errors
964957
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
965958
*/
966-
public function rename(string $toCollectionName, ?string $toDatabaseName = null, array $options = []): array|object
959+
public function rename(string $toCollectionName, ?string $toDatabaseName = null, array $options = []): void
967960
{
968961
if (! isset($toDatabaseName)) {
969962
$toDatabaseName = $this->databaseName;
970963
}
971964

972965
$options = $this->inheritWriteOptions($options);
973-
$options = $this->inheritTypeMap($options);
974966

975967
$operation = new RenameCollection($this->databaseName, $this->collectionName, $toDatabaseName, $toCollectionName, $options);
976968

977-
return $operation->execute(select_server_for_write($this->manager, $options));
969+
$operation->execute(select_server_for_write($this->manager, $options));
978970
}
979971

980972
/**

src/Database.php

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,12 @@ public function command(array|object $command, array $options = []): CursorInter
271271
* @see CreateCollection::__construct() for supported options
272272
* @see https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/client-side-encryption.rst#create-collection-helper
273273
* @see https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/manage-collections/
274-
* @return array|object Command result document
275274
* @throws UnsupportedException if options are not supported by the selected server
276275
* @throws InvalidArgumentException for parameter/option parsing errors
277276
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
278277
*/
279-
public function createCollection(string $collectionName, array $options = []): array|object
278+
public function createCollection(string $collectionName, array $options = []): void
280279
{
281-
if (! isset($options['typeMap'])) {
282-
$options['typeMap'] = $this->typeMap;
283-
}
284-
285280
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
286281
$options['writeConcern'] = $this->writeConcern;
287282
}
@@ -296,7 +291,7 @@ public function createCollection(string $collectionName, array $options = []): a
296291

297292
$server = select_server_for_write($this->manager, $options);
298293

299-
return $operation->execute($server);
294+
$operation->execute($server);
300295
}
301296

302297
/**
@@ -314,17 +309,13 @@ public function createCollection(string $collectionName, array $options = []): a
314309
* getPrevious() and getEncryptedFields() methods, respectively.
315310
*
316311
* @see CreateCollection::__construct() for supported options
317-
* @return array A tuple containing the command result document from creating the collection and the modified "encryptedFields" option
312+
* @return array The modified "encryptedFields" option
318313
* @throws InvalidArgumentException for parameter/option parsing errors
319314
* @throws CreateEncryptedCollectionException for any errors creating data keys or creating the collection
320315
* @throws UnsupportedException if Queryable Encryption is not supported by the selected server
321316
*/
322317
public function createEncryptedCollection(string $collectionName, ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey, array $options): array
323318
{
324-
if (! isset($options['typeMap'])) {
325-
$options['typeMap'] = $this->typeMap;
326-
}
327-
328319
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
329320
$options['writeConcern'] = $this->writeConcern;
330321
}
@@ -334,9 +325,11 @@ public function createEncryptedCollection(string $collectionName, ClientEncrypti
334325

335326
try {
336327
$operation->createDataKeys($clientEncryption, $kmsProvider, $masterKey, $encryptedFields);
337-
$result = $operation->execute($server);
328+
$operation->execute($server);
329+
330+
assert(is_array($encryptedFields), '$encryptedFields is set');
338331

339-
return [$result, $encryptedFields];
332+
return $encryptedFields;
340333
} catch (Throwable $e) {
341334
throw new CreateEncryptedCollectionException($e, $encryptedFields ?? []);
342335
}
@@ -347,17 +340,12 @@ public function createEncryptedCollection(string $collectionName, ClientEncrypti
347340
*
348341
* @see DropDatabase::__construct() for supported options
349342
* @param array $options Additional options
350-
* @return array|object Command result document
351343
* @throws UnsupportedException if options are unsupported on the selected server
352344
* @throws InvalidArgumentException for parameter/option parsing errors
353345
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
354346
*/
355-
public function drop(array $options = []): array|object
347+
public function drop(array $options = []): void
356348
{
357-
if (! isset($options['typeMap'])) {
358-
$options['typeMap'] = $this->typeMap;
359-
}
360-
361349
$server = select_server_for_write($this->manager, $options);
362350

363351
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
@@ -366,7 +354,7 @@ public function drop(array $options = []): array|object
366354

367355
$operation = new DropDatabase($this->databaseName, $options);
368356

369-
return $operation->execute($server);
357+
$operation->execute($server);
370358
}
371359

372360
/**
@@ -375,17 +363,12 @@ public function drop(array $options = []): array|object
375363
* @see DropCollection::__construct() for supported options
376364
* @param string $collectionName Collection name
377365
* @param array $options Additional options
378-
* @return array|object Command result document
379366
* @throws UnsupportedException if options are unsupported on the selected server
380367
* @throws InvalidArgumentException for parameter/option parsing errors
381368
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
382369
*/
383-
public function dropCollection(string $collectionName, array $options = []): array|object
370+
public function dropCollection(string $collectionName, array $options = []): void
384371
{
385-
if (! isset($options['typeMap'])) {
386-
$options['typeMap'] = $this->typeMap;
387-
}
388-
389372
$server = select_server_for_write($this->manager, $options);
390373

391374
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
@@ -401,7 +384,7 @@ public function dropCollection(string $collectionName, array $options = []): arr
401384
? new DropEncryptedCollection($this->databaseName, $collectionName, $options)
402385
: new DropCollection($this->databaseName, $collectionName, $options);
403386

404-
return $operation->execute($server);
387+
$operation->execute($server);
405388
}
406389

407390
/**
@@ -497,12 +480,8 @@ public function listCollections(array $options = []): CollectionInfoIterator
497480
* @throws InvalidArgumentException for parameter/option parsing errors
498481
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
499482
*/
500-
public function modifyCollection(string $collectionName, array $collectionOptions, array $options = []): array|object
483+
public function modifyCollection(string $collectionName, array $collectionOptions, array $options = []): void
501484
{
502-
if (! isset($options['typeMap'])) {
503-
$options['typeMap'] = $this->typeMap;
504-
}
505-
506485
$server = select_server_for_write($this->manager, $options);
507486

508487
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
@@ -511,7 +490,7 @@ public function modifyCollection(string $collectionName, array $collectionOption
511490

512491
$operation = new ModifyCollection($this->databaseName, $collectionName, $collectionOptions, $options);
513492

514-
return $operation->execute($server);
493+
$operation->execute($server);
515494
}
516495

517496
/**
@@ -522,21 +501,16 @@ public function modifyCollection(string $collectionName, array $collectionOption
522501
* @param string $toCollectionName New name of the collection
523502
* @param string|null $toDatabaseName New database name of the collection. Defaults to the original database.
524503
* @param array $options Additional options
525-
* @return array|object Command result document
526504
* @throws UnsupportedException if options are unsupported on the selected server
527505
* @throws InvalidArgumentException for parameter/option parsing errors
528506
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
529507
*/
530-
public function renameCollection(string $fromCollectionName, string $toCollectionName, ?string $toDatabaseName = null, array $options = []): array|object
508+
public function renameCollection(string $fromCollectionName, string $toCollectionName, ?string $toDatabaseName = null, array $options = []): void
531509
{
532510
if (! isset($toDatabaseName)) {
533511
$toDatabaseName = $this->databaseName;
534512
}
535513

536-
if (! isset($options['typeMap'])) {
537-
$options['typeMap'] = $this->typeMap;
538-
}
539-
540514
$server = select_server_for_write($this->manager, $options);
541515

542516
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
@@ -545,7 +519,7 @@ public function renameCollection(string $fromCollectionName, string $toCollectio
545519

546520
$operation = new RenameCollection($this->databaseName, $fromCollectionName, $toDatabaseName, $toCollectionName, $options);
547521

548-
return $operation->execute($server);
522+
$operation->execute($server);
549523
}
550524

551525
/**

0 commit comments

Comments
 (0)