diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 42a382a7b..639bfcdf5 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -105,8 +105,6 @@
-
-
@@ -114,7 +112,6 @@
-
@@ -128,13 +125,10 @@
-
-
-
@@ -144,7 +138,6 @@
-
@@ -162,12 +155,9 @@
-
-
-
-
- src
-
+
+
+
src
diff --git a/src/BulkWriteResult.php b/src/BulkWriteResult.php
index 1a1f3ed41..731c49294 100644
--- a/src/BulkWriteResult.php
+++ b/src/BulkWriteResult.php
@@ -28,16 +28,12 @@ class BulkWriteResult
/** @var WriteResult */
private $writeResult;
- /** @var mixed[] */
+ /** @var array */
private $insertedIds;
/** @var boolean */
private $isAcknowledged;
- /**
- * @param WriteResult $writeResult
- * @param mixed[] $insertedIds
- */
public function __construct(WriteResult $writeResult, array $insertedIds)
{
$this->writeResult = $writeResult;
@@ -90,7 +86,7 @@ public function getInsertedCount()
* field value. Any driver-generated ID will be a MongoDB\BSON\ObjectId
* instance.
*
- * @return mixed[]
+ * @return array
*/
public function getInsertedIds()
{
@@ -165,7 +161,7 @@ public function getUpsertedCount()
* This method should only be called if the write was acknowledged.
*
* @see BulkWriteResult::isAcknowledged()
- * @return mixed[]
+ * @return array
* @throws BadMethodCallException is the write result is unacknowledged
*/
public function getUpsertedIds()
diff --git a/src/ChangeStream.php b/src/ChangeStream.php
index 551024198..cfd10e6f4 100644
--- a/src/ChangeStream.php
+++ b/src/ChangeStream.php
@@ -90,8 +90,6 @@ class ChangeStream implements Iterator
/**
* @internal
- * @param ChangeStreamIterator $iterator
- * @param callable $resumeCallable
*/
public function __construct(ChangeStreamIterator $iterator, callable $resumeCallable)
{
@@ -194,10 +192,8 @@ public function valid()
* Determines if an exception is a resumable error.
*
* @see https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.rst#resumable-error
- * @param RuntimeException $exception
- * @return boolean
*/
- private function isResumableError(RuntimeException $exception)
+ private function isResumableError(RuntimeException $exception): bool
{
if ($exception instanceof ConnectionException) {
return true;
@@ -224,7 +220,7 @@ private function isResumableError(RuntimeException $exception)
* @param boolean $incrementKey Increment $key if there is a current result
* @throws ResumeTokenException
*/
- private function onIteration($incrementKey)
+ private function onIteration(bool $incrementKey): void
{
/* If the cursorId is 0, the server has invalidated the cursor and we
* will never perform another getMore nor need to resume since any
@@ -251,10 +247,8 @@ private function onIteration($incrementKey)
/**
* Recreates the ChangeStreamIterator after a resumable server error.
- *
- * @return void
*/
- private function resume()
+ private function resume(): void
{
$this->iterator = call_user_func($this->resumeCallable, $this->getResumeToken(), $this->hasAdvanced);
$this->iterator->rewind();
@@ -265,10 +259,9 @@ private function resume()
/**
* Either resumes after a resumable error or re-throws the exception.
*
- * @param RuntimeException $exception
* @throws RuntimeException
*/
- private function resumeOrThrow(RuntimeException $exception)
+ private function resumeOrThrow(RuntimeException $exception): void
{
if ($this->isResumableError($exception)) {
$this->resume();
diff --git a/src/Client.php b/src/Client.php
index 181ac733c..7f15ba12b 100644
--- a/src/Client.php
+++ b/src/Client.php
@@ -98,7 +98,7 @@ class Client
* @throws DriverInvalidArgumentException for parameter/option parsing errors in the driver
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function __construct($uri = 'mongodb://127.0.0.1/', array $uriOptions = [], array $driverOptions = [])
+ public function __construct(string $uri = 'mongodb://127.0.0.1/', array $uriOptions = [], array $driverOptions = [])
{
$driverOptions += ['typeMap' => self::$defaultTypeMap];
@@ -116,7 +116,7 @@ public function __construct($uri = 'mongodb://127.0.0.1/', array $uriOptions = [
$driverOptions['driver'] = $this->mergeDriverInfo($driverOptions['driver'] ?? []);
- $this->uri = (string) $uri;
+ $this->uri = $uri;
$this->typeMap = $driverOptions['typeMap'] ?? null;
unset($driverOptions['typeMap']);
@@ -155,7 +155,7 @@ public function __debugInfo()
* @param string $databaseName Name of the database to select
* @return Database
*/
- public function __get($databaseName)
+ public function __get(string $databaseName)
{
return $this->selectDatabase($databaseName);
}
@@ -201,7 +201,7 @@ public function createClientEncryption(array $options)
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function dropDatabase($databaseName, array $options = [])
+ public function dropDatabase(string $databaseName, array $options = [])
{
if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap;
@@ -290,7 +290,6 @@ public function listDatabaseNames(array $options = []): Iterator
* List databases.
*
* @see ListDatabases::__construct() for supported options
- * @param array $options
* @return DatabaseInfoIterator
* @throws UnexpectedValueException if the command response was malformed
* @throws InvalidArgumentException for parameter/option parsing errors
@@ -314,7 +313,7 @@ public function listDatabases(array $options = [])
* @return Collection
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function selectCollection($databaseName, $collectionName, array $options = [])
+ public function selectCollection(string $databaseName, string $collectionName, array $options = [])
{
$options += ['typeMap' => $this->typeMap];
@@ -330,7 +329,7 @@ public function selectCollection($databaseName, $collectionName, array $options
* @return Database
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function selectDatabase($databaseName, array $options = [])
+ public function selectDatabase(string $databaseName, array $options = [])
{
$options += ['typeMap' => $this->typeMap];
diff --git a/src/Collection.php b/src/Collection.php
index bc864256c..517cd307a 100644
--- a/src/Collection.php
+++ b/src/Collection.php
@@ -126,13 +126,13 @@ class Collection
* @param array $options Collection options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct(Manager $manager, $databaseName, $collectionName, array $options = [])
+ public function __construct(Manager $manager, string $databaseName, string $collectionName, array $options = [])
{
- if (strlen((string) $databaseName) < 1) {
+ if (strlen($databaseName) < 1) {
throw new InvalidArgumentException('$databaseName is invalid: ' . $databaseName);
}
- if (strlen((string) $collectionName) < 1) {
+ if (strlen($collectionName) < 1) {
throw new InvalidArgumentException('$collectionName is invalid: ' . $collectionName);
}
@@ -153,8 +153,8 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
}
$this->manager = $manager;
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->readConcern = $options['readConcern'] ?? $this->manager->getReadConcern();
$this->readPreference = $options['readPreference'] ?? $this->manager->getReadPreference();
$this->typeMap = $options['typeMap'] ?? self::$defaultTypeMap;
@@ -446,13 +446,13 @@ public function deleteOne($filter, array $options = [])
* @param string $fieldName Field for which to return distinct values
* @param array|object $filter Query by which to filter documents
* @param array $options Command options
- * @return mixed[]
+ * @return array
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function distinct($fieldName, $filter = [], array $options = [])
+ public function distinct(string $fieldName, $filter = [], array $options = [])
{
if (! isset($options['readPreference']) && ! is_in_transaction($options)) {
$options['readPreference'] = $this->readPreference;
@@ -938,7 +938,6 @@ public function insertOne($document, array $options = [])
* Returns information for all indexes for the collection.
*
* @see ListIndexes::__construct() for supported options
- * @param array $options
* @return IndexInfoIterator
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -1007,9 +1006,9 @@ public function mapReduce(JavascriptInterface $map, JavascriptInterface $reduce,
* Renames the collection.
*
* @see RenameCollection::__construct() for supported options
- * @param string $toCollectionName New name of the collection
- * @param ?string $toDatabaseName New database name of the collection. Defaults to the original database.
- * @param array $options Additional options
+ * @param string $toCollectionName New name of the collection
+ * @param string|null $toDatabaseName New database name of the collection. Defaults to the original database.
+ * @param array $options Additional options
* @return array|object Command result document
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
diff --git a/src/Command/ListCollections.php b/src/Command/ListCollections.php
index 8a017558f..a970aeb07 100644
--- a/src/Command/ListCollections.php
+++ b/src/Command/ListCollections.php
@@ -73,7 +73,7 @@ class ListCollections implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, array $options = [])
+ public function __construct(string $databaseName, array $options = [])
{
if (isset($options['authorizedCollections']) && ! is_bool($options['authorizedCollections'])) {
throw InvalidArgumentException::invalidType('"authorizedCollections" option', $options['authorizedCollections'], 'boolean');
@@ -95,7 +95,7 @@ public function __construct($databaseName, array $options = [])
throw InvalidArgumentException::invalidType('"session" option', $options['session'], Session::class);
}
- $this->databaseName = (string) $databaseName;
+ $this->databaseName = $databaseName;
$this->options = $options;
}
@@ -103,11 +103,9 @@ public function __construct($databaseName, array $options = [])
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
- * @return CachingIterator
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function execute(Server $server)
+ public function execute(Server $server): CachingIterator
{
$cursor = $server->executeReadCommand($this->databaseName, $this->createCommand(), $this->createOptions());
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
@@ -117,10 +115,8 @@ public function execute(Server $server)
/**
* Create the listCollections command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = ['listCollections' => 1];
@@ -144,9 +140,8 @@ private function createCommand()
* the command be executed on the primary.
*
* @see https://php.net/manual/en/mongodb-driver-server.executecommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
diff --git a/src/Command/ListDatabases.php b/src/Command/ListDatabases.php
index 3d75fa96c..4dabc6ed2 100644
--- a/src/Command/ListDatabases.php
+++ b/src/Command/ListDatabases.php
@@ -99,12 +99,11 @@ public function __construct(array $options = [])
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return array An array of database info structures
* @throws UnexpectedValueException if the command response was malformed
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function execute(Server $server)
+ public function execute(Server $server): array
{
$cursor = $server->executeReadCommand('admin', $this->createCommand(), $this->createOptions());
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
@@ -119,10 +118,8 @@ public function execute(Server $server)
/**
* Create the listDatabases command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = ['listDatabases' => 1];
@@ -146,9 +143,8 @@ private function createCommand()
* the command be executed on the primary.
*
* @see https://php.net/manual/en/mongodb-driver-server.executecommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
diff --git a/src/Database.php b/src/Database.php
index 4d8a74463..9bb2484dd 100644
--- a/src/Database.php
+++ b/src/Database.php
@@ -104,9 +104,9 @@ class Database
* @param array $options Database options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct(Manager $manager, $databaseName, array $options = [])
+ public function __construct(Manager $manager, string $databaseName, array $options = [])
{
- if (strlen((string) $databaseName) < 1) {
+ if (strlen($databaseName) < 1) {
throw new InvalidArgumentException('$databaseName is invalid: ' . $databaseName);
}
@@ -127,7 +127,7 @@ public function __construct(Manager $manager, $databaseName, array $options = []
}
$this->manager = $manager;
- $this->databaseName = (string) $databaseName;
+ $this->databaseName = $databaseName;
$this->readConcern = $options['readConcern'] ?? $this->manager->getReadConcern();
$this->readPreference = $options['readPreference'] ?? $this->manager->getReadPreference();
$this->typeMap = $options['typeMap'] ?? self::$defaultTypeMap;
@@ -164,7 +164,7 @@ public function __debugInfo()
* @param string $collectionName Name of the collection to select
* @return Collection
*/
- public function __get($collectionName)
+ public function __get(string $collectionName)
{
return $this->selectCollection($collectionName);
}
@@ -257,14 +257,12 @@ public function command($command, array $options = [])
* Create a new collection explicitly.
*
* @see CreateCollection::__construct() for supported options
- * @param string $collectionName
- * @param array $options
* @return array|object Command result document
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function createCollection($collectionName, array $options = [])
+ public function createCollection(string $collectionName, array $options = [])
{
if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap;
@@ -340,7 +338,7 @@ public function drop(array $options = [])
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function dropCollection($collectionName, array $options = [])
+ public function dropCollection(string $collectionName, array $options = [])
{
if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap;
@@ -453,7 +451,6 @@ public function listCollectionNames(array $options = []): Iterator
* Returns information for all collections in this database.
*
* @see ListCollections::__construct() for supported options
- * @param array $options
* @return CollectionInfoIterator
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -477,7 +474,7 @@ public function listCollections(array $options = [])
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function modifyCollection($collectionName, array $collectionOptions, array $options = [])
+ public function modifyCollection(string $collectionName, array $collectionOptions, array $options = [])
{
if (! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap;
@@ -498,10 +495,10 @@ public function modifyCollection($collectionName, array $collectionOptions, arra
* Rename a collection within this database.
*
* @see RenameCollection::__construct() for supported options
- * @param string $fromCollectionName Collection name
- * @param string $toCollectionName New name of the collection
- * @param ?string $toDatabaseName New database name of the collection. Defaults to the original database.
- * @param array $options Additional options
+ * @param string $fromCollectionName Collection name
+ * @param string $toCollectionName New name of the collection
+ * @param string|null $toDatabaseName New database name of the collection. Defaults to the original database.
+ * @param array $options Additional options
* @return array|object Command result document
* @throws UnsupportedException if options are unsupported on the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
@@ -537,7 +534,7 @@ public function renameCollection(string $fromCollectionName, string $toCollectio
* @return Collection
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function selectCollection($collectionName, array $options = [])
+ public function selectCollection(string $collectionName, array $options = [])
{
$options += [
'readConcern' => $this->readConcern,
diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php
index 99dcd6a72..b140ff3ae 100644
--- a/src/Exception/BadMethodCallException.php
+++ b/src/Exception/BadMethodCallException.php
@@ -29,7 +29,7 @@ class BadMethodCallException extends BaseBadMethodCallException implements Excep
* @param string $class Class name
* @return self
*/
- public static function classIsImmutable($class)
+ public static function classIsImmutable(string $class)
{
return new static(sprintf('%s is immutable', $class));
}
@@ -40,7 +40,7 @@ public static function classIsImmutable($class)
* @param string $method Method name
* @return self
*/
- public static function unacknowledgedWriteResultAccess($method)
+ public static function unacknowledgedWriteResultAccess(string $method)
{
return new static(sprintf('%s should not be called for an unacknowledged write result', $method));
}
diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php
index 8be0de2bb..34f4cc5d9 100644
--- a/src/Exception/InvalidArgumentException.php
+++ b/src/Exception/InvalidArgumentException.php
@@ -36,7 +36,7 @@ class InvalidArgumentException extends DriverInvalidArgumentException implements
* @param string|string[] $expectedType Expected type
* @return self
*/
- public static function invalidType($name, $value, $expectedType)
+ public static function invalidType(string $name, $value, $expectedType)
{
if (is_array($expectedType)) {
switch (count($expectedType)) {
diff --git a/src/GridFS/Bucket.php b/src/GridFS/Bucket.php
index cdf1cddc3..33f6616a7 100644
--- a/src/GridFS/Bucket.php
+++ b/src/GridFS/Bucket.php
@@ -32,7 +32,6 @@
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument;
use MongoDB\Operation\Find;
-use stdClass;
use function array_intersect_key;
use function fopen;
@@ -137,7 +136,7 @@ class Bucket
* @param array $options Bucket options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct(Manager $manager, $databaseName, array $options = [])
+ public function __construct(Manager $manager, string $databaseName, array $options = [])
{
$options += [
'bucketName' => self::$defaultBucketName,
@@ -178,7 +177,7 @@ public function __construct(Manager $manager, $databaseName, array $options = []
}
$this->manager = $manager;
- $this->databaseName = (string) $databaseName;
+ $this->databaseName = $databaseName;
$this->bucketName = $options['bucketName'];
$this->chunkSizeBytes = $options['chunkSizeBytes'];
$this->disableMD5 = $options['disableMD5'];
@@ -282,7 +281,7 @@ public function downloadToStream($id, $destination)
* @throws StreamException if the file could not be uploaded
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function downloadToStreamByName($filename, $destination, array $options = [])
+ public function downloadToStreamByName(string $filename, $destination, array $options = [])
{
if (! is_resource($destination) || get_resource_type($destination) != "stream") {
throw InvalidArgumentException::invalidType('$destination', $destination, 'resource');
@@ -517,7 +516,7 @@ public function openDownloadStream($id)
* @throws FileNotFoundException if no file could be selected
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function openDownloadStreamByName($filename, array $options = [])
+ public function openDownloadStreamByName(string $filename, array $options = [])
{
$options += ['revision' => -1];
@@ -550,7 +549,7 @@ public function openDownloadStreamByName($filename, array $options = [])
* @param array $options Upload options
* @return resource
*/
- public function openUploadStream($filename, array $options = [])
+ public function openUploadStream(string $filename, array $options = [])
{
$options += ['chunkSizeBytes' => $this->chunkSizeBytes];
@@ -574,7 +573,7 @@ public function openUploadStream($filename, array $options = [])
* @throws FileNotFoundException if no file could be selected
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function rename($id, $newFilename)
+ public function rename($id, string $newFilename)
{
$updateResult = $this->collectionWrapper->updateFilenameForId($id, $newFilename);
@@ -620,7 +619,7 @@ public function rename($id, $newFilename)
* @throws StreamException if the file could not be uploaded
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function uploadFromStream($filename, $source, array $options = [])
+ public function uploadFromStream(string $filename, $source, array $options = [])
{
if (! is_resource($source) || get_resource_type($source) != "stream") {
throw InvalidArgumentException::invalidType('$source', $source, 'resource');
@@ -640,10 +639,9 @@ public function uploadFromStream($filename, $source, array $options = [])
/**
* Creates a path for an existing GridFS file.
*
- * @param stdClass $file GridFS file document
- * @return string
+ * @param object $file GridFS file document
*/
- private function createPathForFile(stdClass $file)
+ private function createPathForFile(object $file): string
{
if (! is_object($file->_id) || method_exists($file->_id, '__toString')) {
$id = (string) $file->_id;
@@ -662,10 +660,8 @@ private function createPathForFile(stdClass $file)
/**
* Creates a path for a new GridFS file, which does not yet have an ID.
- *
- * @return string
*/
- private function createPathForUpload()
+ private function createPathForUpload(): string
{
return sprintf(
'%s://%s/%s.files',
@@ -677,10 +673,8 @@ private function createPathForUpload()
/**
* Returns the names of the files collection.
- *
- * @return string
*/
- private function getFilesNamespace()
+ private function getFilesNamespace(): string
{
return sprintf('%s.%s.files', $this->databaseName, $this->bucketName);
}
@@ -692,10 +686,9 @@ private function getFilesNamespace()
* respect the Bucket's type map.
*
* @param resource $stream GridFS stream
- * @return stdClass
* @throws InvalidArgumentException
*/
- private function getRawFileDocumentForStream($stream)
+ private function getRawFileDocumentForStream($stream): object
{
if (! is_resource($stream) || get_resource_type($stream) != "stream") {
throw InvalidArgumentException::invalidType('$stream', $stream, 'resource');
@@ -713,10 +706,10 @@ private function getRawFileDocumentForStream($stream)
/**
* Opens a readable stream for the GridFS file.
*
- * @param stdClass $file GridFS file document
+ * @param object $file GridFS file document
* @return resource
*/
- private function openDownloadStreamByFile(stdClass $file)
+ private function openDownloadStreamByFile(object $file)
{
$path = $this->createPathForFile($file);
$context = stream_context_create([
@@ -732,7 +725,7 @@ private function openDownloadStreamByFile(stdClass $file)
/**
* Registers the GridFS stream wrapper if it is not already registered.
*/
- private function registerStreamWrapper()
+ private function registerStreamWrapper(): void
{
if (in_array(self::$streamWrapperProtocol, stream_get_wrappers())) {
return;
diff --git a/src/GridFS/CollectionWrapper.php b/src/GridFS/CollectionWrapper.php
index 7b58a4fb7..f4d4d76dc 100644
--- a/src/GridFS/CollectionWrapper.php
+++ b/src/GridFS/CollectionWrapper.php
@@ -25,7 +25,6 @@
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\UpdateResult;
use MultipleIterator;
-use stdClass;
use function abs;
use function count;
@@ -64,10 +63,10 @@ class CollectionWrapper
* @param array $collectionOptions Collection options
* @throws InvalidArgumentException
*/
- public function __construct(Manager $manager, $databaseName, $bucketName, array $collectionOptions = [])
+ public function __construct(Manager $manager, string $databaseName, string $bucketName, array $collectionOptions = [])
{
- $this->databaseName = (string) $databaseName;
- $this->bucketName = (string) $bucketName;
+ $this->databaseName = $databaseName;
+ $this->bucketName = $bucketName;
$this->filesCollection = new Collection($manager, $databaseName, sprintf('%s.files', $bucketName), $collectionOptions);
$this->chunksCollection = new Collection($manager, $databaseName, sprintf('%s.chunks', $bucketName), $collectionOptions);
@@ -78,7 +77,7 @@ public function __construct(Manager $manager, $databaseName, $bucketName, array
*
* @param mixed $id
*/
- public function deleteChunksByFilesId($id)
+ public function deleteChunksByFilesId($id): void
{
$this->chunksCollection->deleteMany(['files_id' => $id]);
}
@@ -88,7 +87,7 @@ public function deleteChunksByFilesId($id)
*
* @param mixed $id
*/
- public function deleteFileAndChunksById($id)
+ public function deleteFileAndChunksById($id): void
{
$this->filesCollection->deleteOne(['_id' => $id]);
$this->chunksCollection->deleteMany(['files_id' => $id]);
@@ -97,7 +96,7 @@ public function deleteFileAndChunksById($id)
/**
* Drops the GridFS files and chunks collections.
*/
- public function dropCollections()
+ public function dropCollections(): void
{
$this->filesCollection->drop(['typeMap' => []]);
$this->chunksCollection->drop(['typeMap' => []]);
@@ -108,9 +107,8 @@ public function dropCollections()
*
* @param mixed $id File ID
* @param integer $fromChunk Starting chunk (inclusive)
- * @return Cursor
*/
- public function findChunksByFileId($id, $fromChunk = 0)
+ public function findChunksByFileId($id, int $fromChunk = 0): Cursor
{
return $this->chunksCollection->find(
[
@@ -138,14 +136,11 @@ public function findChunksByFileId($id, $fromChunk = 0)
*
* @see Bucket::downloadToStreamByName()
* @see Bucket::openDownloadStreamByName()
- * @param string $filename
- * @param integer $revision
- * @return stdClass|null
*/
- public function findFileByFilenameAndRevision($filename, $revision)
+ public function findFileByFilenameAndRevision(string $filename, int $revision): ?object
{
- $filename = (string) $filename;
- $revision = (integer) $revision;
+ $filename = $filename;
+ $revision = $revision;
if ($revision < 0) {
$skip = abs($revision) - 1;
@@ -169,9 +164,8 @@ public function findFileByFilenameAndRevision($filename, $revision)
* Finds a GridFS file document for a given ID.
*
* @param mixed $id
- * @return stdClass|null
*/
- public function findFileById($id)
+ public function findFileById($id): ?object
{
return $this->filesCollection->findOne(
['_id' => $id],
@@ -204,42 +198,22 @@ public function findOneFile($filter, array $options = [])
return $this->filesCollection->findOne($filter, $options);
}
- /**
- * Return the bucket name.
- *
- * @return string
- */
- public function getBucketName()
+ public function getBucketName(): string
{
return $this->bucketName;
}
- /**
- * Return the chunks collection.
- *
- * @return Collection
- */
- public function getChunksCollection()
+ public function getChunksCollection(): Collection
{
return $this->chunksCollection;
}
- /**
- * Return the database name.
- *
- * @return string
- */
- public function getDatabaseName()
+ public function getDatabaseName(): string
{
return $this->databaseName;
}
- /**
- * Return the files collection.
- *
- * @return Collection
- */
- public function getFilesCollection()
+ public function getFilesCollection(): Collection
{
return $this->filesCollection;
}
@@ -249,7 +223,7 @@ public function getFilesCollection()
*
* @param array|object $chunk Chunk document
*/
- public function insertChunk($chunk)
+ public function insertChunk($chunk): void
{
if (! $this->checkedIndexes) {
$this->ensureIndexes();
@@ -265,7 +239,7 @@ public function insertChunk($chunk)
*
* @param array|object $file File document
*/
- public function insertFile($file)
+ public function insertFile($file): void
{
if (! $this->checkedIndexes) {
$this->ensureIndexes();
@@ -277,22 +251,20 @@ public function insertFile($file)
/**
* Updates the filename field in the file document for a given ID.
*
- * @param mixed $id
- * @param string $filename
- * @return UpdateResult
+ * @param mixed $id
*/
- public function updateFilenameForId($id, $filename)
+ public function updateFilenameForId($id, string $filename): UpdateResult
{
return $this->filesCollection->updateOne(
['_id' => $id],
- ['$set' => ['filename' => (string) $filename]]
+ ['$set' => ['filename' => $filename]]
);
}
/**
* Create an index on the chunks collection if it does not already exist.
*/
- private function ensureChunksIndex()
+ private function ensureChunksIndex(): void
{
$expectedIndex = ['files_id' => 1, 'n' => 1];
@@ -308,7 +280,7 @@ private function ensureChunksIndex()
/**
* Create an index on the files collection if it does not already exist.
*/
- private function ensureFilesIndex()
+ private function ensureFilesIndex(): void
{
$expectedIndex = ['filename' => 1, 'uploadDate' => 1];
@@ -327,7 +299,7 @@ private function ensureFilesIndex()
* This method is called once before the first write operation on a GridFS
* bucket. Indexes are only be created if the files collection is empty.
*/
- private function ensureIndexes()
+ private function ensureIndexes(): void
{
if ($this->checkedIndexes) {
return;
@@ -375,10 +347,8 @@ private function indexKeysMatch(array $expectedKeys, array $actualKeys): bool
/**
* Returns whether the files collection is empty.
- *
- * @return boolean
*/
- private function isFilesCollectionEmpty()
+ private function isFilesCollectionEmpty(): bool
{
return null === $this->filesCollection->findOne([], [
'readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY),
diff --git a/src/GridFS/Exception/CorruptFileException.php b/src/GridFS/Exception/CorruptFileException.php
index c68ceec95..7879cb1ec 100644
--- a/src/GridFS/Exception/CorruptFileException.php
+++ b/src/GridFS/Exception/CorruptFileException.php
@@ -29,7 +29,7 @@ class CorruptFileException extends RuntimeException
* @param integer $expectedIndex Expected index number
* @return self
*/
- public static function missingChunk($expectedIndex)
+ public static function missingChunk(int $expectedIndex)
{
return new static(sprintf('Chunk not found for index "%d"', $expectedIndex));
}
@@ -41,7 +41,7 @@ public static function missingChunk($expectedIndex)
* @param integer $expectedIndex Expected index number
* @return self
*/
- public static function unexpectedIndex($index, $expectedIndex)
+ public static function unexpectedIndex(int $index, int $expectedIndex)
{
return new static(sprintf('Expected chunk to have index "%d" but found "%d"', $expectedIndex, $index));
}
@@ -53,7 +53,7 @@ public static function unexpectedIndex($index, $expectedIndex)
* @param integer $expectedSize Expected size
* @return self
*/
- public static function unexpectedSize($size, $expectedSize)
+ public static function unexpectedSize(int $size, int $expectedSize)
{
return new static(sprintf('Expected chunk to have size "%d" but found "%d"', $expectedSize, $size));
}
diff --git a/src/GridFS/Exception/FileNotFoundException.php b/src/GridFS/Exception/FileNotFoundException.php
index ff9c2c7eb..5d0f5d5c5 100644
--- a/src/GridFS/Exception/FileNotFoundException.php
+++ b/src/GridFS/Exception/FileNotFoundException.php
@@ -33,7 +33,7 @@ class FileNotFoundException extends RuntimeException
* @param string $namespace Namespace for the files collection
* @return self
*/
- public static function byFilenameAndRevision($filename, $revision, $namespace)
+ public static function byFilenameAndRevision(string $filename, int $revision, string $namespace)
{
return new static(sprintf('File with name "%s" and revision "%d" not found in "%s"', $filename, $revision, $namespace));
}
@@ -45,7 +45,7 @@ public static function byFilenameAndRevision($filename, $revision, $namespace)
* @param string $namespace Namespace for the files collection
* @return self
*/
- public static function byId($id, $namespace)
+ public static function byId($id, string $namespace)
{
$json = toJSON(fromPHP(['_id' => $id]));
diff --git a/src/GridFS/ReadableStream.php b/src/GridFS/ReadableStream.php
index 5a5b1ec3b..9672b803f 100644
--- a/src/GridFS/ReadableStream.php
+++ b/src/GridFS/ReadableStream.php
@@ -20,7 +20,6 @@
use MongoDB\Driver\CursorInterface;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\GridFS\Exception\CorruptFileException;
-use stdClass;
use function ceil;
use function floor;
@@ -58,7 +57,7 @@ class ReadableStream
/** @var float|integer */
private $expectedLastChunkSize = 0;
- /** @var stdClass */
+ /** @var object */
private $file;
/** @var integer */
@@ -71,10 +70,10 @@ class ReadableStream
* Constructs a readable GridFS stream.
*
* @param CollectionWrapper $collectionWrapper GridFS collection wrapper
- * @param stdClass $file GridFS file document
+ * @param object $file GridFS file document
* @throws CorruptFileException
*/
- public function __construct(CollectionWrapper $collectionWrapper, stdClass $file)
+ public function __construct(CollectionWrapper $collectionWrapper, object $file)
{
if (! isset($file->chunkSize) || ! is_integer($file->chunkSize) || $file->chunkSize < 1) {
throw new CorruptFileException('file.chunkSize is not an integer >= 1');
@@ -89,8 +88,8 @@ public function __construct(CollectionWrapper $collectionWrapper, stdClass $file
}
$this->file = $file;
- $this->chunkSize = (integer) $file->chunkSize;
- $this->length = (integer) $file->length;
+ $this->chunkSize = $file->chunkSize;
+ $this->length = $file->length;
$this->collectionWrapper = $collectionWrapper;
@@ -106,7 +105,7 @@ public function __construct(CollectionWrapper $collectionWrapper, stdClass $file
* @see https://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
* @return array
*/
- public function __debugInfo()
+ public function __debugInfo(): array
{
return [
'bucketName' => $this->collectionWrapper->getBucketName(),
@@ -115,37 +114,25 @@ public function __debugInfo()
];
}
- public function close()
+ public function close(): void
{
// Nothing to do
}
- /**
- * Return the stream's file document.
- *
- * @return stdClass
- */
- public function getFile()
+ public function getFile(): object
{
return $this->file;
}
- /**
- * Return the stream's size in bytes.
- *
- * @return integer
- */
- public function getSize()
+ public function getSize(): int
{
return $this->length;
}
/**
* Return whether the current read position is at the end of the stream.
- *
- * @return boolean
*/
- public function isEOF()
+ public function isEOF(): bool
{
if ($this->chunkOffset === $this->numChunks - 1) {
return $this->bufferOffset >= $this->expectedLastChunkSize;
@@ -161,10 +148,9 @@ public function isEOF()
* if data is not available to be read.
*
* @param integer $length Number of bytes to read
- * @return string
* @throws InvalidArgumentException if $length is negative
*/
- public function readBytes($length)
+ public function readBytes(int $length): string
{
if ($length < 0) {
throw new InvalidArgumentException(sprintf('$length must be >= 0; given: %d', $length));
@@ -196,10 +182,9 @@ public function readBytes($length)
/**
* Seeks the chunk and buffer offsets for the next read operation.
*
- * @param integer $offset
* @throws InvalidArgumentException if $offset is out of range
*/
- public function seek($offset)
+ public function seek(int $offset): void
{
if ($offset < 0 || $offset > $this->file->length) {
throw new InvalidArgumentException(sprintf('$offset must be >= 0 and <= %d; given: %d', $this->file->length, $offset));
@@ -247,10 +232,8 @@ public function seek($offset)
* Return the current position of the stream.
*
* This is the offset within the stream where the next byte would be read.
- *
- * @return integer
*/
- public function tell()
+ public function tell(): int
{
return ($this->chunkOffset * $this->chunkSize) + $this->bufferOffset;
}
@@ -261,7 +244,7 @@ public function tell()
* @return boolean Whether there was a current chunk to read
* @throws CorruptFileException if an expected chunk could not be read successfully
*/
- private function initBufferFromCurrentChunk()
+ private function initBufferFromCurrentChunk(): bool
{
if ($this->chunkOffset === 0 && $this->numChunks === 0) {
return false;
@@ -298,7 +281,7 @@ private function initBufferFromCurrentChunk()
* @return boolean Whether there was a next chunk to read
* @throws CorruptFileException if an expected chunk could not be read successfully
*/
- private function initBufferFromNextChunk()
+ private function initBufferFromNextChunk(): bool
{
if ($this->chunkOffset === $this->numChunks - 1) {
return false;
@@ -314,7 +297,7 @@ private function initBufferFromNextChunk()
/**
* Initializes the chunk iterator starting from the current offset.
*/
- private function initChunksIterator()
+ private function initChunksIterator(): void
{
$this->chunksIterator = $this->collectionWrapper->findChunksByFileId($this->file->_id, $this->chunkOffset);
$this->chunksIterator->rewind();
diff --git a/src/GridFS/StreamWrapper.php b/src/GridFS/StreamWrapper.php
index 3507708cb..268c47ea7 100644
--- a/src/GridFS/StreamWrapper.php
+++ b/src/GridFS/StreamWrapper.php
@@ -18,7 +18,6 @@
namespace MongoDB\GridFS;
use MongoDB\BSON\UTCDateTime;
-use stdClass;
use function explode;
use function in_array;
@@ -64,10 +63,8 @@ public function __destruct()
/**
* Return the stream's file document.
- *
- * @return stdClass
*/
- public function getFile()
+ public function getFile(): object
{
return $this->stream->getFile();
}
@@ -77,7 +74,7 @@ public function getFile()
*
* @param string $protocol Protocol to use for stream_wrapper_register()
*/
- public static function register($protocol = 'gridfs')
+ public static function register(string $protocol = 'gridfs'): void
{
if (in_array($protocol, stream_get_wrappers())) {
stream_wrapper_unregister($protocol);
@@ -91,7 +88,7 @@ public static function register($protocol = 'gridfs')
*
* @see https://php.net/manual/en/streamwrapper.stream-close.php
*/
- public function stream_close()
+ public function stream_close(): void
{
if (! $this->stream) {
return;
@@ -104,9 +101,8 @@ public function stream_close()
* Returns whether the file pointer is at the end of the stream.
*
* @see https://php.net/manual/en/streamwrapper.stream-eof.php
- * @return boolean
*/
- public function stream_eof()
+ public function stream_eof(): bool
{
if (! $this->stream instanceof ReadableStream) {
return false;
@@ -119,13 +115,12 @@ public function stream_eof()
* Opens the stream.
*
* @see https://php.net/manual/en/streamwrapper.stream-open.php
- * @param string $path Path to the file resource
- * @param string $mode Mode used to open the file (only "r" and "w" are supported)
- * @param integer $options Additional flags set by the streams API
- * @param string $openedPath Not used
- * @return boolean
+ * @param string $path Path to the file resource
+ * @param string $mode Mode used to open the file (only "r" and "w" are supported)
+ * @param integer $options Additional flags set by the streams API
+ * @param string|null $openedPath Not used
*/
- public function stream_open($path, $mode, $options, &$openedPath)
+ public function stream_open(string $path, string $mode, int $options, ?string &$openedPath): bool
{
$this->initProtocol($path);
$this->mode = $mode;
@@ -149,9 +144,8 @@ public function stream_open($path, $mode, $options, &$openedPath)
*
* @see https://php.net/manual/en/streamwrapper.stream-read.php
* @param integer $length Number of bytes to read
- * @return string
*/
- public function stream_read($length)
+ public function stream_read(int $length): string
{
if (! $this->stream instanceof ReadableStream) {
return '';
@@ -168,7 +162,7 @@ public function stream_read($length)
* @param integer $whence One of SEEK_SET, SEEK_CUR, or SEEK_END
* @return boolean True if the position was updated and false otherwise
*/
- public function stream_seek($offset, $whence = SEEK_SET)
+ public function stream_seek(int $offset, int $whence = SEEK_SET): bool
{
$size = $this->stream->getSize();
@@ -198,9 +192,8 @@ public function stream_seek($offset, $whence = SEEK_SET)
* Return information about the stream.
*
* @see https://php.net/manual/en/streamwrapper.stream-stat.php
- * @return array
*/
- public function stream_stat()
+ public function stream_stat(): array
{
$stat = $this->getStatTemplate();
@@ -230,7 +223,7 @@ public function stream_stat()
* @see https://php.net/manual/en/streamwrapper.stream-tell.php
* @return integer The current position of the stream
*/
- public function stream_tell()
+ public function stream_tell(): int
{
return $this->stream->tell();
}
@@ -242,7 +235,7 @@ public function stream_tell()
* @param string $data Data to write
* @return integer The number of bytes written
*/
- public function stream_write($data)
+ public function stream_write(string $data): int
{
if (! $this->stream instanceof WritableStream) {
return 0;
@@ -253,10 +246,8 @@ public function stream_write($data)
/**
* Returns a stat template with default values.
- *
- * @return array
*/
- private function getStatTemplate()
+ private function getStatTemplate(): array
{
return [
// phpcs:disable Squiz.Arrays.ArrayDeclaration.IndexNoNewline
@@ -281,9 +272,8 @@ private function getStatTemplate()
* Initialize the protocol from the given path.
*
* @see StreamWrapper::stream_open()
- * @param string $path
*/
- private function initProtocol($path)
+ private function initProtocol(string $path): void
{
$parts = explode('://', $path, 2);
$this->protocol = $parts[0] ?: 'gridfs';
@@ -293,9 +283,8 @@ private function initProtocol($path)
* Initialize the internal stream for reading.
*
* @see StreamWrapper::stream_open()
- * @return boolean
*/
- private function initReadableStream()
+ private function initReadableStream(): bool
{
$context = stream_context_get_options($this->context);
@@ -311,9 +300,8 @@ private function initReadableStream()
* Initialize the internal stream for writing.
*
* @see StreamWrapper::stream_open()
- * @return boolean
*/
- private function initWritableStream()
+ private function initWritableStream(): bool
{
$context = stream_context_get_options($this->context);
diff --git a/src/GridFS/WritableStream.php b/src/GridFS/WritableStream.php
index d38d39f8e..b80a8ce6b 100644
--- a/src/GridFS/WritableStream.php
+++ b/src/GridFS/WritableStream.php
@@ -22,7 +22,6 @@
use MongoDB\BSON\UTCDateTime;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException;
-use stdClass;
use function array_intersect_key;
use function hash_final;
@@ -103,7 +102,7 @@ class WritableStream
* @param array $options Upload options
* @throws InvalidArgumentException
*/
- public function __construct(CollectionWrapper $collectionWrapper, $filename, array $options = [])
+ public function __construct(CollectionWrapper $collectionWrapper, string $filename, array $options = [])
{
$options += [
'_id' => new ObjectId(),
@@ -146,7 +145,7 @@ public function __construct(CollectionWrapper $collectionWrapper, $filename, arr
$this->file = [
'_id' => $options['_id'],
'chunkSize' => $this->chunkSize,
- 'filename' => (string) $filename,
+ 'filename' => $filename,
] + array_intersect_key($options, ['aliases' => 1, 'contentType' => 1, 'metadata' => 1]);
}
@@ -154,9 +153,8 @@ public function __construct(CollectionWrapper $collectionWrapper, $filename, arr
* Return internal properties for debugging purposes.
*
* @see https://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
- * @return array
*/
- public function __debugInfo()
+ public function __debugInfo(): array
{
return [
'bucketName' => $this->collectionWrapper->getBucketName(),
@@ -168,7 +166,7 @@ public function __debugInfo()
/**
* Closes an active stream and flushes all buffered data to GridFS.
*/
- public function close()
+ public function close(): void
{
if ($this->isClosed) {
// TODO: Should this be an error condition? e.g. BadMethodCallException
@@ -185,10 +183,8 @@ public function close()
/**
* Return the stream's file document.
- *
- * @return stdClass
*/
- public function getFile()
+ public function getFile(): object
{
return (object) $this->file;
}
@@ -197,10 +193,8 @@ public function getFile()
* Return the stream's size in bytes.
*
* Note: this value will increase as more data is written to the stream.
- *
- * @return integer
*/
- public function getSize()
+ public function getSize(): int
{
return $this->length + strlen($this->buffer);
}
@@ -213,9 +207,8 @@ public function getSize()
* always the end of the stream.
*
* @see WritableStream::getSize()
- * @return integer
*/
- public function tell()
+ public function tell(): int
{
return $this->getSize();
}
@@ -227,13 +220,12 @@ public function tell()
* which point a chunk document will be inserted and the buffer reset.
*
* @param string $data Binary data to write
- * @return integer
*/
- public function writeBytes($data)
+ public function writeBytes(string $data): int
{
if ($this->isClosed) {
// TODO: Should this be an error condition? e.g. BadMethodCallException
- return;
+ return 0;
}
$bytesRead = 0;
@@ -251,7 +243,7 @@ public function writeBytes($data)
return $bytesRead;
}
- private function abort()
+ private function abort(): void
{
try {
$this->collectionWrapper->deleteChunksByFilesId($this->file['_id']);
@@ -285,7 +277,7 @@ private function fileCollectionInsert()
return $this->file['_id'];
}
- private function insertChunkFromBuffer()
+ private function insertChunkFromBuffer(): void
{
if (strlen($this->buffer) == 0) {
return;
diff --git a/src/InsertManyResult.php b/src/InsertManyResult.php
index 5dc29a8d2..87fd60eef 100644
--- a/src/InsertManyResult.php
+++ b/src/InsertManyResult.php
@@ -28,16 +28,12 @@ class InsertManyResult
/** @var WriteResult */
private $writeResult;
- /** @var mixed[] */
+ /** @var array */
private $insertedIds;
/** @var boolean */
private $isAcknowledged;
- /**
- * @param WriteResult $writeResult
- * @param mixed[] $insertedIds
- */
public function __construct(WriteResult $writeResult, array $insertedIds)
{
$this->writeResult = $writeResult;
@@ -72,7 +68,7 @@ public function getInsertedCount()
* field value. Any driver-generated ID will be a MongoDB\BSON\ObjectId
* instance.
*
- * @return mixed[]
+ * @return array
*/
public function getInsertedIds()
{
diff --git a/src/InsertOneResult.php b/src/InsertOneResult.php
index 32a14a1e3..4376b6bdf 100644
--- a/src/InsertOneResult.php
+++ b/src/InsertOneResult.php
@@ -35,8 +35,7 @@ class InsertOneResult
private $isAcknowledged;
/**
- * @param WriteResult $writeResult
- * @param mixed $insertedId
+ * @param mixed $insertedId
*/
public function __construct(WriteResult $writeResult, $insertedId)
{
diff --git a/src/MapReduceResult.php b/src/MapReduceResult.php
index fe2127902..d7ef777a3 100644
--- a/src/MapReduceResult.php
+++ b/src/MapReduceResult.php
@@ -79,7 +79,7 @@ public function getCounts()
*/
public function getExecutionTimeMS()
{
- return (integer) $this->executionTimeMS;
+ return $this->executionTimeMS;
}
/**
diff --git a/src/Model/BSONArray.php b/src/Model/BSONArray.php
index 74d0caf40..a87505f29 100644
--- a/src/Model/BSONArray.php
+++ b/src/Model/BSONArray.php
@@ -51,7 +51,6 @@ public function __clone()
*
* @see https://php.net/oop5.magic#object.set-state
* @see https://php.net/var-export
- * @param array $properties
* @return self
*/
public static function __set_state(array $properties)
diff --git a/src/Model/BSONDocument.php b/src/Model/BSONDocument.php
index af439f8ad..8fc04e84f 100644
--- a/src/Model/BSONDocument.php
+++ b/src/Model/BSONDocument.php
@@ -50,11 +50,8 @@ public function __clone()
* by default.
*
* @see https://php.net/arrayobject.construct
- * @param array $input
- * @param integer $flags
- * @param string $iteratorClass
*/
- public function __construct($input = [], $flags = ArrayObject::ARRAY_AS_PROPS, $iteratorClass = 'ArrayIterator')
+ public function __construct(array $input = [], int $flags = ArrayObject::ARRAY_AS_PROPS, string $iteratorClass = 'ArrayIterator')
{
parent::__construct($input, $flags, $iteratorClass);
}
@@ -64,7 +61,6 @@ public function __construct($input = [], $flags = ArrayObject::ARRAY_AS_PROPS, $
*
* @see https://php.net/oop5.magic#object.set-state
* @see https://php.net/var-export
- * @param array $properties
* @return self
*/
public static function __set_state(array $properties)
diff --git a/src/Model/BSONIterator.php b/src/Model/BSONIterator.php
index 5c086b81a..2bddc264c 100644
--- a/src/Model/BSONIterator.php
+++ b/src/Model/BSONIterator.php
@@ -68,7 +68,7 @@ class BSONIterator implements Iterator
* @param array $options Iterator options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($data, array $options = [])
+ public function __construct(string $data, array $options = [])
{
if (isset($options['typeMap']) && ! is_array($options['typeMap'])) {
throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
@@ -130,15 +130,14 @@ public function rewind()
/**
* @see https://php.net/iterator.valid
- * @return boolean
*/
#[ReturnTypeWillChange]
- public function valid()
+ public function valid(): bool
{
return $this->current !== null;
}
- private function advance()
+ private function advance(): void
{
if ($this->position === $this->bufferLength) {
return;
diff --git a/src/Model/CachingIterator.php b/src/Model/CachingIterator.php
index 0e54dc2c8..f2a7dd25b 100644
--- a/src/Model/CachingIterator.php
+++ b/src/Model/CachingIterator.php
@@ -72,10 +72,8 @@ public function __construct(Traversable $traversable)
/**
* @see https://php.net/countable.count
- * @return integer
*/
- #[ReturnTypeWillChange]
- public function count()
+ public function count(): int
{
$this->exhaustIterator();
@@ -108,10 +106,8 @@ public function key()
/**
* @see https://php.net/iterator.next
- * @return void
*/
- #[ReturnTypeWillChange]
- public function next()
+ public function next(): void
{
if (! $this->iteratorExhausted) {
$this->iteratorAdvanced = true;
@@ -127,10 +123,8 @@ public function next()
/**
* @see https://php.net/iterator.rewind
- * @return void
*/
- #[ReturnTypeWillChange]
- public function rewind()
+ public function rewind(): void
{
/* If the iterator has advanced, exhaust it now so that future iteration
* can rely on the cache.
@@ -144,10 +138,8 @@ public function rewind()
/**
* @see https://php.net/iterator.valid
- * @return boolean
*/
- #[ReturnTypeWillChange]
- public function valid()
+ public function valid(): bool
{
return $this->key() !== null;
}
@@ -155,7 +147,7 @@ public function valid()
/**
* Ensures that the inner iterator is fully consumed and cached.
*/
- private function exhaustIterator()
+ private function exhaustIterator(): void
{
while (! $this->iteratorExhausted) {
$this->next();
@@ -165,7 +157,7 @@ private function exhaustIterator()
/**
* Stores the current item in the cache.
*/
- private function storeCurrentItem()
+ private function storeCurrentItem(): void
{
if (! $this->iterator->valid()) {
return;
diff --git a/src/Model/CallbackIterator.php b/src/Model/CallbackIterator.php
index a5abec9c1..8e3c68d0c 100644
--- a/src/Model/CallbackIterator.php
+++ b/src/Model/CallbackIterator.php
@@ -64,30 +64,24 @@ public function key()
/**
* @see https://php.net/iterator.next
- * @return void
*/
- #[ReturnTypeWillChange]
- public function next()
+ public function next(): void
{
$this->iterator->next();
}
/**
* @see https://php.net/iterator.rewind
- * @return void
*/
- #[ReturnTypeWillChange]
- public function rewind()
+ public function rewind(): void
{
$this->iterator->rewind();
}
/**
* @see https://php.net/iterator.valid
- * @return boolean
*/
- #[ReturnTypeWillChange]
- public function valid()
+ public function valid(): bool
{
return $this->iterator->valid();
}
diff --git a/src/Model/ChangeStreamIterator.php b/src/Model/ChangeStreamIterator.php
index 307a68edc..85fba283d 100644
--- a/src/Model/ChangeStreamIterator.php
+++ b/src/Model/ChangeStreamIterator.php
@@ -71,12 +71,9 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
/**
* @internal
- * @param Cursor $cursor
- * @param integer $firstBatchSize
* @param array|object|null $initialResumeToken
- * @param object|null $postBatchResumeToken
*/
- public function __construct(Cursor $cursor, $firstBatchSize, $initialResumeToken, $postBatchResumeToken)
+ public function __construct(Cursor $cursor, int $firstBatchSize, $initialResumeToken, ?object $postBatchResumeToken)
{
if (! is_integer($firstBatchSize)) {
throw InvalidArgumentException::invalidType('$firstBatchSize', $firstBatchSize, 'integer');
@@ -180,10 +177,8 @@ public function key()
/**
* @see https://php.net/iteratoriterator.rewind
- * @return void
*/
- #[ReturnTypeWillChange]
- public function next()
+ public function next(): void
{
/* Determine if advancing the iterator will execute a getMore command
* (i.e. we are already positioned at the end of the current batch). If
@@ -208,10 +203,8 @@ public function next()
/**
* @see https://php.net/iteratoriterator.rewind
- * @return void
*/
- #[ReturnTypeWillChange]
- public function rewind()
+ public function rewind(): void
{
if ($this->isRewindNop) {
return;
@@ -223,10 +216,8 @@ public function rewind()
/**
* @see https://php.net/iteratoriterator.valid
- * @return boolean
*/
- #[ReturnTypeWillChange]
- public function valid()
+ public function valid(): bool
{
return $this->isValid;
}
@@ -270,10 +261,8 @@ private function extractResumeToken($document)
/**
* Return whether the iterator is positioned at the end of the batch.
- *
- * @return boolean
*/
- private function isAtEndOfBatch()
+ private function isAtEndOfBatch(): bool
{
return $this->batchPosition + 1 >= $this->batchSize;
}
@@ -282,9 +271,8 @@ private function isAtEndOfBatch()
* Perform housekeeping after an iteration event.
*
* @see https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.rst#updating-the-cached-resume-token
- * @param boolean $incrementBatchPosition
*/
- private function onIteration($incrementBatchPosition)
+ private function onIteration(bool $incrementBatchPosition): void
{
$this->isValid = parent::valid();
diff --git a/src/Model/CollectionInfo.php b/src/Model/CollectionInfo.php
index 0513125ca..6722978bc 100644
--- a/src/Model/CollectionInfo.php
+++ b/src/Model/CollectionInfo.php
@@ -86,8 +86,6 @@ public function getCappedSize()
/**
* Return information about the _id index for the collection.
- *
- * @return array
*/
public function getIdIndex(): array
{
@@ -98,7 +96,6 @@ public function getIdIndex(): array
* Return the "info" property of the server response.
*
* @see https://mongodb.com/docs/manual/reference/command/listCollections/#output
- * @return array
*/
public function getInfo(): array
{
@@ -131,7 +128,6 @@ public function getOptions()
* Return the collection type.
*
* @see https://mongodb.com/docs/manual/reference/command/listCollections/#output
- * @return string
*/
public function getType(): string
{
diff --git a/src/Model/CollectionInfoCommandIterator.php b/src/Model/CollectionInfoCommandIterator.php
index 316b67fb0..96c2d73a9 100644
--- a/src/Model/CollectionInfoCommandIterator.php
+++ b/src/Model/CollectionInfoCommandIterator.php
@@ -18,7 +18,6 @@
namespace MongoDB\Model;
use IteratorIterator;
-use ReturnTypeWillChange;
use Traversable;
/**
@@ -37,10 +36,7 @@ class CollectionInfoCommandIterator extends IteratorIterator implements Collecti
/** @var string|null */
private $databaseName;
- /**
- * @param string|null $databaseName
- */
- public function __construct(Traversable $iterator, $databaseName = null)
+ public function __construct(Traversable $iterator, ?string $databaseName = null)
{
parent::__construct($iterator);
@@ -52,10 +48,8 @@ public function __construct(Traversable $iterator, $databaseName = null)
*
* @see CollectionInfoIterator::current()
* @see https://php.net/iterator.current
- * @return CollectionInfo
*/
- #[ReturnTypeWillChange]
- public function current()
+ public function current(): CollectionInfo
{
$info = parent::current();
diff --git a/src/Model/DatabaseInfoLegacyIterator.php b/src/Model/DatabaseInfoLegacyIterator.php
index c6f5f0842..2fb8e88a5 100644
--- a/src/Model/DatabaseInfoLegacyIterator.php
+++ b/src/Model/DatabaseInfoLegacyIterator.php
@@ -17,8 +17,6 @@
namespace MongoDB\Model;
-use ReturnTypeWillChange;
-
use function current;
use function key;
use function next;
@@ -39,9 +37,6 @@ class DatabaseInfoLegacyIterator implements DatabaseInfoIterator
/** @var array */
private $databases;
- /**
- * @param array $databases
- */
public function __construct(array $databases)
{
$this->databases = $databases;
@@ -52,9 +47,8 @@ public function __construct(array $databases)
*
* @see DatabaseInfoIterator::current()
* @see https://php.net/iterator.current
- * @return DatabaseInfo
*/
- public function current()
+ public function current(): DatabaseInfo
{
return new DatabaseInfo(current($this->databases));
}
@@ -63,10 +57,8 @@ public function current()
* Return the key of the current element.
*
* @see https://php.net/iterator.key
- * @return integer
*/
- #[ReturnTypeWillChange]
- public function key()
+ public function key(): int
{
return key($this->databases);
}
@@ -75,10 +67,8 @@ public function key()
* Move forward to next element.
*
* @see https://php.net/iterator.next
- * @return void
*/
- #[ReturnTypeWillChange]
- public function next()
+ public function next(): void
{
next($this->databases);
}
@@ -87,10 +77,8 @@ public function next()
* Rewind the Iterator to the first element.
*
* @see https://php.net/iterator.rewind
- * @return void
*/
- #[ReturnTypeWillChange]
- public function rewind()
+ public function rewind(): void
{
reset($this->databases);
}
@@ -99,10 +87,8 @@ public function rewind()
* Checks if current position is valid.
*
* @see https://php.net/iterator.valid
- * @return boolean
*/
- #[ReturnTypeWillChange]
- public function valid()
+ public function valid(): bool
{
return key($this->databases) !== null;
}
diff --git a/src/Model/IndexInfoIteratorIterator.php b/src/Model/IndexInfoIteratorIterator.php
index fcdcbf041..f0a35baf0 100644
--- a/src/Model/IndexInfoIteratorIterator.php
+++ b/src/Model/IndexInfoIteratorIterator.php
@@ -18,7 +18,6 @@
namespace MongoDB\Model;
use IteratorIterator;
-use ReturnTypeWillChange;
use Traversable;
use function array_key_exists;
@@ -41,10 +40,7 @@ class IndexInfoIteratorIterator extends IteratorIterator implements IndexInfoIte
/** @var string|null $ns */
private $ns;
- /**
- * @param string|null $ns
- */
- public function __construct(Traversable $iterator, $ns = null)
+ public function __construct(Traversable $iterator, ?string $ns = null)
{
parent::__construct($iterator);
@@ -56,10 +52,8 @@ public function __construct(Traversable $iterator, $ns = null)
*
* @see IndexInfoIterator::current()
* @see https://php.net/iterator.current
- * @return IndexInfo
*/
- #[ReturnTypeWillChange]
- public function current()
+ public function current(): IndexInfo
{
$info = parent::current();
diff --git a/src/Model/IndexInput.php b/src/Model/IndexInput.php
index 5c6342b4c..65c3fc2a2 100644
--- a/src/Model/IndexInput.php
+++ b/src/Model/IndexInput.php
@@ -19,7 +19,6 @@
use MongoDB\BSON\Serializable;
use MongoDB\Exception\InvalidArgumentException;
-use ReturnTypeWillChange;
use function is_array;
use function is_float;
@@ -77,10 +76,8 @@ public function __construct(array $index)
/**
* Return the index name.
- *
- * @return string
*/
- public function __toString()
+ public function __toString(): string
{
return $this->index['name'];
}
@@ -90,10 +87,8 @@ public function __toString()
*
* @see \MongoDB\Collection::createIndexes()
* @see https://php.net/mongodb-bson-serializable.bsonserialize
- * @return array
*/
- #[ReturnTypeWillChange]
- public function bsonSerialize()
+ public function bsonSerialize(): array
{
return $this->index;
}
diff --git a/src/Operation/Aggregate.php b/src/Operation/Aggregate.php
index de3c1e4f0..f529be022 100644
--- a/src/Operation/Aggregate.php
+++ b/src/Operation/Aggregate.php
@@ -137,7 +137,7 @@ class Aggregate implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, array $pipeline, array $options = [])
+ public function __construct(string $databaseName, ?string $collectionName, array $pipeline, array $options = [])
{
$expectedIndex = 0;
@@ -246,8 +246,8 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
unset($options['batchSize']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = isset($collectionName) ? (string) $collectionName : null;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->pipeline = $pipeline;
$this->options = $options;
}
@@ -256,7 +256,6 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return Traversable
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if read concern or write concern is used and unsupported
@@ -307,7 +306,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -317,10 +315,8 @@ public function getCommandDocument(Server $server)
/**
* Create the aggregate command document.
- *
- * @return array
*/
- private function createCommandDocument()
+ private function createCommandDocument(): array
{
$cmd = [
'aggregate' => $this->collectionName ?? 1,
diff --git a/src/Operation/BulkWrite.php b/src/Operation/BulkWrite.php
index f9096c2c5..28568de25 100644
--- a/src/Operation/BulkWrite.php
+++ b/src/Operation/BulkWrite.php
@@ -127,7 +127,7 @@ class BulkWrite implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, array $operations, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, array $operations, array $options = [])
{
if (empty($operations)) {
throw new InvalidArgumentException('$operations is empty');
@@ -297,8 +297,8 @@ public function __construct($databaseName, $collectionName, array $operations, a
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->operations = $operations;
$this->options = $options;
}
@@ -307,7 +307,6 @@ public function __construct($databaseName, $collectionName, array $operations, a
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return BulkWriteResult
* @throws UnsupportedException if write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -352,9 +351,8 @@ public function execute(Server $server)
* Create options for constructing the bulk write.
*
* @see https://php.net/manual/en/mongodb-driver-bulkwrite.construct.php
- * @return array
*/
- private function createBulkWriteOptions()
+ private function createBulkWriteOptions(): array
{
$options = ['ordered' => $this->options['ordered']];
@@ -375,9 +373,8 @@ private function createBulkWriteOptions()
* Create options for executing the bulk write.
*
* @see https://php.net/manual/en/mongodb-driver-server.executebulkwrite.php
- * @return array
*/
- private function createExecuteOptions()
+ private function createExecuteOptions(): array
{
$options = [];
diff --git a/src/Operation/Count.php b/src/Operation/Count.php
index aff947b72..b72bc34bf 100644
--- a/src/Operation/Count.php
+++ b/src/Operation/Count.php
@@ -90,7 +90,7 @@ class Count implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter = [], array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter = [], array $options = [])
{
if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
@@ -132,8 +132,8 @@ public function __construct($databaseName, $collectionName, $filter = [], array
unset($options['readConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->filter = $filter;
$this->options = $options;
}
@@ -142,7 +142,6 @@ public function __construct($databaseName, $collectionName, $filter = [], array
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return integer
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if read concern is used and unsupported
@@ -170,7 +169,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -180,10 +178,8 @@ public function getCommandDocument(Server $server)
/**
* Create the count command document.
- *
- * @return array
*/
- private function createCommandDocument()
+ private function createCommandDocument(): array
{
$cmd = ['count' => $this->collectionName];
@@ -212,9 +208,8 @@ private function createCommandDocument()
* Create options for executing the command.
*
* @see https://php.net/manual/en/mongodb-driver-server.executereadcommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
diff --git a/src/Operation/CountDocuments.php b/src/Operation/CountDocuments.php
index 6e0e561f9..cc5534d28 100644
--- a/src/Operation/CountDocuments.php
+++ b/src/Operation/CountDocuments.php
@@ -93,7 +93,7 @@ class CountDocuments implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter, array $options = [])
{
if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
@@ -107,8 +107,8 @@ public function __construct($databaseName, $collectionName, $filter, array $opti
throw InvalidArgumentException::invalidType('"skip" option', $options['skip'], 'integer');
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->filter = $filter;
$this->aggregateOptions = array_intersect_key($options, ['collation' => 1, 'comment' => 1, 'hint' => 1, 'maxTimeMS' => 1, 'readConcern' => 1, 'readPreference' => 1, 'session' => 1]);
@@ -121,7 +121,6 @@ public function __construct($databaseName, $collectionName, $filter, array $opti
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return integer
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if collation or read concern is used and unsupported
@@ -146,10 +145,7 @@ public function execute(Server $server)
return (integer) $result->n;
}
- /**
- * @return Aggregate
- */
- private function createAggregate()
+ private function createAggregate(): Aggregate
{
$pipeline = [
['$match' => (object) $this->filter],
diff --git a/src/Operation/CreateCollection.php b/src/Operation/CreateCollection.php
index 61c687730..8860a2889 100644
--- a/src/Operation/CreateCollection.php
+++ b/src/Operation/CreateCollection.php
@@ -142,7 +142,7 @@ class CreateCollection implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, array $options = [])
{
if (isset($options['autoIndexId']) && ! is_bool($options['autoIndexId'])) {
throw InvalidArgumentException::invalidType('"autoIndexId" option', $options['autoIndexId'], 'boolean');
@@ -256,8 +256,8 @@ public function __construct($databaseName, $collectionName, array $options = [])
}
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->options = $options;
}
@@ -265,7 +265,6 @@ public function __construct($databaseName, $collectionName, array $options = [])
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return array|object Command result document
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
@@ -282,10 +281,8 @@ public function execute(Server $server)
/**
* Create the create command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = ['create' => $this->collectionName];
@@ -308,9 +305,8 @@ private function createCommand()
* Create options for executing the command.
*
* @see https://php.net/manual/en/mongodb-driver-server.executewritecommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
diff --git a/src/Operation/CreateIndexes.php b/src/Operation/CreateIndexes.php
index 498b8c1ef..351f25116 100644
--- a/src/Operation/CreateIndexes.php
+++ b/src/Operation/CreateIndexes.php
@@ -84,7 +84,7 @@ class CreateIndexes implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, array $indexes, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, array $indexes, array $options = [])
{
if (empty($indexes)) {
throw new InvalidArgumentException('$indexes is empty');
@@ -126,8 +126,8 @@ public function __construct($databaseName, $collectionName, array $indexes, arra
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->options = $options;
}
@@ -135,7 +135,6 @@ public function __construct($databaseName, $collectionName, array $indexes, arra
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return string[] The names of the created indexes
* @throws UnsupportedException if write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -158,9 +157,8 @@ public function execute(Server $server)
* Create options for executing the command.
*
* @see https://php.net/manual/en/mongodb-driver-server.executewritecommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
@@ -179,10 +177,9 @@ private function createOptions()
* Create one or more indexes for the collection using the createIndexes
* command.
*
- * @param Server $server
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- private function executeCommand(Server $server)
+ private function executeCommand(Server $server): void
{
$cmd = [
'createIndexes' => $this->collectionName,
diff --git a/src/Operation/DatabaseCommand.php b/src/Operation/DatabaseCommand.php
index 317abc658..a0f48fae0 100644
--- a/src/Operation/DatabaseCommand.php
+++ b/src/Operation/DatabaseCommand.php
@@ -65,7 +65,7 @@ class DatabaseCommand implements Executable
* @param array $options Options for command execution
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $command, array $options = [])
+ public function __construct(string $databaseName, $command, array $options = [])
{
if (! is_array($command) && ! is_object($command)) {
throw InvalidArgumentException::invalidType('$command', $command, 'array or object');
@@ -83,7 +83,7 @@ public function __construct($databaseName, $command, array $options = [])
throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
}
- $this->databaseName = (string) $databaseName;
+ $this->databaseName = $databaseName;
$this->command = $command instanceof Command ? $command : new Command($command);
$this->options = $options;
}
@@ -92,7 +92,6 @@ public function __construct($databaseName, $command, array $options = [])
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return Cursor
*/
public function execute(Server $server)
@@ -110,9 +109,8 @@ public function execute(Server $server)
* Create options for executing the command.
*
* @see https://php.net/manual/en/mongodb-driver-server.executecommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
diff --git a/src/Operation/Delete.php b/src/Operation/Delete.php
index 95df96624..7ca197f7a 100644
--- a/src/Operation/Delete.php
+++ b/src/Operation/Delete.php
@@ -97,7 +97,7 @@ class Delete implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter, $limit, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter, int $limit, array $options = [])
{
if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
@@ -131,8 +131,8 @@ public function __construct($databaseName, $collectionName, $filter, $limit, arr
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->filter = $filter;
$this->limit = $limit;
$this->options = $options;
@@ -142,7 +142,6 @@ public function __construct($databaseName, $collectionName, $filter, $limit, arr
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return DeleteResult
* @throws UnsupportedException if hint or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -175,7 +174,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -214,10 +212,8 @@ private function createBulkWriteOptions(): array
*
* Note that these options are different from the bulk write options, which
* are created in createExecuteOptions().
- *
- * @return array
*/
- private function createDeleteOptions()
+ private function createDeleteOptions(): array
{
$deleteOptions = ['limit' => $this->limit];
@@ -236,9 +232,8 @@ private function createDeleteOptions()
* Create options for executing the bulk write.
*
* @see https://php.net/manual/en/mongodb-driver-server.executebulkwrite.php
- * @return array
*/
- private function createExecuteOptions()
+ private function createExecuteOptions(): array
{
$options = [];
diff --git a/src/Operation/DeleteMany.php b/src/Operation/DeleteMany.php
index 3e3a73d0f..33497f3f4 100644
--- a/src/Operation/DeleteMany.php
+++ b/src/Operation/DeleteMany.php
@@ -68,7 +68,7 @@ class DeleteMany implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter, array $options = [])
{
$this->delete = new Delete($databaseName, $collectionName, $filter, 0, $options);
}
@@ -77,7 +77,6 @@ public function __construct($databaseName, $collectionName, $filter, array $opti
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return DeleteResult
* @throws UnsupportedException if collation is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -91,7 +90,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/src/Operation/DeleteOne.php b/src/Operation/DeleteOne.php
index dda930208..a91d67bb5 100644
--- a/src/Operation/DeleteOne.php
+++ b/src/Operation/DeleteOne.php
@@ -68,7 +68,7 @@ class DeleteOne implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter, array $options = [])
{
$this->delete = new Delete($databaseName, $collectionName, $filter, 1, $options);
}
@@ -77,7 +77,6 @@ public function __construct($databaseName, $collectionName, $filter, array $opti
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return DeleteResult
* @throws UnsupportedException if collation is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -91,7 +90,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/src/Operation/Distinct.php b/src/Operation/Distinct.php
index 3298cda89..d957bfc29 100644
--- a/src/Operation/Distinct.php
+++ b/src/Operation/Distinct.php
@@ -86,7 +86,7 @@ class Distinct implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $fieldName, $filter = [], array $options = [])
+ public function __construct(string $databaseName, string $collectionName, string $fieldName, $filter = [], array $options = [])
{
if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
@@ -120,9 +120,9 @@ public function __construct($databaseName, $collectionName, $fieldName, $filter
unset($options['readConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
- $this->fieldName = (string) $fieldName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
+ $this->fieldName = $fieldName;
$this->filter = $filter;
$this->options = $options;
}
@@ -131,8 +131,7 @@ public function __construct($databaseName, $collectionName, $fieldName, $filter
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
- * @return mixed[]
+ * @return array
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if read concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -163,7 +162,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -173,10 +171,8 @@ public function getCommandDocument(Server $server)
/**
* Create the distinct command document.
- *
- * @return array
*/
- private function createCommandDocument()
+ private function createCommandDocument(): array
{
$cmd = [
'distinct' => $this->collectionName,
@@ -204,9 +200,8 @@ private function createCommandDocument()
* Create options for executing the command.
*
* @see https://php.net/manual/en/mongodb-driver-server.executereadcommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
diff --git a/src/Operation/DropCollection.php b/src/Operation/DropCollection.php
index 2ab9b8716..846dca4a7 100644
--- a/src/Operation/DropCollection.php
+++ b/src/Operation/DropCollection.php
@@ -71,7 +71,7 @@ class DropCollection implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, array $options = [])
{
if (isset($options['session']) && ! $options['session'] instanceof Session) {
throw InvalidArgumentException::invalidType('"session" option', $options['session'], Session::class);
@@ -89,8 +89,8 @@ public function __construct($databaseName, $collectionName, array $options = [])
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->options = $options;
}
@@ -98,7 +98,6 @@ public function __construct($databaseName, $collectionName, array $options = [])
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return array|object Command result document
* @throws UnsupportedException if write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -132,10 +131,8 @@ public function execute(Server $server)
/**
* Create the drop command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = ['drop' => $this->collectionName];
@@ -150,9 +147,8 @@ private function createCommand()
* Create options for executing the command.
*
* @see https://php.net/manual/en/mongodb-driver-server.executewritecommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
diff --git a/src/Operation/DropDatabase.php b/src/Operation/DropDatabase.php
index 0e569f068..c909b2436 100644
--- a/src/Operation/DropDatabase.php
+++ b/src/Operation/DropDatabase.php
@@ -63,7 +63,7 @@ class DropDatabase implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, array $options = [])
+ public function __construct(string $databaseName, array $options = [])
{
if (isset($options['session']) && ! $options['session'] instanceof Session) {
throw InvalidArgumentException::invalidType('"session" option', $options['session'], Session::class);
@@ -81,7 +81,7 @@ public function __construct($databaseName, array $options = [])
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
+ $this->databaseName = $databaseName;
$this->options = $options;
}
@@ -89,7 +89,6 @@ public function __construct($databaseName, array $options = [])
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return array|object Command result document
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
@@ -106,10 +105,8 @@ public function execute(Server $server)
/**
* Create the dropDatabase command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = ['dropDatabase' => 1];
@@ -124,9 +121,8 @@ private function createCommand()
* Create options for executing the command.
*
* @see https://php.net/manual/en/mongodb-driver-server.executewritecommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
diff --git a/src/Operation/DropIndexes.php b/src/Operation/DropIndexes.php
index e63be7fd1..ef0e2f4d3 100644
--- a/src/Operation/DropIndexes.php
+++ b/src/Operation/DropIndexes.php
@@ -75,9 +75,9 @@ class DropIndexes implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $indexName, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, string $indexName, array $options = [])
{
- $indexName = (string) $indexName;
+ $indexName = $indexName;
if ($indexName === '') {
throw new InvalidArgumentException('$indexName cannot be empty');
@@ -103,8 +103,8 @@ public function __construct($databaseName, $collectionName, $indexName, array $o
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->indexName = $indexName;
$this->options = $options;
}
@@ -113,7 +113,6 @@ public function __construct($databaseName, $collectionName, $indexName, array $o
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return array|object Command result document
* @throws UnsupportedException if write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -136,10 +135,8 @@ public function execute(Server $server)
/**
* Create the dropIndexes command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = [
'dropIndexes' => $this->collectionName,
@@ -159,9 +156,8 @@ private function createCommand()
* Create options for executing the command.
*
* @see https://php.net/manual/en/mongodb-driver-server.executewritecommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
diff --git a/src/Operation/EstimatedDocumentCount.php b/src/Operation/EstimatedDocumentCount.php
index 5ed9c73b9..6deeef3e5 100644
--- a/src/Operation/EstimatedDocumentCount.php
+++ b/src/Operation/EstimatedDocumentCount.php
@@ -77,10 +77,10 @@ class EstimatedDocumentCount implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, array $options = [])
{
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
@@ -105,7 +105,6 @@ public function __construct($databaseName, $collectionName, array $options = [])
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return integer
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if collation or read concern is used and unsupported
@@ -120,7 +119,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/src/Operation/Executable.php b/src/Operation/Executable.php
index b71b20ba6..5bd8c68b3 100644
--- a/src/Operation/Executable.php
+++ b/src/Operation/Executable.php
@@ -32,7 +32,6 @@ interface Executable
/**
* Execute the operation.
*
- * @param Server $server
* @return mixed
*/
public function execute(Server $server);
diff --git a/src/Operation/Explain.php b/src/Operation/Explain.php
index b6cec43e3..13ae85d09 100644
--- a/src/Operation/Explain.php
+++ b/src/Operation/Explain.php
@@ -78,7 +78,7 @@ class Explain implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, Explainable $explainable, array $options = [])
+ public function __construct(string $databaseName, Explainable $explainable, array $options = [])
{
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], ReadPreference::class);
@@ -105,7 +105,6 @@ public function __construct($databaseName, Explainable $explainable, array $opti
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return array|object
* @throws UnsupportedException if the server does not support explaining the operation
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -127,11 +126,8 @@ public function execute(Server $server)
/**
* Create the explain command.
- *
- * @param Server $server
- * @return Command
*/
- private function createCommand(Server $server)
+ private function createCommand(Server $server): Command
{
$cmd = ['explain' => $this->explainable->getCommandDocument($server)];
@@ -148,9 +144,8 @@ private function createCommand(Server $server)
* Create options for executing the command.
*
* @see https://php.net/manual/en/mongodb-driver-server.executecommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
diff --git a/src/Operation/Explainable.php b/src/Operation/Explainable.php
index 973495235..7647b51ec 100644
--- a/src/Operation/Explainable.php
+++ b/src/Operation/Explainable.php
@@ -30,7 +30,6 @@ interface Explainable extends Executable
/**
* Returns the command document for this operation.
*
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server);
diff --git a/src/Operation/Find.php b/src/Operation/Find.php
index 77e20ba12..619e6f5c5 100644
--- a/src/Operation/Find.php
+++ b/src/Operation/Find.php
@@ -160,7 +160,7 @@ class Find implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter, array $options = [])
{
if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
@@ -292,8 +292,8 @@ public function __construct($databaseName, $collectionName, $filter, array $opti
trigger_error('The "maxScan" option is deprecated and will be removed in a future release', E_USER_DEPRECATED);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->filter = $filter;
$this->options = $options;
}
@@ -302,7 +302,6 @@ public function __construct($databaseName, $collectionName, $filter, array $opti
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return Cursor
* @throws UnsupportedException if read concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -327,7 +326,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -380,9 +378,8 @@ private function createCommandDocument(): array
* Create options for executing the command.
*
* @see https://php.net/manual/en/mongodb-driver-server.executequery.php
- * @return array
*/
- private function createExecuteOptions()
+ private function createExecuteOptions(): array
{
$options = [];
@@ -402,10 +399,8 @@ private function createExecuteOptions()
*
* Note that these are separate from the options for executing the command,
* which are created in createExecuteOptions().
- *
- * @return array
*/
- private function createQueryOptions()
+ private function createQueryOptions(): array
{
$options = [];
diff --git a/src/Operation/FindAndModify.php b/src/Operation/FindAndModify.php
index 290b8205f..c5103a8a0 100644
--- a/src/Operation/FindAndModify.php
+++ b/src/Operation/FindAndModify.php
@@ -129,7 +129,7 @@ class FindAndModify implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, array $options)
+ public function __construct(string $databaseName, string $collectionName, array $options)
{
$options += ['remove' => false];
@@ -209,8 +209,8 @@ public function __construct($databaseName, $collectionName, array $options)
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->options = $options;
}
@@ -218,7 +218,6 @@ public function __construct($databaseName, $collectionName, array $options)
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return array|object|null
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if hint or write concern is used and unsupported
@@ -261,7 +260,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -271,10 +269,8 @@ public function getCommandDocument(Server $server)
/**
* Create the findAndModify command document.
- *
- * @return array
*/
- private function createCommandDocument()
+ private function createCommandDocument(): array
{
$cmd = ['findAndModify' => $this->collectionName];
@@ -315,9 +311,8 @@ private function createCommandDocument()
* Create options for executing the command.
*
* @see https://php.net/manual/en/mongodb-driver-server.executewritecommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
diff --git a/src/Operation/FindOne.php b/src/Operation/FindOne.php
index b75edcb1e..3de70dae6 100644
--- a/src/Operation/FindOne.php
+++ b/src/Operation/FindOne.php
@@ -103,7 +103,7 @@ class FindOne implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter, array $options = [])
{
$this->find = new Find(
$databaseName,
@@ -117,7 +117,6 @@ public function __construct($databaseName, $collectionName, $filter, array $opti
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return array|object|null
* @throws UnsupportedException if collation or read concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -134,7 +133,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/src/Operation/FindOneAndDelete.php b/src/Operation/FindOneAndDelete.php
index 03fd6e1a7..c4b54dadf 100644
--- a/src/Operation/FindOneAndDelete.php
+++ b/src/Operation/FindOneAndDelete.php
@@ -81,7 +81,7 @@ class FindOneAndDelete implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter, array $options = [])
{
if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
@@ -108,7 +108,6 @@ public function __construct($databaseName, $collectionName, $filter, array $opti
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return array|object|null
* @throws UnsupportedException if collation or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -122,7 +121,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/src/Operation/FindOneAndReplace.php b/src/Operation/FindOneAndReplace.php
index dce8a6a97..0e619b86d 100644
--- a/src/Operation/FindOneAndReplace.php
+++ b/src/Operation/FindOneAndReplace.php
@@ -100,7 +100,7 @@ class FindOneAndReplace implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter, $replacement, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter, $replacement, array $options = [])
{
if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
@@ -151,7 +151,6 @@ public function __construct($databaseName, $collectionName, $filter, $replacemen
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return array|object|null
* @throws UnsupportedException if collation or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -165,7 +164,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/src/Operation/FindOneAndUpdate.php b/src/Operation/FindOneAndUpdate.php
index 98b6cf42c..e9a592473 100644
--- a/src/Operation/FindOneAndUpdate.php
+++ b/src/Operation/FindOneAndUpdate.php
@@ -104,7 +104,7 @@ class FindOneAndUpdate implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter, $update, array $options = [])
{
if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
@@ -155,7 +155,6 @@ public function __construct($databaseName, $collectionName, $filter, $update, ar
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return array|object|null
* @throws UnsupportedException if collation or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -169,7 +168,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/src/Operation/InsertMany.php b/src/Operation/InsertMany.php
index af7bd7361..b8b3c1255 100644
--- a/src/Operation/InsertMany.php
+++ b/src/Operation/InsertMany.php
@@ -79,7 +79,7 @@ class InsertMany implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, array $documents, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, array $documents, array $options = [])
{
if (empty($documents)) {
throw new InvalidArgumentException('$documents is empty');
@@ -125,8 +125,8 @@ public function __construct($databaseName, $collectionName, array $documents, ar
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->documents = $documents;
$this->options = $options;
}
@@ -135,7 +135,6 @@ public function __construct($databaseName, $collectionName, array $documents, ar
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return InsertManyResult
* @throws UnsupportedException if write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -163,9 +162,8 @@ public function execute(Server $server)
* Create options for constructing the bulk write.
*
* @see https://php.net/manual/en/mongodb-driver-bulkwrite.construct.php
- * @return array
*/
- private function createBulkWriteOptions()
+ private function createBulkWriteOptions(): array
{
$options = ['ordered' => $this->options['ordered']];
@@ -182,9 +180,8 @@ private function createBulkWriteOptions()
* Create options for executing the bulk write.
*
* @see https://php.net/manual/en/mongodb-driver-server.executebulkwrite.php
- * @return array
*/
- private function createExecuteOptions()
+ private function createExecuteOptions(): array
{
$options = [];
diff --git a/src/Operation/InsertOne.php b/src/Operation/InsertOne.php
index 9398f1795..d0690a5d5 100644
--- a/src/Operation/InsertOne.php
+++ b/src/Operation/InsertOne.php
@@ -73,7 +73,7 @@ class InsertOne implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $document, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $document, array $options = [])
{
if (! is_array($document) && ! is_object($document)) {
throw InvalidArgumentException::invalidType('$document', $document, 'array or object');
@@ -99,8 +99,8 @@ public function __construct($databaseName, $collectionName, $document, array $op
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->document = $document;
$this->options = $options;
}
@@ -109,7 +109,6 @@ public function __construct($databaseName, $collectionName, $document, array $op
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return InsertOneResult
* @throws UnsupportedException if write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -133,9 +132,8 @@ public function execute(Server $server)
* Create options for constructing the bulk write.
*
* @see https://php.net/manual/en/mongodb-driver-bulkwrite.construct.php
- * @return array
*/
- private function createBulkWriteOptions()
+ private function createBulkWriteOptions(): array
{
$options = [];
@@ -152,9 +150,8 @@ private function createBulkWriteOptions()
* Create options for executing the bulk write.
*
* @see https://php.net/manual/en/mongodb-driver-server.executebulkwrite.php
- * @return array
*/
- private function createExecuteOptions()
+ private function createExecuteOptions(): array
{
$options = [];
diff --git a/src/Operation/ListCollectionNames.php b/src/Operation/ListCollectionNames.php
index 4bc5565a3..d0700887b 100644
--- a/src/Operation/ListCollectionNames.php
+++ b/src/Operation/ListCollectionNames.php
@@ -61,7 +61,7 @@ class ListCollectionNames implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, array $options = [])
+ public function __construct(string $databaseName, array $options = [])
{
$this->listCollections = new ListCollectionsCommand($databaseName, ['nameOnly' => true] + $options);
}
@@ -70,7 +70,6 @@ public function __construct($databaseName, array $options = [])
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return Iterator
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
diff --git a/src/Operation/ListCollections.php b/src/Operation/ListCollections.php
index 8a55f9908..e5702509b 100644
--- a/src/Operation/ListCollections.php
+++ b/src/Operation/ListCollections.php
@@ -64,9 +64,9 @@ class ListCollections implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, array $options = [])
+ public function __construct(string $databaseName, array $options = [])
{
- $this->databaseName = (string) $databaseName;
+ $this->databaseName = $databaseName;
$this->listCollections = new ListCollectionsCommand($databaseName, ['nameOnly' => false] + $options);
}
@@ -74,7 +74,6 @@ public function __construct($databaseName, array $options = [])
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return CollectionInfoIterator
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
diff --git a/src/Operation/ListDatabaseNames.php b/src/Operation/ListDatabaseNames.php
index 950c82b7c..ccace38f8 100644
--- a/src/Operation/ListDatabaseNames.php
+++ b/src/Operation/ListDatabaseNames.php
@@ -72,8 +72,6 @@ public function __construct(array $options = [])
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
- * @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/ListDatabases.php b/src/Operation/ListDatabases.php
index 6b0c4ba2c..a19cf07bb 100644
--- a/src/Operation/ListDatabases.php
+++ b/src/Operation/ListDatabases.php
@@ -70,7 +70,6 @@ public function __construct(array $options = [])
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return DatabaseInfoIterator
* @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 b6e8a1ea0..e762d9ca2 100644
--- a/src/Operation/ListIndexes.php
+++ b/src/Operation/ListIndexes.php
@@ -73,7 +73,7 @@ class ListIndexes implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, array $options = [])
{
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
@@ -83,8 +83,8 @@ public function __construct($databaseName, $collectionName, array $options = [])
throw InvalidArgumentException::invalidType('"session" option', $options['session'], Session::class);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->options = $options;
}
@@ -92,7 +92,6 @@ public function __construct($databaseName, $collectionName, array $options = [])
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return IndexInfoIterator
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
@@ -108,9 +107,8 @@ public function execute(Server $server)
* the command be executed on the primary.
*
* @see https://php.net/manual/en/mongodb-driver-server.executecommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
@@ -125,11 +123,9 @@ private function createOptions()
* Returns information for all indexes for this collection using the
* listIndexes command.
*
- * @param Server $server
- * @return IndexInfoIteratorIterator
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- private function executeCommand(Server $server)
+ private function executeCommand(Server $server): IndexInfoIteratorIterator
{
$cmd = ['listIndexes' => $this->collectionName];
diff --git a/src/Operation/MapReduce.php b/src/Operation/MapReduce.php
index b1e8319ce..97e22f080 100644
--- a/src/Operation/MapReduce.php
+++ b/src/Operation/MapReduce.php
@@ -158,7 +158,7 @@ class MapReduce implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, JavascriptInterface $map, JavascriptInterface $reduce, $out, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, JavascriptInterface $map, JavascriptInterface $reduce, $out, array $options = [])
{
if (! is_string($out) && ! is_array($out) && ! is_object($out)) {
throw InvalidArgumentException::invalidType('$out', $out, 'string or array or object');
@@ -251,8 +251,8 @@ public function __construct($databaseName, $collectionName, JavascriptInterface
$this->checkOutDeprecations($out);
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->map = $map;
$this->reduce = $reduce;
$this->out = $out;
@@ -263,7 +263,6 @@ public function __construct($databaseName, $collectionName, JavascriptInterface
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return MapReduceResult
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if read concern or write concern is used and unsupported
@@ -310,9 +309,8 @@ public function execute(Server $server)
/**
* @param string|array|object $out
- * @return void
*/
- private function checkOutDeprecations($out)
+ private function checkOutDeprecations($out): void
{
if (is_string($out)) {
return;
@@ -331,10 +329,8 @@ private function checkOutDeprecations($out)
/**
* Create the mapReduce command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = [
'mapReduce' => $this->collectionName,
@@ -361,12 +357,9 @@ private function createCommand()
/**
* Creates a callable for MapReduceResult::getIterator().
*
- * @param stdClass $result
- * @param Server $server
- * @return callable
* @throws UnexpectedValueException if the command response was malformed
*/
- private function createGetIteratorCallable(stdClass $result, Server $server)
+ private function createGetIteratorCallable(stdClass $result, Server $server): callable
{
// Inline results can be wrapped with an ArrayIterator
if (isset($result->results) && is_array($result->results)) {
@@ -397,10 +390,8 @@ private function createGetIteratorCallable(stdClass $result, Server $server)
*
* @see https://php.net/manual/en/mongodb-driver-server.executereadcommand.php
* @see https://php.net/manual/en/mongodb-driver-server.executereadwritecommand.php
- * @param boolean $hasOutputCollection
- * @return array
*/
- private function createOptions($hasOutputCollection)
+ private function createOptions(bool $hasOutputCollection): array
{
$options = [];
diff --git a/src/Operation/ModifyCollection.php b/src/Operation/ModifyCollection.php
index cd52cb9a0..7933859bf 100644
--- a/src/Operation/ModifyCollection.php
+++ b/src/Operation/ModifyCollection.php
@@ -70,7 +70,7 @@ class ModifyCollection implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, array $collectionOptions, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, array $collectionOptions, array $options = [])
{
if (empty($collectionOptions)) {
throw new InvalidArgumentException('$collectionOptions is empty');
@@ -92,8 +92,8 @@ public function __construct($databaseName, $collectionName, array $collectionOpt
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->collectionOptions = $collectionOptions;
$this->options = $options;
}
@@ -102,7 +102,6 @@ public function __construct($databaseName, $collectionName, array $collectionOpt
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return array|object Command result document
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
@@ -132,9 +131,8 @@ private function createCommand(): Command
* Create options for executing the command.
*
* @see https://php.net/manual/en/mongodb-driver-server.executewritecommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
diff --git a/src/Operation/RenameCollection.php b/src/Operation/RenameCollection.php
index e489713a3..815428132 100644
--- a/src/Operation/RenameCollection.php
+++ b/src/Operation/RenameCollection.php
@@ -104,7 +104,6 @@ public function __construct(string $fromDatabaseName, string $fromCollectionName
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return array|object Command result document
* @throws UnsupportedException if write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -127,10 +126,8 @@ public function execute(Server $server)
/**
* Create the renameCollection command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = [
'renameCollection' => $this->fromNamespace,
@@ -150,9 +147,8 @@ private function createCommand()
* Create options for executing the command.
*
* @see https://php.net/manual/en/mongodb-driver-server.executewritecommand.php
- * @return array
*/
- private function createOptions()
+ private function createOptions(): array
{
$options = [];
diff --git a/src/Operation/ReplaceOne.php b/src/Operation/ReplaceOne.php
index ef7575ddc..d5d117b91 100644
--- a/src/Operation/ReplaceOne.php
+++ b/src/Operation/ReplaceOne.php
@@ -80,7 +80,7 @@ class ReplaceOne implements Executable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter, $replacement, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter, $replacement, array $options = [])
{
if (! is_array($replacement) && ! is_object($replacement)) {
throw InvalidArgumentException::invalidType('$replacement', $replacement, 'array or object');
@@ -107,7 +107,6 @@ public function __construct($databaseName, $collectionName, $filter, $replacemen
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return UpdateResult
* @throws UnsupportedException if collation is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
diff --git a/src/Operation/Update.php b/src/Operation/Update.php
index 6ec9a2ac5..96a51c53f 100644
--- a/src/Operation/Update.php
+++ b/src/Operation/Update.php
@@ -112,7 +112,7 @@ class Update implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter, $update, array $options = [])
{
if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
@@ -175,8 +175,8 @@ public function __construct($databaseName, $collectionName, $filter, $update, ar
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->filter = $filter;
$this->update = $update;
$this->options = $options;
@@ -186,7 +186,6 @@ public function __construct($databaseName, $collectionName, $filter, $update, ar
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return UpdateResult
* @throws UnsupportedException if hint or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -219,7 +218,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -241,9 +239,8 @@ public function getCommandDocument(Server $server)
* Create options for constructing the bulk write.
*
* @see https://php.net/manual/en/mongodb-driver-bulkwrite.construct.php
- * @return array
*/
- private function createBulkWriteOptions()
+ private function createBulkWriteOptions(): array
{
$options = [];
@@ -264,9 +261,8 @@ private function createBulkWriteOptions()
* Create options for executing the bulk write.
*
* @see https://php.net/manual/en/mongodb-driver-server.executebulkwrite.php
- * @return array
*/
- private function createExecuteOptions()
+ private function createExecuteOptions(): array
{
$options = [];
@@ -286,10 +282,8 @@ private function createExecuteOptions()
*
* Note that these options are different from the bulk write options, which
* are created in createExecuteOptions().
- *
- * @return array
*/
- private function createUpdateOptions()
+ private function createUpdateOptions(): array
{
$updateOptions = [
'multi' => $this->options['multi'],
diff --git a/src/Operation/UpdateMany.php b/src/Operation/UpdateMany.php
index 27a6955ad..e442365a1 100644
--- a/src/Operation/UpdateMany.php
+++ b/src/Operation/UpdateMany.php
@@ -83,7 +83,7 @@ class UpdateMany implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter, $update, array $options = [])
{
if (! is_array($update) && ! is_object($update)) {
throw InvalidArgumentException::invalidType('$update', $update, 'array or object');
@@ -106,7 +106,6 @@ public function __construct($databaseName, $collectionName, $filter, $update, ar
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return UpdateResult
* @throws UnsupportedException if collation is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -120,7 +119,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/src/Operation/UpdateOne.php b/src/Operation/UpdateOne.php
index 22a01e2a0..a7bfab518 100644
--- a/src/Operation/UpdateOne.php
+++ b/src/Operation/UpdateOne.php
@@ -83,7 +83,7 @@ class UpdateOne implements Executable, Explainable
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
+ public function __construct(string $databaseName, string $collectionName, $filter, $update, array $options = [])
{
if (! is_array($update) && ! is_object($update)) {
throw InvalidArgumentException::invalidType('$update', $update, 'array or object');
@@ -106,7 +106,6 @@ public function __construct($databaseName, $collectionName, $filter, $update, ar
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return UpdateResult
* @throws UnsupportedException if collation is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -120,7 +119,6 @@ public function execute(Server $server)
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/src/Operation/Watch.php b/src/Operation/Watch.php
index 3daf2d26a..a188ba774 100644
--- a/src/Operation/Watch.php
+++ b/src/Operation/Watch.php
@@ -201,7 +201,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
* @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function __construct(Manager $manager, $databaseName, $collectionName, array $pipeline, array $options = [])
+ public function __construct(Manager $manager, ?string $databaseName, ?string $collectionName, array $pipeline, array $options = [])
{
if (isset($collectionName) && ! isset($databaseName)) {
throw new InvalidArgumentException('$collectionName should also be null if $databaseName is null');
@@ -263,8 +263,8 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
}
$this->manager = $manager;
- $this->databaseName = (string) $databaseName;
- $this->collectionName = isset($collectionName) ? (string) $collectionName : null;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->pipeline = $pipeline;
$this->aggregate = $this->createAggregate();
@@ -317,7 +317,6 @@ final public function commandSucceeded(CommandSucceededEvent $event): void
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return ChangeStream
* @throws UnsupportedException if collation or read concern is used and unsupported
* @throws RuntimeException for other driver errors (e.g. connection errors)
@@ -336,10 +335,8 @@ function ($resumeToken, $hasAdvanced) {
* Create the aggregate command for a change stream.
*
* This method is also used to recreate the aggregate command when resuming.
- *
- * @return Aggregate
*/
- private function createAggregate()
+ private function createAggregate(): Aggregate
{
$pipeline = $this->pipeline;
array_unshift($pipeline, ['$changeStream' => (object) $this->changeStreamOptions]);
@@ -349,11 +346,8 @@ private function createAggregate()
/**
* Create a ChangeStreamIterator by executing the aggregate command.
- *
- * @param Server $server
- * @return ChangeStreamIterator
*/
- private function createChangeStreamIterator(Server $server)
+ private function createChangeStreamIterator(Server $server): ChangeStreamIterator
{
return new ChangeStreamIterator(
$this->executeAggregate($server),
@@ -368,11 +362,8 @@ private function createChangeStreamIterator(Server $server)
*
* The command will be executed using APM so that we can capture data from
* its response (e.g. firstBatch size, postBatchResumeToken).
- *
- * @param Server $server
- * @return Cursor
*/
- private function executeAggregate(Server $server)
+ private function executeAggregate(Server $server): Cursor
{
addSubscriber($this);
@@ -411,11 +402,9 @@ private function getInitialResumeToken()
*
* @see https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.rst#resume-process
* @param array|object|null $resumeToken
- * @param bool $hasAdvanced
- * @return ChangeStreamIterator
* @throws InvalidArgumentException
*/
- private function resume($resumeToken = null, $hasAdvanced = false)
+ private function resume($resumeToken = null, bool $hasAdvanced = false): ChangeStreamIterator
{
if (isset($resumeToken) && ! is_array($resumeToken) && ! is_object($resumeToken)) {
throw InvalidArgumentException::invalidType('$resumeToken', $resumeToken, 'array or object');
@@ -453,10 +442,8 @@ private function resume($resumeToken = null, $hasAdvanced = false)
* Determine whether to capture operation time from an aggregate response.
*
* @see https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.rst#startatoperationtime
- * @param Server $server
- * @return boolean
*/
- private function shouldCaptureOperationTime(Server $server)
+ private function shouldCaptureOperationTime(Server $server): bool
{
if ($this->hasResumed) {
return false;
diff --git a/src/Operation/WithTransaction.php b/src/Operation/WithTransaction.php
index 6278972dd..e31b01b9e 100644
--- a/src/Operation/WithTransaction.php
+++ b/src/Operation/WithTransaction.php
@@ -52,11 +52,10 @@ public function __construct(callable $callback, array $transactionOptions = [])
* @see Client::startSession
*
* @param Session $session A session object as retrieved by Client::startSession
- * @return void
* @throws RuntimeException for driver errors while committing the transaction
* @throws Exception for any other errors, including those thrown in the callback
*/
- public function execute(Session $session)
+ public function execute(Session $session): void
{
$startTime = time();
@@ -123,9 +122,8 @@ public function execute(Session $session)
* Returns whether the time limit for retrying transactions in the convenient transaction API has passed
*
* @param int $startTime The time the transaction was started
- * @return bool
*/
- private function isTransactionTimeLimitExceeded($startTime)
+ private function isTransactionTimeLimitExceeded(int $startTime): bool
{
return time() - $startTime >= 120;
}
diff --git a/src/functions.php b/src/functions.php
index c0ab80e9a..042bee19f 100644
--- a/src/functions.php
+++ b/src/functions.php
@@ -98,7 +98,6 @@ function apply_type_map_to_document($document, array $typeMap)
* @internal
* @param array|object $document Document containing fields mapped to values,
* which denote order or an index type
- * @return string
* @throws InvalidArgumentException
*/
function generate_index_name($document): string
@@ -178,7 +177,6 @@ function get_encrypted_fields_from_server(string $databaseName, string $collecti
*
* @internal
* @param array|object $document Update or replacement document
- * @return boolean
* @throws InvalidArgumentException
*/
function is_first_key_operator($document): bool
@@ -206,7 +204,6 @@ function is_first_key_operator($document): bool
*
* @internal
* @param mixed $pipeline
- * @return boolean
*/
function is_pipeline($pipeline): bool
{
@@ -247,7 +244,6 @@ function is_pipeline($pipeline): bool
*
* @internal
* @param array $options Command options
- * @return boolean
*/
function is_in_transaction(array $options): bool
{
@@ -266,7 +262,6 @@ function is_in_transaction(array $options): bool
*
* @internal
* @param array $pipeline List of pipeline operations
- * @return boolean
*/
function is_last_pipeline_operator_write(array $pipeline): bool
{
@@ -289,7 +284,6 @@ function is_last_pipeline_operator_write(array $pipeline): bool
* @internal
* @see https://mongodb.com/docs/manual/reference/command/mapReduce/#output-inline
* @param string|array|object $out Output specification
- * @return boolean
* @throws InvalidArgumentException
*/
function is_mapreduce_output_inline($out): bool
@@ -323,8 +317,6 @@ function is_mapreduce_output_inline($out): bool
*
* @internal
* @see https://mongodb.com/docs/manual/reference/write-concern/
- * @param WriteConcern $writeConcern
- * @return boolean
*/
function is_write_concern_acknowledged(WriteConcern $writeConcern): bool
{
@@ -340,7 +332,6 @@ function is_write_concern_acknowledged(WriteConcern $writeConcern): bool
* @internal
* @param Server $server Server to check
* @param integer $feature Feature constant (i.e. wire protocol version)
- * @return boolean
*/
function server_supports_feature(Server $server, int $feature): bool
{
@@ -356,7 +347,6 @@ function server_supports_feature(Server $server, int $feature): bool
*
* @internal
* @param mixed $input
- * @return boolean
*/
function is_string_array($input): bool
{
@@ -417,7 +407,6 @@ function recursive_copy($element)
* @internal
* @param array $typeMap The existing typeMap
* @param string $fieldPath The field path to apply the root type to
- * @return array
*/
function create_field_path_type_map(array $typeMap, string $fieldPath): array
{
@@ -470,11 +459,10 @@ function create_field_path_type_map(array $typeMap, string $fieldPath): array
* @param Session $session A session object as retrieved by Client::startSession
* @param callable $callback A callback that will be invoked within the transaction
* @param array $transactionOptions Additional options that are passed to Session::startTransaction
- * @return void
* @throws RuntimeException for driver errors while committing the transaction
* @throws Exception for any other errors, including those thrown in the callback
*/
-function with_transaction(Session $session, callable $callback, array $transactionOptions = [])
+function with_transaction(Session $session, callable $callback, array $transactionOptions = []): void
{
$operation = new WithTransaction($callback, $transactionOptions);
$operation->execute($session);
@@ -484,8 +472,6 @@ function with_transaction(Session $session, callable $callback, array $transacti
* Returns the session option if it is set and valid.
*
* @internal
- * @param array $options
- * @return Session|null
*/
function extract_session_from_options(array $options): ?Session
{
@@ -500,8 +486,6 @@ function extract_session_from_options(array $options): ?Session
* Returns the readPreference option if it is set and valid.
*
* @internal
- * @param array $options
- * @return ReadPreference|null
*/
function extract_read_preference_from_options(array $options): ?ReadPreference
{
@@ -517,7 +501,6 @@ function extract_read_preference_from_options(array $options): ?ReadPreference
* (if given)
*
* @internal
- * @return Server
*/
function select_server(Manager $manager, array $options): Server
{
diff --git a/tests/ClientFunctionalTest.php b/tests/ClientFunctionalTest.php
index a51b90d60..6535c66da 100644
--- a/tests/ClientFunctionalTest.php
+++ b/tests/ClientFunctionalTest.php
@@ -91,9 +91,6 @@ public function testListDatabaseNames(): void
* argument as its first and only parameter. If a DatabaseInfo matching
* the given name is found, it will be passed to the callback, which may
* perform additional assertions.
- *
- * @param string $databaseName
- * @param callable $callback
*/
private function assertDatabaseExists(string $databaseName, ?callable $callback = null): void
{
diff --git a/tests/Collection/CollectionFunctionalTest.php b/tests/Collection/CollectionFunctionalTest.php
index e1e9fc982..cd687bc0e 100644
--- a/tests/Collection/CollectionFunctionalTest.php
+++ b/tests/Collection/CollectionFunctionalTest.php
@@ -15,6 +15,7 @@
use MongoDB\MapReduceResult;
use MongoDB\Operation\Count;
use MongoDB\Tests\CommandObserver;
+use TypeError;
use function array_filter;
use function call_user_func;
@@ -32,9 +33,9 @@ class CollectionFunctionalTest extends FunctionalTestCase
/**
* @dataProvider provideInvalidDatabaseAndCollectionNames
*/
- public function testConstructorDatabaseNameArgument($databaseName): void
+ public function testConstructorDatabaseNameArgument($databaseName, string $expectedExceptionClass): void
{
- $this->expectException(InvalidArgumentException::class);
+ $this->expectException($expectedExceptionClass);
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
new Collection($this->manager, $databaseName, $this->getCollectionName());
}
@@ -42,9 +43,9 @@ public function testConstructorDatabaseNameArgument($databaseName): void
/**
* @dataProvider provideInvalidDatabaseAndCollectionNames
*/
- public function testConstructorCollectionNameArgument($collectionName): void
+ public function testConstructorCollectionNameArgument($collectionName, string $expectedExceptionClass): void
{
- $this->expectException(InvalidArgumentException::class);
+ $this->expectException($expectedExceptionClass);
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
new Collection($this->manager, $this->getDatabaseName(), $collectionName);
}
@@ -52,8 +53,8 @@ public function testConstructorCollectionNameArgument($collectionName): void
public function provideInvalidDatabaseAndCollectionNames()
{
return [
- [null],
- [''],
+ [null, TypeError::class],
+ ['', InvalidArgumentException::class],
];
}
@@ -805,9 +806,6 @@ public function testMethodInTransactionWithReadConcernOption($method): void
/**
* Create data fixtures.
- *
- * @param integer $n
- * @param array $executeBulkWriteOptions
*/
private function createFixtures(int $n, array $executeBulkWriteOptions = []): void
{
diff --git a/tests/Collection/CrudSpecFunctionalTest.php b/tests/Collection/CrudSpecFunctionalTest.php
index f1cc519b6..4bb7ac174 100644
--- a/tests/Collection/CrudSpecFunctionalTest.php
+++ b/tests/Collection/CrudSpecFunctionalTest.php
@@ -107,9 +107,6 @@ public function provideSpecificationTests()
/**
* Assert that the collections contain equivalent documents.
- *
- * @param Collection $expectedCollection
- * @param Collection $actualCollection
*/
private function assertEquivalentCollections(Collection $expectedCollection, Collection $actualCollection): void
{
@@ -152,8 +149,6 @@ private function checkServerlessRequirement(?string $serverless): void
/**
* Checks that the server version is within the allowed bounds (if any).
*
- * @param string|null $minServerVersion
- * @param string|null $maxServerVersion
* @throws PHPUnit_Framework_SkippedTestError
*/
private function checkServerVersion(?string $minServerVersion, ?string $maxServerVersion): void
@@ -172,7 +167,6 @@ private function checkServerVersion(?string $minServerVersion, ?string $maxServe
/**
* Executes an "operation" block.
*
- * @param array $operation
* @return mixed
* @throws LogicException if the operation is unsupported
*/
@@ -260,10 +254,7 @@ private function executeOperation(array $operation)
/**
* Executes an "outcome" block.
*
- * @param array $operation
- * @param array $outcome
- * @param mixed $result
- * @param RuntimeException $exception
+ * @param mixed $result
* @return mixed
* @throws LogicException if the operation is unsupported
*/
@@ -300,8 +291,6 @@ private function executeOutcome(array $operation, array $outcome, $result, ?Runt
*
* If no result can be extracted, null will be returned.
*
- * @param array $operation
- * @param RuntimeException $exception
* @return mixed
*/
private function extractResultFromException(array $operation, array $outcome, RuntimeException $exception)
@@ -332,7 +321,6 @@ private function extractResultFromException(array $operation, array $outcome, Ru
/**
* Executes the "result" section of an "outcome" block.
*
- * @param array $operation
* @param mixed $expectedResult
* @param mixed $actualResult
* @throws LogicException if the operation is unsupported
@@ -498,9 +486,6 @@ private function executeAssertResult(array $operation, $expectedResult, $actualR
/**
* Initializes data in the test collections.
- *
- * @param array $initialData
- * @param array $expectedData
*/
private function initializeData(array $initialData, ?array $expectedData = null): void
{
@@ -515,9 +500,6 @@ private function initializeData(array $initialData, ?array $expectedData = null)
/**
* Prepares a request element for a bulkWrite operation.
- *
- * @param array $request
- * @return array
*/
private function prepareBulkWriteRequest(array $request): array
{
@@ -560,9 +542,6 @@ private function prepareBulkWriteRequest(array $request): array
/**
* Prepares arguments for findOneAndReplace and findOneAndUpdate operations.
- *
- * @param array $arguments
- * @return array
*/
private function prepareFindAndModifyArguments(array $arguments): array
{
diff --git a/tests/Database/DatabaseFunctionalTest.php b/tests/Database/DatabaseFunctionalTest.php
index 180762384..6eb2f9fd1 100644
--- a/tests/Database/DatabaseFunctionalTest.php
+++ b/tests/Database/DatabaseFunctionalTest.php
@@ -11,6 +11,7 @@
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\CreateIndexes;
+use TypeError;
use function array_key_exists;
use function current;
@@ -23,9 +24,9 @@ class DatabaseFunctionalTest extends FunctionalTestCase
/**
* @dataProvider provideInvalidDatabaseNames
*/
- public function testConstructorDatabaseNameArgument($databaseName): void
+ public function testConstructorDatabaseNameArgument($databaseName, string $expectedExceptionClass): void
{
- $this->expectException(InvalidArgumentException::class);
+ $this->expectException($expectedExceptionClass);
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
new Database($this->manager, $databaseName);
}
@@ -33,8 +34,8 @@ public function testConstructorDatabaseNameArgument($databaseName): void
public function provideInvalidDatabaseNames()
{
return [
- [null],
- [''],
+ [null, TypeError::class],
+ ['', InvalidArgumentException::class],
];
}
diff --git a/tests/DocumentationExamplesTest.php b/tests/DocumentationExamplesTest.php
index 23ac8b50f..d766ed8ea 100644
--- a/tests/DocumentationExamplesTest.php
+++ b/tests/DocumentationExamplesTest.php
@@ -1958,8 +1958,6 @@ public function testQueryableEncryption(): void
/**
* Return the test collection name.
- *
- * @return string
*/
protected function getCollectionName(): string
{
diff --git a/tests/FunctionalTestCase.php b/tests/FunctionalTestCase.php
index 36992c965..6dd6b348e 100644
--- a/tests/FunctionalTestCase.php
+++ b/tests/FunctionalTestCase.php
@@ -305,8 +305,6 @@ public static function getModuleInfo(string $row): ?string
* If the "writeConcern" option is not specified but is supported by the
* server, a majority write concern will be used. This is helpful for tests
* using transactions or secondary reads.
- *
- * @param array $options
*/
protected function createCollection(array $options = []): void
{
@@ -322,8 +320,6 @@ protected function createCollection(array $options = []): void
* If the "writeConcern" option is not specified but is supported by the
* server, a majority write concern will be used. This is helpful for tests
* using transactions or secondary reads.
- *
- * @param array $options
*/
protected function dropCollection(array $options = []): void
{
@@ -615,8 +611,6 @@ private function disableFailPoints(): void
/**
* Checks if the failCommand command is supported on this server version
- *
- * @return bool
*/
private function isFailCommandSupported(): bool
{
@@ -627,8 +621,6 @@ private function isFailCommandSupported(): bool
/**
* Checks if the failCommand command is enabled by checking the enableTestCommands parameter
- *
- * @return bool
*/
private function isFailCommandEnabled(): bool
{
diff --git a/tests/GridFS/BucketFunctionalTest.php b/tests/GridFS/BucketFunctionalTest.php
index f00e23049..c59f4c128 100644
--- a/tests/GridFS/BucketFunctionalTest.php
+++ b/tests/GridFS/BucketFunctionalTest.php
@@ -782,10 +782,6 @@ public function testDanglingOpenWritableStream(): void
* argument as its first and only parameter. If an IndexInfo matching the
* given name is found, it will be passed to the callback, which may perform
* additional assertions.
- *
- * @param string $collectionName
- * @param string $indexName
- * @param callable $callback
*/
private function assertIndexExists(string $collectionName, string $indexName, ?callable $callback = null): void
{
@@ -814,9 +810,6 @@ private function assertIndexExists(string $collectionName, string $indexName, ?c
/**
* Asserts that an index with the given name does not exist for the collection.
- *
- * @param string $collectionName
- * @param string $indexName
*/
private function assertIndexNotExists(string $collectionName, string $indexName): void
{
@@ -837,8 +830,6 @@ private function assertIndexNotExists(string $collectionName, string $indexName)
/**
* Return a list of invalid stream values.
- *
- * @return array
*/
private function getInvalidStreamValues(): array
{
diff --git a/tests/GridFS/FunctionalTestCase.php b/tests/GridFS/FunctionalTestCase.php
index 5c2b8f45e..d78b1e6b1 100644
--- a/tests/GridFS/FunctionalTestCase.php
+++ b/tests/GridFS/FunctionalTestCase.php
@@ -42,7 +42,6 @@ public function setUp(): void
*
* Note: this will seek to the beginning of the stream before reading.
*
- * @param string $expectedContents
* @param resource $stream
*/
protected function assertStreamContents(string $expectedContents, $stream): void
@@ -55,7 +54,6 @@ protected function assertStreamContents(string $expectedContents, $stream): void
/**
* Creates an in-memory stream with the given data.
*
- * @param string $data
* @return resource
*/
protected function createStream(string $data = '')
diff --git a/tests/Model/ChangeStreamIteratorTest.php b/tests/Model/ChangeStreamIteratorTest.php
index af3f0bdf6..9be703bab 100644
--- a/tests/Model/ChangeStreamIteratorTest.php
+++ b/tests/Model/ChangeStreamIteratorTest.php
@@ -1,5 +1,10 @@
expectException(InvalidArgumentException::class);
+ $this->expectException(TypeError::class);
new ChangeStreamIterator($this->collection->find(), $firstBatchSize, null, null);
}
- public function provideInvalidIntegerValues()
- {
- return $this->wrapValuesForDataProvider($this->getInvalidIntegerValues());
- }
-
public function testInitialResumeToken(): void
{
$iterator = new ChangeStreamIterator($this->collection->find(), 0, null, null);
@@ -73,7 +74,7 @@ public function testInitialResumeTokenArgumentTypeCheck($initialResumeToken): vo
*/
public function testPostBatchResumeTokenArgumentTypeCheck($postBatchResumeToken): void
{
- $this->expectException(InvalidArgumentException::class);
+ $this->expectException(TypeError::class);
new ChangeStreamIterator($this->collection->find(), 0, null, $postBatchResumeToken);
}
diff --git a/tests/Operation/AggregateFunctionalTest.php b/tests/Operation/AggregateFunctionalTest.php
index d300fd57b..d8b6c13af 100644
--- a/tests/Operation/AggregateFunctionalTest.php
+++ b/tests/Operation/AggregateFunctionalTest.php
@@ -339,9 +339,6 @@ public function testReadPreferenceWithinTransaction(): void
/**
* Create data fixtures.
- *
- * @param integer $n
- * @param array $executeBulkWriteOptions
*/
private function createFixtures(int $n, array $executeBulkWriteOptions = []): void
{
diff --git a/tests/Operation/BulkWriteFunctionalTest.php b/tests/Operation/BulkWriteFunctionalTest.php
index dd0a18eaf..b935e5501 100644
--- a/tests/Operation/BulkWriteFunctionalTest.php
+++ b/tests/Operation/BulkWriteFunctionalTest.php
@@ -313,8 +313,6 @@ public function testBulkWriteWithPipelineUpdates(): void
/**
* Create data fixtures.
- *
- * @param integer $n
*/
private function createFixtures(int $n): void
{
diff --git a/tests/Operation/CreateIndexesFunctionalTest.php b/tests/Operation/CreateIndexesFunctionalTest.php
index 8bc79d87a..d3d1b8e63 100644
--- a/tests/Operation/CreateIndexesFunctionalTest.php
+++ b/tests/Operation/CreateIndexesFunctionalTest.php
@@ -223,9 +223,6 @@ public function testCommitQuorumUnsupported(): void
* argument as its first and only parameter. If an IndexInfo matching the
* given name is found, it will be passed to the callback, which may perform
* additional assertions.
- *
- * @param string $indexName
- * @param callable $callback
*/
private function assertIndexExists(string $indexName, ?callable $callback = null): void
{
diff --git a/tests/Operation/DeleteFunctionalTest.php b/tests/Operation/DeleteFunctionalTest.php
index 3bfd4c79f..d97d53474 100644
--- a/tests/Operation/DeleteFunctionalTest.php
+++ b/tests/Operation/DeleteFunctionalTest.php
@@ -129,8 +129,6 @@ public function testUnacknowledgedWriteConcernAccessesDeletedCount(DeleteResult
/**
* Create data fixtures.
- *
- * @param integer $n
*/
private function createFixtures(int $n): void
{
diff --git a/tests/Operation/DeleteTest.php b/tests/Operation/DeleteTest.php
index 2bbfda47f..859721f6d 100644
--- a/tests/Operation/DeleteTest.php
+++ b/tests/Operation/DeleteTest.php
@@ -1,11 +1,15 @@
getDatabaseName(), $this->getCollectionName(), $filter, 0);
}
+ /**
+ * @dataProvider provideInvalidIntegerValues
+ */
+ public function testConstructorLimitArgumentMustBeInt($limit): void
+ {
+ $this->expectException(TypeError::class);
+ new Delete($this->getDatabaseName(), $this->getCollectionName(), [], $limit);
+ }
+
/**
* @dataProvider provideInvalidLimitValues
*/
@@ -30,7 +43,7 @@ public function testConstructorLimitArgumentMustBeOneOrZero($limit): void
public function provideInvalidLimitValues()
{
- return $this->wrapValuesForDataProvider(array_merge($this->getInvalidIntegerValues(), [-1, 2]));
+ return $this->wrapValuesForDataProvider([-1, 2]);
}
/**
diff --git a/tests/Operation/DropDatabaseFunctionalTest.php b/tests/Operation/DropDatabaseFunctionalTest.php
index 2b62c6294..217bf1e63 100644
--- a/tests/Operation/DropDatabaseFunctionalTest.php
+++ b/tests/Operation/DropDatabaseFunctionalTest.php
@@ -78,9 +78,6 @@ function (array $event): void {
/**
* Asserts that a database with the given name does not exist on the server.
- *
- * @param Server $server
- * @param string $databaseName
*/
private function assertDatabaseDoesNotExist(Server $server, string $databaseName): void
{
diff --git a/tests/Operation/DropIndexesFunctionalTest.php b/tests/Operation/DropIndexesFunctionalTest.php
index cc5f75ffa..a7cecf548 100644
--- a/tests/Operation/DropIndexesFunctionalTest.php
+++ b/tests/Operation/DropIndexesFunctionalTest.php
@@ -149,8 +149,6 @@ function (array $event): void {
* argument as its first and only parameter. If an IndexInfo matching the
* given name is found, it will be passed to the callback, which may perform
* additional assertions.
- *
- * @param callable $callback
*/
private function assertIndexExists($indexName, ?callable $callback = null): void
{
diff --git a/tests/Operation/ExplainFunctionalTest.php b/tests/Operation/ExplainFunctionalTest.php
index a639a1d67..fe4f154e7 100644
--- a/tests/Operation/ExplainFunctionalTest.php
+++ b/tests/Operation/ExplainFunctionalTest.php
@@ -425,8 +425,6 @@ private function assertExplainResult($result, $executionStatsExpected, $allPlans
/**
* Create data fixtures.
- *
- * @param integer $n
*/
private function createFixtures(int $n): void
{
diff --git a/tests/Operation/FindAndModifyFunctionalTest.php b/tests/Operation/FindAndModifyFunctionalTest.php
index 13f6184fb..b9b6b605c 100644
--- a/tests/Operation/FindAndModifyFunctionalTest.php
+++ b/tests/Operation/FindAndModifyFunctionalTest.php
@@ -199,8 +199,6 @@ public function provideTypeMapOptionsAndExpectedDocument()
/**
* Create data fixtures.
- *
- * @param integer $n
*/
private function createFixtures(int $n): void
{
diff --git a/tests/Operation/FindFunctionalTest.php b/tests/Operation/FindFunctionalTest.php
index e8996f27a..5ff55752b 100644
--- a/tests/Operation/FindFunctionalTest.php
+++ b/tests/Operation/FindFunctionalTest.php
@@ -246,9 +246,6 @@ public function testReadPreferenceWithinTransaction(): void
/**
* Create data fixtures.
- *
- * @param integer $n
- * @param array $executeBulkWriteOptions
*/
private function createFixtures(int $n, array $executeBulkWriteOptions = []): void
{
diff --git a/tests/Operation/FindOneFunctionalTest.php b/tests/Operation/FindOneFunctionalTest.php
index e15e6967c..cd1096fa7 100644
--- a/tests/Operation/FindOneFunctionalTest.php
+++ b/tests/Operation/FindOneFunctionalTest.php
@@ -40,8 +40,6 @@ public function provideTypeMapOptionsAndExpectedDocument()
/**
* Create data fixtures.
- *
- * @param integer $n
*/
private function createFixtures(int $n): void
{
diff --git a/tests/Operation/MapReduceFunctionalTest.php b/tests/Operation/MapReduceFunctionalTest.php
index 204be0906..d47109b03 100644
--- a/tests/Operation/MapReduceFunctionalTest.php
+++ b/tests/Operation/MapReduceFunctionalTest.php
@@ -294,8 +294,6 @@ public function testTypeMapOptionWithOutputCollection(?array $typeMap, array $ex
/**
* Create data fixtures.
- *
- * @param integer $n
*/
private function createFixtures(int $n): void
{
diff --git a/tests/Operation/UpdateFunctionalTest.php b/tests/Operation/UpdateFunctionalTest.php
index cf7392584..c0b6ba76a 100644
--- a/tests/Operation/UpdateFunctionalTest.php
+++ b/tests/Operation/UpdateFunctionalTest.php
@@ -267,8 +267,6 @@ public function testUnacknowledgedWriteConcernAccessesUpsertedId(UpdateResult $r
/**
* Create data fixtures.
- *
- * @param integer $n
*/
private function createFixtures(int $n): void
{
diff --git a/tests/PHPUnit/Functions.php b/tests/PHPUnit/Functions.php
index 6f9bf5dee..55edd3a6f 100644
--- a/tests/PHPUnit/Functions.php
+++ b/tests/PHPUnit/Functions.php
@@ -1249,13 +1249,11 @@ function assertClassNotHasStaticAttribute(string $attributeName, string $classNa
*
* @see Assert::assertObjectHasAttribute
*
- * @param object $object
- *
* @throws ExpectationFailedException
* @throws InvalidArgumentException
* @throws Exception
*/
- function assertObjectHasAttribute(string $attributeName, $object, string $message = ''): void
+ function assertObjectHasAttribute(string $attributeName, object $object, string $message = ''): void
{
Assert::assertObjectHasAttribute(...func_get_args());
}
@@ -1267,13 +1265,11 @@ function assertObjectHasAttribute(string $attributeName, $object, string $messag
*
* @see Assert::assertObjectNotHasAttribute
*
- * @param object $object
- *
* @throws ExpectationFailedException
* @throws InvalidArgumentException
* @throws Exception
*/
- function assertObjectNotHasAttribute(string $attributeName, $object, string $message = ''): void
+ function assertObjectNotHasAttribute(string $attributeName, object $object, string $message = ''): void
{
Assert::assertObjectNotHasAttribute(...func_get_args());
}
@@ -1952,9 +1948,6 @@ function assertStringStartsWith(string $prefix, string $string, string $message
*
* @see Assert::assertStringStartsNotWith
*
- * @param string $prefix
- * @param string $string
- *
* @throws ExpectationFailedException
* @throws InvalidArgumentException
*/
@@ -2222,9 +2215,6 @@ function assertJsonStringEqualsJsonString(string $expectedJson, string $actualJs
*
* @see Assert::assertJsonStringNotEqualsJsonString
*
- * @param string $expectedJson
- * @param string $actualJson
- *
* @throws ExpectationFailedException
* @throws InvalidArgumentException
*/
diff --git a/tests/SpecTests/CommandExpectations.php b/tests/SpecTests/CommandExpectations.php
index e25ea7c29..86492a3ed 100644
--- a/tests/SpecTests/CommandExpectations.php
+++ b/tests/SpecTests/CommandExpectations.php
@@ -198,9 +198,6 @@ public function stopMonitoring(): void
/**
* Assert that the command expectations match the monitored events.
- *
- * @param FunctionalTestCase $test Test instance
- * @param Context $context Execution context
*/
public function assert(FunctionalTestCase $test, Context $context): void
{
diff --git a/tests/SpecTests/Context.php b/tests/SpecTests/Context.php
index fbc55ae31..0ead3e961 100644
--- a/tests/SpecTests/Context.php
+++ b/tests/SpecTests/Context.php
@@ -317,8 +317,6 @@ public function getInternalClient(): Client
* Prepare options readConcern, readPreference, and writeConcern options by
* creating value objects.
*
- * @param array $options
- * @return array
* @throws LogicException if any option keys are unsupported
*/
public function prepareOptions(array $options): array
diff --git a/tests/SpecTests/DocumentsMatchConstraint.php b/tests/SpecTests/DocumentsMatchConstraint.php
index b512cfd28..9940586c4 100644
--- a/tests/SpecTests/DocumentsMatchConstraint.php
+++ b/tests/SpecTests/DocumentsMatchConstraint.php
@@ -132,8 +132,7 @@ private function doEvaluate($other, $description = '', $returnResult = false)
}
/**
- * @param string $expectedType
- * @param mixed $actualValue
+ * @param mixed $actualValue
*/
private function assertBSONType(string $expectedType, $actualValue): void
{
@@ -275,10 +274,6 @@ private function assertBSONType(string $expectedType, $actualValue): void
/**
* Compares two documents recursively.
*
- * @param ArrayObject $expected
- * @param ArrayObject $actual
- * @param boolean $ignoreExtraKeys
- * @param string $keyPrefix
* @throws RuntimeException if the documents do not match
*/
private function assertEquals(ArrayObject $expected, ArrayObject $actual, bool $ignoreExtraKeys, string $keyPrefix = ''): void
@@ -412,8 +407,7 @@ private static function isNumeric($value): bool
* value within the array or document will then be prepared recursively.
*
* @param array|object $bson
- * @param boolean $isRoot If true, ensure an array value is converted to a document
- * @param boolean $sortKeys
+ * @param boolean $isRoot If true, ensure an array value is converted to a document
* @return BSONDocument|BSONArray
* @throws InvalidArgumentException if $bson is not an array or object
*/
diff --git a/tests/SpecTests/FunctionalTestCase.php b/tests/SpecTests/FunctionalTestCase.php
index 0606e0356..3b266fb04 100644
--- a/tests/SpecTests/FunctionalTestCase.php
+++ b/tests/SpecTests/FunctionalTestCase.php
@@ -87,7 +87,6 @@ public static function assertCommandReplyMatches(stdClass $expected, stdClass $a
*
* @param array|object $expectedDocument
* @param array|object $actualDocument
- * @param string $message
*/
public static function assertDocumentsMatch($expectedDocument, $actualDocument, string $message = ''): void
{
@@ -98,9 +97,6 @@ public static function assertDocumentsMatch($expectedDocument, $actualDocument,
/**
* Assert data within the outcome collection.
- *
- * @param array $expectedDocuments
- * @param int $resultExpectation
*/
protected function assertOutcomeCollectionData(array $expectedDocuments, int $resultExpectation = ResultExpectation::ASSERT_SAME_DOCUMENT): void
{
@@ -133,7 +129,6 @@ protected function assertOutcomeCollectionData(array $expectedDocuments, int $re
/**
* Checks server version and topology requirements.
*
- * @param array $runOn
* @throws SkippedTest if the server requirements are not met
*/
protected function checkServerRequirements(array $runOn): void
@@ -161,7 +156,6 @@ protected function checkServerRequirements(array $runOn): void
* This decodes the file through the driver's extended JSON parser to ensure
* proper handling of special types.
*
- * @param string $json
* @return array|object
*/
protected function decodeJson(string $json)
@@ -172,7 +166,6 @@ protected function decodeJson(string $json)
/**
* Return the test context.
*
- * @return Context
* @throws LogicException if the context has not been set
*/
protected function getContext(): Context
@@ -186,8 +179,6 @@ protected function getContext(): Context
/**
* Set the test context.
- *
- * @param Context $context
*/
protected function setContext(Context $context): void
{
@@ -228,9 +219,6 @@ protected function dropTestAndOutcomeCollections(array $testCollectionDropOption
/**
* Insert data fixtures into the test collection.
- *
- * @param array $documents
- * @param string|null $collectionName
*/
protected function insertDataFixtures(array $documents, ?string $collectionName = null): void
{
@@ -257,7 +245,6 @@ private function getOutcomeCollection(array $collectionOptions = [])
/**
* Return the corresponding topology constants for the current topology.
*
- * @return string
* @throws UnexpectedValueException if topology is neither single nor RS nor sharded
*/
private function getTopology(): string
@@ -300,11 +287,6 @@ private function isServerlessRequirementSatisfied(?string $serverlessMode): bool
/**
* Checks if server version and topology requirements are satifised.
- *
- * @param string|null $minServerVersion
- * @param string|null $maxServerVersion
- * @param array|null $topologies
- * @return boolean
*/
private function isServerRequirementSatisifed(?string $minServerVersion, ?string $maxServerVersion, ?array $topologies = null, ?string $serverlessMode = null): bool
{
diff --git a/tests/SpecTests/Operation.php b/tests/SpecTests/Operation.php
index 25f1c07d4..42d9da990 100644
--- a/tests/SpecTests/Operation.php
+++ b/tests/SpecTests/Operation.php
@@ -100,8 +100,6 @@ public static function fromClientSideEncryption(stdClass $operation)
/**
* This method is exclusively used to prepare nested operations for the
* withTransaction session operation
- *
- * @return Operation
*/
private static function fromConvenientTransactions(stdClass $operation): Operation
{
@@ -189,9 +187,7 @@ public static function fromTransactions(stdClass $operation)
/**
* Execute the operation and assert its outcome.
*
- * @param FunctionalTestCase $test Test instance
- * @param Context $context Execution context
- * @param bool $bubbleExceptions If true, any exception that was caught is rethrown
+ * @param bool $bubbleExceptions If true, any exception that was caught is rethrown
*/
public function assert(FunctionalTestCase $test, Context $context, bool $bubbleExceptions = false): void
{
@@ -237,7 +233,6 @@ public function assert(FunctionalTestCase $test, Context $context, bool $bubbleE
/**
* Executes the operation with a given context.
*
- * @param Context $context Execution context
* @return mixed
* @throws LogicException if the operation is unsupported
*/
@@ -291,8 +286,6 @@ private function execute(FunctionalTestCase $test, Context $context)
/**
* Executes the client operation and return its result.
*
- * @param Client $client
- * @param Context $context Execution context
* @return mixed
* @throws LogicException if the collection operation is unsupported
*/
@@ -322,8 +315,6 @@ private function executeForClient(Client $client, Context $context)
/**
* Executes the collection operation and return its result.
*
- * @param Collection $collection
- * @param Context $context Execution context
* @return mixed
* @throws LogicException if the collection operation is unsupported
*/
@@ -464,8 +455,6 @@ private function executeForCollection(Collection $collection, Context $context)
/**
* Executes the database operation and return its result.
*
- * @param Database $database
- * @param Context $context Execution context
* @return mixed
* @throws LogicException if the database operation is unsupported
*/
@@ -519,8 +508,6 @@ private function executeForDatabase(Database $database, Context $context)
/**
* Executes the GridFS bucket operation and return its result.
*
- * @param Bucket $bucket
- * @param Context $context Execution context
* @return mixed
* @throws LogicException if the database operation is unsupported
*/
@@ -562,9 +549,6 @@ private function executeForGridFSBucket(Bucket $bucket, Context $context)
/**
* Executes the session operation and return its result.
*
- * @param Session $session
- * @param FunctionalTestCase $test
- * @param Context $context Execution context
* @return mixed
* @throws LogicException if the session operation is unsupported
*/
@@ -672,12 +656,6 @@ private function executeForTestRunner(FunctionalTestCase $test, Context $context
}
}
- /**
- * @param string $databaseName
- * @param string $collectionName
- *
- * @return array
- */
private function getIndexNames(Context $context, string $databaseName, string $collectionName): array
{
return array_map(
@@ -838,8 +816,6 @@ private function getResultAssertionTypeForDatabase()
/**
* Prepares a request element for a bulkWrite operation.
*
- * @param stdClass $request
- * @return array
* @throws LogicException if the bulk write request is unsupported
*/
private function prepareBulkWriteRequest(stdClass $request): array
diff --git a/tests/SpecTests/ResultExpectation.php b/tests/SpecTests/ResultExpectation.php
index bb6f1c282..9626719e2 100644
--- a/tests/SpecTests/ResultExpectation.php
+++ b/tests/SpecTests/ResultExpectation.php
@@ -45,10 +45,6 @@ final class ResultExpectation
/** @var callable */
private $assertionCallable;
- /**
- * @param integer $assertionType
- * @param mixed $expectedValue
- */
private function __construct(int $assertionType, $expectedValue)
{
switch ($assertionType) {
@@ -352,7 +348,6 @@ private static function isArrayOfObjects($array)
*
* @see https://github.com/mongodb/specifications/blob/master/source/transactions/tests/README.rst#test-format
* @param mixed $result
- * @return boolean
*/
private static function isErrorResult($result): bool
{
diff --git a/tests/SpecTests/TransactionsSpecTest.php b/tests/SpecTests/TransactionsSpecTest.php
index 4f26e9c3e..15f4fefe6 100644
--- a/tests/SpecTests/TransactionsSpecTest.php
+++ b/tests/SpecTests/TransactionsSpecTest.php
@@ -352,7 +352,6 @@ private static function killAllSessions(): void
/**
* Work around potential error executing distinct on sharded clusters.
*
- * @param array $operations
* @see https://github.com/mongodb/specifications/tree/master/source/transactions/tests#why-do-tests-that-run-distinct-sometimes-fail-with-staledbversion
*/
private function preventStaleDbVersionError(array $operations): void
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 133d9699f..7ed378e11 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -35,8 +35,6 @@ abstract class TestCase extends BaseTestCase
{
/**
* Return the connection URI.
- *
- * @return string
*/
public static function getUri(): string
{
@@ -134,6 +132,11 @@ public function provideInvalidDocumentValues()
return $this->wrapValuesForDataProvider($this->getInvalidDocumentValues());
}
+ public function provideInvalidIntegerValues()
+ {
+ return $this->wrapValuesForDataProvider($this->getInvalidIntegerValues());
+ }
+
protected function assertDeprecated(callable $execution): void
{
$errors = [];
@@ -153,8 +156,6 @@ protected function assertDeprecated(callable $execution): void
/**
* Return the test collection name.
- *
- * @return string
*/
protected function getCollectionName(): string
{
@@ -165,8 +166,6 @@ protected function getCollectionName(): string
/**
* Return the test database name.
- *
- * @return string
*/
protected function getDatabaseName(): string
{
@@ -175,10 +174,6 @@ protected function getDatabaseName(): string
/**
* Return a list of invalid array values.
- *
- * @param boolean $includeNull
- *
- * @return array
*/
protected function getInvalidArrayValues(bool $includeNull = false): array
{
@@ -187,10 +182,6 @@ protected function getInvalidArrayValues(bool $includeNull = false): array
/**
* Return a list of invalid boolean values.
- *
- * @param boolean $includeNull
- *
- * @return array
*/
protected function getInvalidBooleanValues(bool $includeNull = false): array
{
@@ -199,10 +190,6 @@ protected function getInvalidBooleanValues(bool $includeNull = false): array
/**
* Return a list of invalid document values.
- *
- * @param boolean $includeNull
- *
- * @return array
*/
protected function getInvalidDocumentValues(bool $includeNull = false): array
{
@@ -211,10 +198,6 @@ protected function getInvalidDocumentValues(bool $includeNull = false): array
/**
* Return a list of invalid integer values.
- *
- * @param boolean $includeNull
- *
- * @return array
*/
protected function getInvalidIntegerValues(bool $includeNull = false): array
{
@@ -223,10 +206,6 @@ protected function getInvalidIntegerValues(bool $includeNull = false): array
/**
* Return a list of invalid ReadPreference values.
- *
- * @param boolean $includeNull
- *
- * @return array
*/
protected function getInvalidReadConcernValues(bool $includeNull = false): array
{
@@ -235,10 +214,6 @@ protected function getInvalidReadConcernValues(bool $includeNull = false): array
/**
* Return a list of invalid ReadPreference values.
- *
- * @param boolean $includeNull
- *
- * @return array
*/
protected function getInvalidReadPreferenceValues(bool $includeNull = false): array
{
@@ -247,10 +222,6 @@ protected function getInvalidReadPreferenceValues(bool $includeNull = false): ar
/**
* Return a list of invalid Session values.
- *
- * @param boolean $includeNull
- *
- * @return array
*/
protected function getInvalidSessionValues(bool $includeNull = false): array
{
@@ -259,10 +230,6 @@ protected function getInvalidSessionValues(bool $includeNull = false): array
/**
* Return a list of invalid string values.
- *
- * @param boolean $includeNull
- *
- * @return array
*/
protected function getInvalidStringValues(bool $includeNull = false): array
{
@@ -271,10 +238,6 @@ protected function getInvalidStringValues(bool $includeNull = false): array
/**
* Return a list of invalid WriteConcern values.
- *
- * @param boolean $includeNull
- *
- * @return array
*/
protected function getInvalidWriteConcernValues(bool $includeNull = false): array
{
@@ -283,8 +246,6 @@ protected function getInvalidWriteConcernValues(bool $includeNull = false): arra
/**
* Return the test namespace.
- *
- * @return string
*/
protected function getNamespace(): string
{
@@ -295,7 +256,6 @@ protected function getNamespace(): string
* Wrap a list of values for use as a single-argument data provider.
*
* @param array $values List of values
- * @return array
*/
protected function wrapValuesForDataProvider(array $values): array
{
diff --git a/tests/UnifiedSpecTests/Context.php b/tests/UnifiedSpecTests/Context.php
index 39e3f5d1f..2300965f3 100644
--- a/tests/UnifiedSpecTests/Context.php
+++ b/tests/UnifiedSpecTests/Context.php
@@ -91,8 +91,6 @@ public function setUrisForUseMultipleMongoses(string $singleMongosUri, string $m
/**
* Create entities for "createEntities".
- *
- * @param array $createEntities
*/
public function createEntities(array $entities): void
{
diff --git a/tests/UnifiedSpecTests/EventCollector.php b/tests/UnifiedSpecTests/EventCollector.php
index 1da92832c..98465a1a3 100644
--- a/tests/UnifiedSpecTests/EventCollector.php
+++ b/tests/UnifiedSpecTests/EventCollector.php
@@ -163,8 +163,7 @@ private static function getConnectionId($event): string
return sprintf('%s:%d', $server->getHost(), $server->getPort());
}
- /** @param object $event */
- private static function getEventName($event): string
+ private static function getEventName(object $event): string
{
static $eventNamesByClass = null;