diff --git a/cache/stores/mongodb/MongoDB/BulkWriteResult.php b/cache/stores/mongodb/MongoDB/BulkWriteResult.php
index 1a1f3ed4111..dec8d59de1e 100644
--- a/cache/stores/mongodb/MongoDB/BulkWriteResult.php
+++ b/cache/stores/mongodb/MongoDB/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;
@@ -51,7 +47,7 @@ class BulkWriteResult
* This method should only be called if the write was acknowledged.
*
* @see BulkWriteResult::isAcknowledged()
- * @return integer
+ * @return integer|null
* @throws BadMethodCallException is the write result is unacknowledged
*/
public function getDeletedCount()
@@ -69,7 +65,7 @@ class BulkWriteResult
* This method should only be called if the write was acknowledged.
*
* @see BulkWriteResult::isAcknowledged()
- * @return integer
+ * @return integer|null
* @throws BadMethodCallException is the write result is unacknowledged
*/
public function getInsertedCount()
@@ -90,7 +86,7 @@ class BulkWriteResult
* field value. Any driver-generated ID will be a MongoDB\BSON\ObjectId
* instance.
*
- * @return mixed[]
+ * @return array
*/
public function getInsertedIds()
{
@@ -103,7 +99,7 @@ class BulkWriteResult
* This method should only be called if the write was acknowledged.
*
* @see BulkWriteResult::isAcknowledged()
- * @return integer
+ * @return integer|null
* @throws BadMethodCallException is the write result is unacknowledged
*/
public function getMatchedCount()
@@ -142,7 +138,7 @@ class BulkWriteResult
* This method should only be called if the write was acknowledged.
*
* @see BulkWriteResult::isAcknowledged()
- * @return integer
+ * @return integer|null
* @throws BadMethodCallException is the write result is unacknowledged
*/
public function getUpsertedCount()
@@ -165,7 +161,7 @@ class BulkWriteResult
* 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/cache/stores/mongodb/MongoDB/ChangeStream.php b/cache/stores/mongodb/MongoDB/ChangeStream.php
index 551024198fe..33c461801d3 100644
--- a/cache/stores/mongodb/MongoDB/ChangeStream.php
+++ b/cache/stores/mongodb/MongoDB/ChangeStream.php
@@ -22,6 +22,7 @@ use MongoDB\Driver\CursorId;
use MongoDB\Driver\Exception\ConnectionException;
use MongoDB\Driver\Exception\RuntimeException;
use MongoDB\Driver\Exception\ServerException;
+use MongoDB\Exception\BadMethodCallException;
use MongoDB\Exception\ResumeTokenException;
use MongoDB\Model\ChangeStreamIterator;
use ReturnTypeWillChange;
@@ -32,6 +33,8 @@ use function in_array;
/**
* Iterator for a change stream.
*
+ * @psalm-type ResumeCallable = callable(array|object|null, bool): ChangeStreamIterator
+ *
* @api
* @see \MongoDB\Collection::watch()
* @see https://mongodb.com/docs/manual/reference/method/db.watch/#mongodb-method-db.watch
@@ -71,7 +74,7 @@ class ChangeStream implements Iterator
/** @var int */
private static $wireVersionForResumableChangeStreamError = 9;
- /** @var callable */
+ /** @var ResumeCallable|null */
private $resumeCallable;
/** @var ChangeStreamIterator */
@@ -90,8 +93,8 @@ class ChangeStream implements Iterator
/**
* @internal
- * @param ChangeStreamIterator $iterator
- * @param callable $resumeCallable
+ *
+ * @param ResumeCallable $resumeCallable
*/
public function __construct(ChangeStreamIterator $iterator, callable $resumeCallable)
{
@@ -194,10 +197,8 @@ class ChangeStream implements Iterator
* 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 +225,7 @@ class ChangeStream implements Iterator
* @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,12 +252,15 @@ class ChangeStream implements Iterator
/**
* Recreates the ChangeStreamIterator after a resumable server error.
- *
- * @return void
*/
- private function resume()
+ private function resume(): void
{
+ if (! $this->resumeCallable) {
+ throw new BadMethodCallException('Cannot resume a closed change stream.');
+ }
+
$this->iterator = call_user_func($this->resumeCallable, $this->getResumeToken(), $this->hasAdvanced);
+
$this->iterator->rewind();
$this->onIteration($this->hasAdvanced);
@@ -265,10 +269,9 @@ class ChangeStream implements Iterator
/**
* 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/cache/stores/mongodb/MongoDB/Client.php b/cache/stores/mongodb/MongoDB/Client.php
index 181ac733c4f..bb12c3776bb 100644
--- a/cache/stores/mongodb/MongoDB/Client.php
+++ b/cache/stores/mongodb/MongoDB/Client.php
@@ -44,6 +44,8 @@ use function is_string;
class Client
{
+ public const DEFAULT_URI = 'mongodb://127.0.0.1/';
+
/** @var array */
private static $defaultTypeMap = [
'array' => BSONArray::class,
@@ -91,14 +93,14 @@ class Client
* @see https://mongodb.com/docs/manual/reference/connection-string/
* @see https://php.net/manual/en/mongodb-driver-manager.construct.php
* @see https://php.net/manual/en/mongodb.persistence.php#mongodb.persistence.typemaps
- * @param string $uri MongoDB connection string
- * @param array $uriOptions Additional connection string options
- * @param array $driverOptions Driver-specific options
+ * @param string|null $uri MongoDB connection string. If none is provided, this defaults to self::DEFAULT_URI.
+ * @param array $uriOptions Additional connection string options
+ * @param array $driverOptions Driver-specific options
* @throws InvalidArgumentException for parameter/option parsing errors
* @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 = null, array $uriOptions = [], array $driverOptions = [])
{
$driverOptions += ['typeMap' => self::$defaultTypeMap];
@@ -116,8 +118,8 @@ class Client
$driverOptions['driver'] = $this->mergeDriverInfo($driverOptions['driver'] ?? []);
- $this->uri = (string) $uri;
- $this->typeMap = $driverOptions['typeMap'] ?? null;
+ $this->uri = $uri ?? self::DEFAULT_URI;
+ $this->typeMap = $driverOptions['typeMap'];
unset($driverOptions['typeMap']);
@@ -155,7 +157,7 @@ class Client
* @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 +203,7 @@ class Client
* @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 +292,6 @@ class Client
* 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 +315,7 @@ class Client
* @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 +331,7 @@ class Client
* @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/cache/stores/mongodb/MongoDB/Collection.php b/cache/stores/mongodb/MongoDB/Collection.php
index bc864256cf3..517cd307a9a 100644
--- a/cache/stores/mongodb/MongoDB/Collection.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class Collection
}
$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 @@ class Collection
* @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 @@ class Collection
* 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 @@ class Collection
* 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/cache/stores/mongodb/MongoDB/Command/ListCollections.php b/cache/stores/mongodb/MongoDB/Command/ListCollections.php
index 8a017558fe0..a970aeb079c 100644
--- a/cache/stores/mongodb/MongoDB/Command/ListCollections.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class ListCollections implements Executable
throw InvalidArgumentException::invalidType('"session" option', $options['session'], Session::class);
}
- $this->databaseName = (string) $databaseName;
+ $this->databaseName = $databaseName;
$this->options = $options;
}
@@ -103,11 +103,9 @@ class ListCollections implements Executable
* 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 @@ class ListCollections implements Executable
/**
* Create the listCollections command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = ['listCollections' => 1];
@@ -144,9 +140,8 @@ class ListCollections implements Executable
* 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/cache/stores/mongodb/MongoDB/Command/ListDatabases.php b/cache/stores/mongodb/MongoDB/Command/ListDatabases.php
index 3d75fa96c7f..4dabc6ed2ee 100644
--- a/cache/stores/mongodb/MongoDB/Command/ListDatabases.php
+++ b/cache/stores/mongodb/MongoDB/Command/ListDatabases.php
@@ -99,12 +99,11 @@ class ListDatabases implements Executable
* 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 @@ class ListDatabases implements Executable
/**
* Create the listDatabases command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = ['listDatabases' => 1];
@@ -146,9 +143,8 @@ class ListDatabases implements Executable
* 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/cache/stores/mongodb/MongoDB/Database.php b/cache/stores/mongodb/MongoDB/Database.php
index 4d8a7446360..9bb2484dd46 100644
--- a/cache/stores/mongodb/MongoDB/Database.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class Database
}
$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 @@ class Database
* @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 @@ class Database
* 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 @@ class Database
* @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 @@ class Database
* 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 @@ class Database
* @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 @@ class Database
* 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 @@ class Database
* @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/cache/stores/mongodb/MongoDB/DeleteResult.php b/cache/stores/mongodb/MongoDB/DeleteResult.php
index 5666307f236..697ee869266 100644
--- a/cache/stores/mongodb/MongoDB/DeleteResult.php
+++ b/cache/stores/mongodb/MongoDB/DeleteResult.php
@@ -43,7 +43,7 @@ class DeleteResult
* This method should only be called if the write was acknowledged.
*
* @see DeleteResult::isAcknowledged()
- * @return integer
+ * @return integer|null
* @throws BadMethodCallException is the write result is unacknowledged
*/
public function getDeletedCount()
diff --git a/cache/stores/mongodb/MongoDB/Exception/BadMethodCallException.php b/cache/stores/mongodb/MongoDB/Exception/BadMethodCallException.php
index 99dcd6a7290..b140ff3aed5 100644
--- a/cache/stores/mongodb/MongoDB/Exception/BadMethodCallException.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class BadMethodCallException extends BaseBadMethodCallException implements Excep
* @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/cache/stores/mongodb/MongoDB/Exception/InvalidArgumentException.php b/cache/stores/mongodb/MongoDB/Exception/InvalidArgumentException.php
index 8be0de2bbf3..34f4cc5d918 100644
--- a/cache/stores/mongodb/MongoDB/Exception/InvalidArgumentException.php
+++ b/cache/stores/mongodb/MongoDB/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/cache/stores/mongodb/MongoDB/GridFS/Bucket.php b/cache/stores/mongodb/MongoDB/GridFS/Bucket.php
index cdf1cddc3b3..67ad9ffd87c 100644
--- a/cache/stores/mongodb/MongoDB/GridFS/Bucket.php
+++ b/cache/stores/mongodb/MongoDB/GridFS/Bucket.php
@@ -32,9 +32,9 @@ use MongoDB\GridFS\Exception\StreamException;
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument;
use MongoDB\Operation\Find;
-use stdClass;
use function array_intersect_key;
+use function assert;
use function fopen;
use function get_resource_type;
use function in_array;
@@ -137,7 +137,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 +178,7 @@ class Bucket
}
$this->manager = $manager;
- $this->databaseName = (string) $databaseName;
+ $this->databaseName = $databaseName;
$this->bucketName = $options['bucketName'];
$this->chunkSizeBytes = $options['chunkSizeBytes'];
$this->disableMD5 = $options['disableMD5'];
@@ -282,7 +282,7 @@ class Bucket
* @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');
@@ -413,6 +413,7 @@ class Bucket
*/
$typeMap = ['root' => 'stdClass'] + $this->typeMap;
$file = apply_type_map_to_document($file, $typeMap);
+ assert(is_object($file));
if (! isset($file->_id) && ! property_exists($file, '_id')) {
throw new CorruptFileException('file._id does not exist');
@@ -517,7 +518,7 @@ class Bucket
* @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 +551,7 @@ class Bucket
* @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 +575,7 @@ class Bucket
* @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 +621,7 @@ class Bucket
* @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,15 +641,14 @@ class Bucket
/**
* 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;
- } else {
+ if (is_array($file->_id) || (is_object($file->_id) && ! method_exists($file->_id, '__toString'))) {
$id = toJSON(fromPHP(['_id' => $file->_id]));
+ } else {
+ $id = (string) $file->_id;
}
return sprintf(
@@ -662,10 +662,8 @@ class Bucket
/**
* 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 +675,8 @@ class Bucket
/**
* 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 +688,9 @@ class Bucket
* 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 +708,10 @@ class Bucket
/**
* 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 +727,7 @@ class Bucket
/**
* 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/cache/stores/mongodb/MongoDB/GridFS/CollectionWrapper.php b/cache/stores/mongodb/MongoDB/GridFS/CollectionWrapper.php
index 7b58a4fb7d7..28218707cf6 100644
--- a/cache/stores/mongodb/MongoDB/GridFS/CollectionWrapper.php
+++ b/cache/stores/mongodb/MongoDB/GridFS/CollectionWrapper.php
@@ -25,11 +25,12 @@ use MongoDB\Driver\ReadPreference;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\UpdateResult;
use MultipleIterator;
-use stdClass;
use function abs;
+use function assert;
use function count;
use function is_numeric;
+use function is_object;
use function sprintf;
/**
@@ -64,10 +65,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 +79,7 @@ class CollectionWrapper
*
* @param mixed $id
*/
- public function deleteChunksByFilesId($id)
+ public function deleteChunksByFilesId($id): void
{
$this->chunksCollection->deleteMany(['files_id' => $id]);
}
@@ -88,7 +89,7 @@ class CollectionWrapper
*
* @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 +98,7 @@ class CollectionWrapper
/**
* Drops the GridFS files and chunks collections.
*/
- public function dropCollections()
+ public function dropCollections(): void
{
$this->filesCollection->drop(['typeMap' => []]);
$this->chunksCollection->drop(['typeMap' => []]);
@@ -108,9 +109,8 @@ class CollectionWrapper
*
* @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 +138,11 @@ class CollectionWrapper
*
* @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;
@@ -155,7 +152,7 @@ class CollectionWrapper
$sortOrder = 1;
}
- return $this->filesCollection->findOne(
+ $file = $this->filesCollection->findOne(
['filename' => $filename],
[
'skip' => $skip,
@@ -163,20 +160,25 @@ class CollectionWrapper
'typeMap' => ['root' => 'stdClass'],
]
);
+ assert(is_object($file) || $file === null);
+
+ return $file;
}
/**
* 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(
+ $file = $this->filesCollection->findOne(
['_id' => $id],
['typeMap' => ['root' => 'stdClass']]
);
+ assert(is_object($file) || $file === null);
+
+ return $file;
}
/**
@@ -204,42 +206,22 @@ class CollectionWrapper
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 +231,7 @@ class CollectionWrapper
*
* @param array|object $chunk Chunk document
*/
- public function insertChunk($chunk)
+ public function insertChunk($chunk): void
{
if (! $this->checkedIndexes) {
$this->ensureIndexes();
@@ -265,7 +247,7 @@ class CollectionWrapper
*
* @param array|object $file File document
*/
- public function insertFile($file)
+ public function insertFile($file): void
{
if (! $this->checkedIndexes) {
$this->ensureIndexes();
@@ -277,22 +259,20 @@ class CollectionWrapper
/**
* 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 +288,7 @@ class CollectionWrapper
/**
* 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 +307,7 @@ class CollectionWrapper
* 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 +355,8 @@ class CollectionWrapper
/**
* 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/cache/stores/mongodb/MongoDB/GridFS/Exception/CorruptFileException.php b/cache/stores/mongodb/MongoDB/GridFS/Exception/CorruptFileException.php
index c68ceec9549..e31d7daeb73 100644
--- a/cache/stores/mongodb/MongoDB/GridFS/Exception/CorruptFileException.php
+++ b/cache/stores/mongodb/MongoDB/GridFS/Exception/CorruptFileException.php
@@ -23,13 +23,21 @@ use function sprintf;
class CorruptFileException extends RuntimeException
{
+ /**
+ * Thrown when a chunk doesn't contain valid data.
+ */
+ public static function invalidChunkData(int $chunkIndex): self
+ {
+ return new static(sprintf('Invalid data found for index "%d"', $chunkIndex));
+ }
+
/**
* Thrown when a chunk is not found for an expected index.
*
* @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 +49,7 @@ class CorruptFileException extends RuntimeException
* @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 +61,7 @@ class CorruptFileException extends RuntimeException
* @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/cache/stores/mongodb/MongoDB/GridFS/Exception/FileNotFoundException.php b/cache/stores/mongodb/MongoDB/GridFS/Exception/FileNotFoundException.php
index ff9c2c7ebef..5d0f5d5c570 100644
--- a/cache/stores/mongodb/MongoDB/GridFS/Exception/FileNotFoundException.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class FileNotFoundException extends RuntimeException
* @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/cache/stores/mongodb/MongoDB/GridFS/ReadableStream.php b/cache/stores/mongodb/MongoDB/GridFS/ReadableStream.php
index 5a5b1ec3b12..d76e061720a 100644
--- a/cache/stores/mongodb/MongoDB/GridFS/ReadableStream.php
+++ b/cache/stores/mongodb/MongoDB/GridFS/ReadableStream.php
@@ -17,14 +17,16 @@
namespace MongoDB\GridFS;
-use MongoDB\Driver\CursorInterface;
+use MongoDB\BSON\Binary;
+use MongoDB\Driver\Cursor;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\GridFS\Exception\CorruptFileException;
-use stdClass;
+use function assert;
use function ceil;
use function floor;
use function is_integer;
+use function is_object;
use function property_exists;
use function sprintf;
use function strlen;
@@ -49,16 +51,16 @@ class ReadableStream
/** @var integer */
private $chunkOffset = 0;
- /** @var CursorInterface|null */
+ /** @var Cursor|null */
private $chunksIterator;
/** @var CollectionWrapper */
private $collectionWrapper;
- /** @var float|integer */
+ /** @var integer */
private $expectedLastChunkSize = 0;
- /** @var stdClass */
+ /** @var object */
private $file;
/** @var integer */
@@ -71,10 +73,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 +91,8 @@ class ReadableStream
}
$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 +108,7 @@ class ReadableStream
* @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 +117,25 @@ class ReadableStream
];
}
- 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 +151,9 @@ class ReadableStream
* 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));
@@ -178,6 +167,8 @@ class ReadableStream
return '';
}
+ assert($this->buffer !== null);
+
$data = '';
while (strlen($data) < $length) {
@@ -196,10 +187,9 @@ class ReadableStream
/**
* 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 +237,8 @@ class ReadableStream
* 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,22 +249,31 @@ class ReadableStream
* @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;
}
+ if ($this->chunksIterator === null) {
+ return false;
+ }
+
if (! $this->chunksIterator->valid()) {
throw CorruptFileException::missingChunk($this->chunkOffset);
}
$currentChunk = $this->chunksIterator->current();
+ assert(is_object($currentChunk));
if ($currentChunk->n !== $this->chunkOffset) {
throw CorruptFileException::unexpectedIndex($currentChunk->n, $this->chunkOffset);
}
+ if (! $currentChunk->data instanceof Binary) {
+ throw CorruptFileException::invalidChunkData($this->chunkOffset);
+ }
+
$this->buffer = $currentChunk->data->getData();
$actualChunkSize = strlen($this->buffer);
@@ -298,12 +295,16 @@ class ReadableStream
* @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;
}
+ if ($this->chunksIterator === null) {
+ return false;
+ }
+
$this->bufferOffset = 0;
$this->chunkOffset++;
$this->chunksIterator->next();
@@ -314,7 +315,7 @@ class ReadableStream
/**
* 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/cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php b/cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php
index 3507708cbba..3e04c3d14c0 100644
--- a/cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php
+++ b/cache/stores/mongodb/MongoDB/GridFS/StreamWrapper.php
@@ -18,11 +18,12 @@
namespace MongoDB\GridFS;
use MongoDB\BSON\UTCDateTime;
-use stdClass;
+use function assert;
use function explode;
use function in_array;
use function is_integer;
+use function is_resource;
use function stream_context_get_options;
use function stream_get_wrappers;
use function stream_wrapper_register;
@@ -64,11 +65,11 @@ class StreamWrapper
/**
* Return the stream's file document.
- *
- * @return stdClass
*/
- public function getFile()
+ public function getFile(): object
{
+ assert($this->stream !== null);
+
return $this->stream->getFile();
}
@@ -77,7 +78,7 @@ class StreamWrapper
*
* @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 +92,7 @@ class StreamWrapper
*
* @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 +105,8 @@ class StreamWrapper
* 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 +119,12 @@ class StreamWrapper
* 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 +148,8 @@ class StreamWrapper
*
* @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,8 +166,10 @@ class StreamWrapper
* @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
{
+ assert($this->stream !== null);
+
$size = $this->stream->getSize();
if ($whence === SEEK_CUR) {
@@ -198,10 +198,11 @@ class StreamWrapper
* 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
{
+ assert($this->stream !== null);
+
$stat = $this->getStatTemplate();
$stat[2] = $stat['mode'] = $this->stream instanceof ReadableStream
@@ -230,8 +231,10 @@ class StreamWrapper
* @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
{
+ assert($this->stream !== null);
+
return $this->stream->tell();
}
@@ -242,7 +245,7 @@ class StreamWrapper
* @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 +256,8 @@ class StreamWrapper
/**
* 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 +282,8 @@ class StreamWrapper
* 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,12 +293,13 @@ class StreamWrapper
* Initialize the internal stream for reading.
*
* @see StreamWrapper::stream_open()
- * @return boolean
*/
- private function initReadableStream()
+ private function initReadableStream(): bool
{
+ assert(is_resource($this->context));
$context = stream_context_get_options($this->context);
+ assert($this->protocol !== null);
$this->stream = new ReadableStream(
$context[$this->protocol]['collectionWrapper'],
$context[$this->protocol]['file']
@@ -311,12 +312,13 @@ class StreamWrapper
* Initialize the internal stream for writing.
*
* @see StreamWrapper::stream_open()
- * @return boolean
*/
- private function initWritableStream()
+ private function initWritableStream(): bool
{
+ assert(is_resource($this->context));
$context = stream_context_get_options($this->context);
+ assert($this->protocol !== null);
$this->stream = new WritableStream(
$context[$this->protocol]['collectionWrapper'],
$context[$this->protocol]['filename'],
diff --git a/cache/stores/mongodb/MongoDB/GridFS/WritableStream.php b/cache/stores/mongodb/MongoDB/GridFS/WritableStream.php
index d38d39f8e11..43519e09bf5 100644
--- a/cache/stores/mongodb/MongoDB/GridFS/WritableStream.php
+++ b/cache/stores/mongodb/MongoDB/GridFS/WritableStream.php
@@ -17,12 +17,12 @@
namespace MongoDB\GridFS;
+use HashContext;
use MongoDB\BSON\Binary;
use MongoDB\BSON\ObjectId;
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;
@@ -66,7 +66,7 @@ class WritableStream
/** @var array */
private $file;
- /** @var resource */
+ /** @var HashContext|null */
private $hashCtx;
/** @var boolean */
@@ -103,7 +103,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 +146,7 @@ class WritableStream
$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 +154,8 @@ class WritableStream
* 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 +167,7 @@ class WritableStream
/**
* 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 +184,8 @@ class WritableStream
/**
* Return the stream's file document.
- *
- * @return stdClass
*/
- public function getFile()
+ public function getFile(): object
{
return (object) $this->file;
}
@@ -197,10 +194,8 @@ class WritableStream
* 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 +208,8 @@ class WritableStream
* always the end of the stream.
*
* @see WritableStream::getSize()
- * @return integer
*/
- public function tell()
+ public function tell(): int
{
return $this->getSize();
}
@@ -227,13 +221,12 @@ class WritableStream
* 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 +244,7 @@ class WritableStream
return $bytesRead;
}
- private function abort()
+ private function abort(): void
{
try {
$this->collectionWrapper->deleteChunksByFilesId($this->file['_id']);
@@ -270,7 +263,7 @@ class WritableStream
$this->file['length'] = $this->length;
$this->file['uploadDate'] = new UTCDateTime();
- if (! $this->disableMD5) {
+ if (! $this->disableMD5 && $this->hashCtx) {
$this->file['md5'] = hash_final($this->hashCtx);
}
@@ -285,7 +278,7 @@ class WritableStream
return $this->file['_id'];
}
- private function insertChunkFromBuffer()
+ private function insertChunkFromBuffer(): void
{
if (strlen($this->buffer) == 0) {
return;
@@ -300,7 +293,7 @@ class WritableStream
'data' => new Binary($data, Binary::TYPE_GENERIC),
];
- if (! $this->disableMD5) {
+ if (! $this->disableMD5 && $this->hashCtx) {
hash_update($this->hashCtx, $data);
}
diff --git a/cache/stores/mongodb/MongoDB/InsertManyResult.php b/cache/stores/mongodb/MongoDB/InsertManyResult.php
index 5dc29a8d2b6..d1aabe55893 100644
--- a/cache/stores/mongodb/MongoDB/InsertManyResult.php
+++ b/cache/stores/mongodb/MongoDB/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;
@@ -51,7 +47,7 @@ class InsertManyResult
* This method should only be called if the write was acknowledged.
*
* @see InsertManyResult::isAcknowledged()
- * @return integer
+ * @return integer|null
* @throws BadMethodCallException is the write result is unacknowledged
*/
public function getInsertedCount()
@@ -72,7 +68,7 @@ class InsertManyResult
* field value. Any driver-generated ID will be a MongoDB\BSON\ObjectId
* instance.
*
- * @return mixed[]
+ * @return array
*/
public function getInsertedIds()
{
diff --git a/cache/stores/mongodb/MongoDB/InsertOneResult.php b/cache/stores/mongodb/MongoDB/InsertOneResult.php
index 32a14a1e345..6a74eb90054 100644
--- a/cache/stores/mongodb/MongoDB/InsertOneResult.php
+++ b/cache/stores/mongodb/MongoDB/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)
{
@@ -51,7 +50,7 @@ class InsertOneResult
* This method should only be called if the write was acknowledged.
*
* @see InsertOneResult::isAcknowledged()
- * @return integer
+ * @return integer|null
* @throws BadMethodCallException is the write result is unacknowledged
*/
public function getInsertedCount()
diff --git a/cache/stores/mongodb/MongoDB/MapReduceResult.php b/cache/stores/mongodb/MongoDB/MapReduceResult.php
index fe212790203..d7ef777a356 100644
--- a/cache/stores/mongodb/MongoDB/MapReduceResult.php
+++ b/cache/stores/mongodb/MongoDB/MapReduceResult.php
@@ -79,7 +79,7 @@ class MapReduceResult implements IteratorAggregate
*/
public function getExecutionTimeMS()
{
- return (integer) $this->executionTimeMS;
+ return $this->executionTimeMS;
}
/**
diff --git a/cache/stores/mongodb/MongoDB/Model/BSONArray.php b/cache/stores/mongodb/MongoDB/Model/BSONArray.php
index 0b49fd98f09..a87505f29c1 100644
--- a/cache/stores/mongodb/MongoDB/Model/BSONArray.php
+++ b/cache/stores/mongodb/MongoDB/Model/BSONArray.php
@@ -51,7 +51,6 @@ class BSONArray extends ArrayObject implements JsonSerializable, Serializable, U
*
* @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)
@@ -71,6 +70,7 @@ class BSONArray extends ArrayObject implements JsonSerializable, Serializable, U
* @see https://php.net/mongodb-bson-serializable.bsonserialize
* @return array
*/
+ #[ReturnTypeWillChange]
public function bsonSerialize()
{
return array_values($this->getArrayCopy());
@@ -82,6 +82,7 @@ class BSONArray extends ArrayObject implements JsonSerializable, Serializable, U
* @see https://php.net/mongodb-bson-unserializable.bsonunserialize
* @param array $data Array data
*/
+ #[ReturnTypeWillChange]
public function bsonUnserialize(array $data)
{
self::__construct($data);
diff --git a/cache/stores/mongodb/MongoDB/Model/BSONDocument.php b/cache/stores/mongodb/MongoDB/Model/BSONDocument.php
index ab8cb5375b1..8fc04e84f55 100644
--- a/cache/stores/mongodb/MongoDB/Model/BSONDocument.php
+++ b/cache/stores/mongodb/MongoDB/Model/BSONDocument.php
@@ -50,11 +50,8 @@ class BSONDocument extends ArrayObject implements JsonSerializable, Serializable
* 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 @@ class BSONDocument extends ArrayObject implements JsonSerializable, Serializable
*
* @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)
@@ -81,6 +77,7 @@ class BSONDocument extends ArrayObject implements JsonSerializable, Serializable
* @see https://php.net/mongodb-bson-serializable.bsonserialize
* @return object
*/
+ #[ReturnTypeWillChange]
public function bsonSerialize()
{
return (object) $this->getArrayCopy();
@@ -92,6 +89,7 @@ class BSONDocument extends ArrayObject implements JsonSerializable, Serializable
* @see https://php.net/mongodb-bson-unserializable.bsonunserialize
* @param array $data Array data
*/
+ #[ReturnTypeWillChange]
public function bsonUnserialize(array $data)
{
parent::__construct($data, ArrayObject::ARRAY_AS_PROPS);
diff --git a/cache/stores/mongodb/MongoDB/Model/BSONIterator.php b/cache/stores/mongodb/MongoDB/Model/BSONIterator.php
index 5c086b81a34..2bddc264cd4 100644
--- a/cache/stores/mongodb/MongoDB/Model/BSONIterator.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class BSONIterator implements Iterator
/**
* @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/cache/stores/mongodb/MongoDB/Model/CachingIterator.php b/cache/stores/mongodb/MongoDB/Model/CachingIterator.php
index 0e54dc2c8f4..f2a7dd25b98 100644
--- a/cache/stores/mongodb/MongoDB/Model/CachingIterator.php
+++ b/cache/stores/mongodb/MongoDB/Model/CachingIterator.php
@@ -72,10 +72,8 @@ class CachingIterator implements Countable, Iterator
/**
* @see https://php.net/countable.count
- * @return integer
*/
- #[ReturnTypeWillChange]
- public function count()
+ public function count(): int
{
$this->exhaustIterator();
@@ -108,10 +106,8 @@ class CachingIterator implements Countable, Iterator
/**
* @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 @@ class CachingIterator implements Countable, Iterator
/**
* @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 @@ class CachingIterator implements Countable, Iterator
/**
* @see https://php.net/iterator.valid
- * @return boolean
*/
- #[ReturnTypeWillChange]
- public function valid()
+ public function valid(): bool
{
return $this->key() !== null;
}
@@ -155,7 +147,7 @@ class CachingIterator implements Countable, Iterator
/**
* 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 @@ class CachingIterator implements Countable, Iterator
/**
* Stores the current item in the cache.
*/
- private function storeCurrentItem()
+ private function storeCurrentItem(): void
{
if (! $this->iterator->valid()) {
return;
diff --git a/cache/stores/mongodb/MongoDB/Model/CallbackIterator.php b/cache/stores/mongodb/MongoDB/Model/CallbackIterator.php
index a5abec9c1af..8e3c68d0c17 100644
--- a/cache/stores/mongodb/MongoDB/Model/CallbackIterator.php
+++ b/cache/stores/mongodb/MongoDB/Model/CallbackIterator.php
@@ -64,30 +64,24 @@ class CallbackIterator implements Iterator
/**
* @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/cache/stores/mongodb/MongoDB/Model/ChangeStreamIterator.php b/cache/stores/mongodb/MongoDB/Model/ChangeStreamIterator.php
index f8c40c1b5e8..ceb31f9fc96 100644
--- a/cache/stores/mongodb/MongoDB/Model/ChangeStreamIterator.php
+++ b/cache/stores/mongodb/MongoDB/Model/ChangeStreamIterator.php
@@ -30,9 +30,9 @@ use MongoDB\Exception\ResumeTokenException;
use MongoDB\Exception\UnexpectedValueException;
use ReturnTypeWillChange;
+use function assert;
use function count;
use function is_array;
-use function is_integer;
use function is_object;
use function MongoDB\Driver\Monitoring\addSubscriber;
use function MongoDB\Driver\Monitoring\removeSubscriber;
@@ -71,25 +71,14 @@ 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');
- }
-
if (isset($initialResumeToken) && ! is_array($initialResumeToken) && ! is_object($initialResumeToken)) {
throw InvalidArgumentException::invalidType('$initialResumeToken', $initialResumeToken, 'array or object');
}
- if (isset($postBatchResumeToken) && ! is_object($postBatchResumeToken)) {
- throw InvalidArgumentException::invalidType('$postBatchResumeToken', $postBatchResumeToken, 'object');
- }
-
parent::__construct($cursor);
$this->batchSize = $firstBatchSize;
@@ -100,24 +89,24 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
}
/** @internal */
- final public function commandFailed(CommandFailedEvent $event)
+ final public function commandFailed(CommandFailedEvent $event): void
{
}
/** @internal */
- final public function commandStarted(CommandStartedEvent $event)
+ final public function commandStarted(CommandStartedEvent $event): void
{
if ($event->getCommandName() !== 'getMore') {
return;
}
$this->batchPosition = 0;
- $this->batchSize = null;
+ $this->batchSize = 0;
$this->postBatchResumeToken = null;
}
/** @internal */
- final public function commandSucceeded(CommandSucceededEvent $event)
+ final public function commandSucceeded(CommandSucceededEvent $event): void
{
if ($event->getCommandName() !== 'getMore') {
return;
@@ -146,6 +135,20 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
return $this->isValid ? parent::current() : null;
}
+ /**
+ * Necessary to let psalm know that we're always expecting a cursor as inner
+ * iterator. This could be side-stepped due to the class not being final,
+ * but it's very much an invalid use-case. This method can be dropped in 2.0
+ * once the class is final.
+ */
+ final public function getInnerIterator(): Cursor
+ {
+ $cursor = parent::getInnerIterator();
+ assert($cursor instanceof Cursor);
+
+ return $cursor;
+ }
+
/**
* Returns the resume token for the iterator's current position.
*
@@ -180,10 +183,8 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
/**
* @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 +209,8 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
/**
* @see https://php.net/iteratoriterator.rewind
- * @return void
*/
- #[ReturnTypeWillChange]
- public function rewind()
+ public function rewind(): void
{
if ($this->isRewindNop) {
return;
@@ -223,10 +222,8 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
/**
* @see https://php.net/iteratoriterator.valid
- * @return boolean
*/
- #[ReturnTypeWillChange]
- public function valid()
+ public function valid(): bool
{
return $this->isValid;
}
@@ -270,10 +267,8 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
/**
* 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 +277,8 @@ class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
* 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/cache/stores/mongodb/MongoDB/Model/CollectionInfo.php b/cache/stores/mongodb/MongoDB/Model/CollectionInfo.php
index 0513125caab..6722978bc65 100644
--- a/cache/stores/mongodb/MongoDB/Model/CollectionInfo.php
+++ b/cache/stores/mongodb/MongoDB/Model/CollectionInfo.php
@@ -86,8 +86,6 @@ class CollectionInfo implements ArrayAccess
/**
* Return information about the _id index for the collection.
- *
- * @return array
*/
public function getIdIndex(): array
{
@@ -98,7 +96,6 @@ class CollectionInfo implements ArrayAccess
* 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 @@ class CollectionInfo implements ArrayAccess
* Return the collection type.
*
* @see https://mongodb.com/docs/manual/reference/command/listCollections/#output
- * @return string
*/
public function getType(): string
{
diff --git a/cache/stores/mongodb/MongoDB/Model/CollectionInfoCommandIterator.php b/cache/stores/mongodb/MongoDB/Model/CollectionInfoCommandIterator.php
index 316b67fb00b..96c2d73a97f 100644
--- a/cache/stores/mongodb/MongoDB/Model/CollectionInfoCommandIterator.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class CollectionInfoCommandIterator extends IteratorIterator implements Collecti
*
* @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/cache/stores/mongodb/MongoDB/Model/DatabaseInfoLegacyIterator.php b/cache/stores/mongodb/MongoDB/Model/DatabaseInfoLegacyIterator.php
index c6f5f084254..2fb8e88a514 100644
--- a/cache/stores/mongodb/MongoDB/Model/DatabaseInfoLegacyIterator.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class DatabaseInfoLegacyIterator implements DatabaseInfoIterator
*
* @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 @@ class DatabaseInfoLegacyIterator implements DatabaseInfoIterator
* 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 @@ class DatabaseInfoLegacyIterator implements DatabaseInfoIterator
* 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 @@ class DatabaseInfoLegacyIterator implements DatabaseInfoIterator
* 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 @@ class DatabaseInfoLegacyIterator implements DatabaseInfoIterator
* 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/cache/stores/mongodb/MongoDB/Model/IndexInfoIteratorIterator.php b/cache/stores/mongodb/MongoDB/Model/IndexInfoIteratorIterator.php
index fcdcbf0412b..f0a35baf0e8 100644
--- a/cache/stores/mongodb/MongoDB/Model/IndexInfoIteratorIterator.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class IndexInfoIteratorIterator extends IteratorIterator implements IndexInfoIte
*
* @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/cache/stores/mongodb/MongoDB/Model/IndexInput.php b/cache/stores/mongodb/MongoDB/Model/IndexInput.php
index 584d8f912c0..65c3fc2a2e1 100644
--- a/cache/stores/mongodb/MongoDB/Model/IndexInput.php
+++ b/cache/stores/mongodb/MongoDB/Model/IndexInput.php
@@ -76,10 +76,8 @@ class IndexInput implements Serializable
/**
* Return the index name.
- *
- * @return string
*/
- public function __toString()
+ public function __toString(): string
{
return $this->index['name'];
}
@@ -89,9 +87,8 @@ class IndexInput implements Serializable
*
* @see \MongoDB\Collection::createIndexes()
* @see https://php.net/mongodb-bson-serializable.bsonserialize
- * @return array
*/
- public function bsonSerialize()
+ public function bsonSerialize(): array
{
return $this->index;
}
diff --git a/cache/stores/mongodb/MongoDB/Operation/Aggregate.php b/cache/stores/mongodb/MongoDB/Operation/Aggregate.php
index de3c1e4f095..040e3c9c9f6 100644
--- a/cache/stores/mongodb/MongoDB/Operation/Aggregate.php
+++ b/cache/stores/mongodb/MongoDB/Operation/Aggregate.php
@@ -30,7 +30,6 @@ use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException;
use stdClass;
-use Traversable;
use function current;
use function is_array;
@@ -137,7 +136,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 +245,8 @@ class Aggregate implements Executable, Explainable
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,8 +255,7 @@ class Aggregate implements Executable, Explainable
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
- * @return Traversable
+ * @return ArrayIterator|Cursor
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if read concern or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -296,7 +294,7 @@ class Aggregate implements Executable, Explainable
$result = current($cursor->toArray());
- if (! isset($result->result) || ! is_array($result->result)) {
+ if (! is_object($result) || ! isset($result->result) || ! is_array($result->result)) {
throw new UnexpectedValueException('aggregate command did not return a "result" array');
}
@@ -307,7 +305,6 @@ class Aggregate implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -317,10 +314,8 @@ class Aggregate implements Executable, Explainable
/**
* Create the aggregate command document.
- *
- * @return array
*/
- private function createCommandDocument()
+ private function createCommandDocument(): array
{
$cmd = [
'aggregate' => $this->collectionName ?? 1,
diff --git a/cache/stores/mongodb/MongoDB/Operation/BulkWrite.php b/cache/stores/mongodb/MongoDB/Operation/BulkWrite.php
index f9096c2c559..28568de2505 100644
--- a/cache/stores/mongodb/MongoDB/Operation/BulkWrite.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class BulkWrite implements Executable
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 @@ class BulkWrite implements Executable
* 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 @@ class BulkWrite implements Executable
* 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 @@ class BulkWrite implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/Count.php b/cache/stores/mongodb/MongoDB/Operation/Count.php
index aff947b728a..7e427313c0c 100644
--- a/cache/stores/mongodb/MongoDB/Operation/Count.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class Count implements Executable, Explainable
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 @@ class Count implements Executable, Explainable
* 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
@@ -159,7 +158,7 @@ class Count implements Executable, Explainable
$result = current($cursor->toArray());
// Older server versions may return a float
- if (! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) {
+ if (! is_object($result) || ! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) {
throw new UnexpectedValueException('count command did not return a numeric "n" value');
}
@@ -170,7 +169,6 @@ class Count implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -180,10 +178,8 @@ class Count implements Executable, Explainable
/**
* Create the count command document.
- *
- * @return array
*/
- private function createCommandDocument()
+ private function createCommandDocument(): array
{
$cmd = ['count' => $this->collectionName];
@@ -212,9 +208,8 @@ class Count implements Executable, Explainable
* 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/cache/stores/mongodb/MongoDB/Operation/CountDocuments.php b/cache/stores/mongodb/MongoDB/Operation/CountDocuments.php
index 6e0e561f932..57b04544b29 100644
--- a/cache/stores/mongodb/MongoDB/Operation/CountDocuments.php
+++ b/cache/stores/mongodb/MongoDB/Operation/CountDocuments.php
@@ -17,6 +17,7 @@
namespace MongoDB\Operation;
+use MongoDB\Driver\Cursor;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
@@ -24,6 +25,7 @@ use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException;
use function array_intersect_key;
+use function assert;
use function count;
use function current;
use function is_array;
@@ -93,7 +95,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 +109,8 @@ class CountDocuments implements Executable
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 +123,6 @@ class CountDocuments implements Executable
* 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
@@ -130,6 +131,8 @@ class CountDocuments implements Executable
public function execute(Server $server)
{
$cursor = $this->aggregate->execute($server);
+ assert($cursor instanceof Cursor);
+
$allResults = $cursor->toArray();
/* If there are no documents to count, the aggregation pipeline has no items to group, and
@@ -139,17 +142,14 @@ class CountDocuments implements Executable
}
$result = current($allResults);
- if (! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) {
+ if (! is_object($result) || ! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) {
throw new UnexpectedValueException('count command did not return a numeric "n" value');
}
return (integer) $result->n;
}
- /**
- * @return Aggregate
- */
- private function createAggregate()
+ private function createAggregate(): Aggregate
{
$pipeline = [
['$match' => (object) $this->filter],
diff --git a/cache/stores/mongodb/MongoDB/Operation/CreateCollection.php b/cache/stores/mongodb/MongoDB/Operation/CreateCollection.php
index 61c68773078..8860a28897b 100644
--- a/cache/stores/mongodb/MongoDB/Operation/CreateCollection.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class CreateCollection implements Executable
}
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->options = $options;
}
@@ -265,7 +265,6 @@ class CreateCollection implements Executable
* 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 @@ class CreateCollection implements Executable
/**
* Create the create command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = ['create' => $this->collectionName];
@@ -308,9 +305,8 @@ class CreateCollection implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/CreateIndexes.php b/cache/stores/mongodb/MongoDB/Operation/CreateIndexes.php
index 498b8c1efa9..351f2511652 100644
--- a/cache/stores/mongodb/MongoDB/Operation/CreateIndexes.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class CreateIndexes implements Executable
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->options = $options;
}
@@ -135,7 +135,6 @@ class CreateIndexes implements Executable
* 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 @@ class CreateIndexes implements Executable
* 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 @@ class CreateIndexes implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/DatabaseCommand.php b/cache/stores/mongodb/MongoDB/Operation/DatabaseCommand.php
index 317abc6586b..4e6fac52268 100644
--- a/cache/stores/mongodb/MongoDB/Operation/DatabaseCommand.php
+++ b/cache/stores/mongodb/MongoDB/Operation/DatabaseCommand.php
@@ -38,7 +38,7 @@ class DatabaseCommand implements Executable
/** @var string */
private $databaseName;
- /** @var array|Command|object */
+ /** @var Command */
private $command;
/** @var array */
@@ -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 @@ class DatabaseCommand implements Executable
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 @@ class DatabaseCommand implements Executable
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return Cursor
*/
public function execute(Server $server)
@@ -110,9 +109,8 @@ class DatabaseCommand implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/Delete.php b/cache/stores/mongodb/MongoDB/Operation/Delete.php
index 95df96624d4..7ca197f7af3 100644
--- a/cache/stores/mongodb/MongoDB/Operation/Delete.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class Delete implements Executable, Explainable
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 @@ class Delete implements Executable, Explainable
* 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 @@ class Delete implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -214,10 +212,8 @@ class Delete implements Executable, Explainable
*
* 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 @@ class Delete implements Executable, Explainable
* 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/cache/stores/mongodb/MongoDB/Operation/DeleteMany.php b/cache/stores/mongodb/MongoDB/Operation/DeleteMany.php
index 3e3a73d0fc7..33497f3f471 100644
--- a/cache/stores/mongodb/MongoDB/Operation/DeleteMany.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class DeleteMany implements Executable, Explainable
* 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 @@ class DeleteMany implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/cache/stores/mongodb/MongoDB/Operation/DeleteOne.php b/cache/stores/mongodb/MongoDB/Operation/DeleteOne.php
index dda930208cd..a91d67bb57a 100644
--- a/cache/stores/mongodb/MongoDB/Operation/DeleteOne.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class DeleteOne implements Executable, Explainable
* 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 @@ class DeleteOne implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/cache/stores/mongodb/MongoDB/Operation/Distinct.php b/cache/stores/mongodb/MongoDB/Operation/Distinct.php
index 3298cda8927..3c2f93dbd8c 100644
--- a/cache/stores/mongodb/MongoDB/Operation/Distinct.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class Distinct implements Executable, Explainable
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 @@ class Distinct implements Executable, Explainable
* 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)
@@ -152,7 +151,7 @@ class Distinct implements Executable, Explainable
$result = current($cursor->toArray());
- if (! isset($result->values) || ! is_array($result->values)) {
+ if (! is_object($result) || ! isset($result->values) || ! is_array($result->values)) {
throw new UnexpectedValueException('distinct command did not return a "values" array');
}
@@ -163,7 +162,6 @@ class Distinct implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -173,10 +171,8 @@ class Distinct implements Executable, Explainable
/**
* Create the distinct command document.
- *
- * @return array
*/
- private function createCommandDocument()
+ private function createCommandDocument(): array
{
$cmd = [
'distinct' => $this->collectionName,
@@ -204,9 +200,8 @@ class Distinct implements Executable, Explainable
* 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/cache/stores/mongodb/MongoDB/Operation/DropCollection.php b/cache/stores/mongodb/MongoDB/Operation/DropCollection.php
index 2ab9b871609..11e85bdd79b 100644
--- a/cache/stores/mongodb/MongoDB/Operation/DropCollection.php
+++ b/cache/stores/mongodb/MongoDB/Operation/DropCollection.php
@@ -19,6 +19,7 @@ namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\Exception\CommandException;
+use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern;
@@ -71,7 +72,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 +90,8 @@ class DropCollection implements Executable
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->options = $options;
}
@@ -98,7 +99,6 @@ class DropCollection implements Executable
* 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 +132,8 @@ class DropCollection implements Executable
/**
* Create the drop command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = ['drop' => $this->collectionName];
@@ -150,9 +148,8 @@ class DropCollection implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/DropDatabase.php b/cache/stores/mongodb/MongoDB/Operation/DropDatabase.php
index 0e569f06892..c909b2436c2 100644
--- a/cache/stores/mongodb/MongoDB/Operation/DropDatabase.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class DropDatabase implements Executable
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
+ $this->databaseName = $databaseName;
$this->options = $options;
}
@@ -89,7 +89,6 @@ class DropDatabase implements Executable
* 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 @@ class DropDatabase implements Executable
/**
* Create the dropDatabase command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = ['dropDatabase' => 1];
@@ -124,9 +121,8 @@ class DropDatabase implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/DropIndexes.php b/cache/stores/mongodb/MongoDB/Operation/DropIndexes.php
index e63be7fd104..ef0e2f4d3c8 100644
--- a/cache/stores/mongodb/MongoDB/Operation/DropIndexes.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class DropIndexes implements Executable
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 @@ class DropIndexes implements Executable
* 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 @@ class DropIndexes implements Executable
/**
* Create the dropIndexes command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = [
'dropIndexes' => $this->collectionName,
@@ -159,9 +156,8 @@ class DropIndexes implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/EstimatedDocumentCount.php b/cache/stores/mongodb/MongoDB/Operation/EstimatedDocumentCount.php
index 5ed9c73b91b..6deeef3e535 100644
--- a/cache/stores/mongodb/MongoDB/Operation/EstimatedDocumentCount.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class EstimatedDocumentCount implements Executable, Explainable
* 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 @@ class EstimatedDocumentCount implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/cache/stores/mongodb/MongoDB/Operation/Executable.php b/cache/stores/mongodb/MongoDB/Operation/Executable.php
index b71b20ba65f..5bd8c68b385 100644
--- a/cache/stores/mongodb/MongoDB/Operation/Executable.php
+++ b/cache/stores/mongodb/MongoDB/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/cache/stores/mongodb/MongoDB/Operation/Explain.php b/cache/stores/mongodb/MongoDB/Operation/Explain.php
index b6cec43e3b8..13ae85d0919 100644
--- a/cache/stores/mongodb/MongoDB/Operation/Explain.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class Explain implements Executable
* 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 @@ class Explain implements Executable
/**
* 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 @@ class Explain implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/Explainable.php b/cache/stores/mongodb/MongoDB/Operation/Explainable.php
index 973495235dd..7647b51ec00 100644
--- a/cache/stores/mongodb/MongoDB/Operation/Explainable.php
+++ b/cache/stores/mongodb/MongoDB/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/cache/stores/mongodb/MongoDB/Operation/Find.php b/cache/stores/mongodb/MongoDB/Operation/Find.php
index 77e20ba12e4..619e6f5c508 100644
--- a/cache/stores/mongodb/MongoDB/Operation/Find.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class Find implements Executable, Explainable
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 @@ class Find implements Executable, Explainable
* 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 @@ class Find implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -380,9 +378,8 @@ class Find implements Executable, Explainable
* 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 @@ class Find implements Executable, Explainable
*
* 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/cache/stores/mongodb/MongoDB/Operation/FindAndModify.php b/cache/stores/mongodb/MongoDB/Operation/FindAndModify.php
index 290b8205f38..d4fc2b3a4c1 100644
--- a/cache/stores/mongodb/MongoDB/Operation/FindAndModify.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class FindAndModify implements Executable, Explainable
unset($options['writeConcern']);
}
- $this->databaseName = (string) $databaseName;
- $this->collectionName = (string) $collectionName;
+ $this->databaseName = $databaseName;
+ $this->collectionName = $collectionName;
$this->options = $options;
}
@@ -218,7 +218,6 @@ class FindAndModify implements Executable, Explainable
* 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
@@ -254,14 +253,13 @@ class FindAndModify implements Executable, Explainable
$result = current($cursor->toArray());
- return $result->value ?? null;
+ return is_object($result) ? ($result->value ?? null) : null;
}
/**
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -271,10 +269,8 @@ class FindAndModify implements Executable, Explainable
/**
* Create the findAndModify command document.
- *
- * @return array
*/
- private function createCommandDocument()
+ private function createCommandDocument(): array
{
$cmd = ['findAndModify' => $this->collectionName];
@@ -315,9 +311,8 @@ class FindAndModify implements Executable, Explainable
* 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/cache/stores/mongodb/MongoDB/Operation/FindOne.php b/cache/stores/mongodb/MongoDB/Operation/FindOne.php
index b75edcb1ed5..3de70dae6ea 100644
--- a/cache/stores/mongodb/MongoDB/Operation/FindOne.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class FindOne implements Executable, Explainable
* 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 @@ class FindOne implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/cache/stores/mongodb/MongoDB/Operation/FindOneAndDelete.php b/cache/stores/mongodb/MongoDB/Operation/FindOneAndDelete.php
index 03fd6e1a7df..c4b54dadfe0 100644
--- a/cache/stores/mongodb/MongoDB/Operation/FindOneAndDelete.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class FindOneAndDelete implements Executable, Explainable
* 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 @@ class FindOneAndDelete implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/cache/stores/mongodb/MongoDB/Operation/FindOneAndReplace.php b/cache/stores/mongodb/MongoDB/Operation/FindOneAndReplace.php
index dce8a6a9702..0e619b86d21 100644
--- a/cache/stores/mongodb/MongoDB/Operation/FindOneAndReplace.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class FindOneAndReplace implements Executable, Explainable
* 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 @@ class FindOneAndReplace implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/cache/stores/mongodb/MongoDB/Operation/FindOneAndUpdate.php b/cache/stores/mongodb/MongoDB/Operation/FindOneAndUpdate.php
index 98b6cf42c01..e9a592473e5 100644
--- a/cache/stores/mongodb/MongoDB/Operation/FindOneAndUpdate.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class FindOneAndUpdate implements Executable, Explainable
* 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 @@ class FindOneAndUpdate implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/cache/stores/mongodb/MongoDB/Operation/InsertMany.php b/cache/stores/mongodb/MongoDB/Operation/InsertMany.php
index af7bd736181..b8b3c12553c 100644
--- a/cache/stores/mongodb/MongoDB/Operation/InsertMany.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class InsertMany implements Executable
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 @@ class InsertMany implements Executable
* 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 @@ class InsertMany implements Executable
* 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 @@ class InsertMany implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/InsertOne.php b/cache/stores/mongodb/MongoDB/Operation/InsertOne.php
index 9398f179560..d0690a5d57a 100644
--- a/cache/stores/mongodb/MongoDB/Operation/InsertOne.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class InsertOne implements Executable
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 @@ class InsertOne implements Executable
* 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 @@ class InsertOne implements Executable
* 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 @@ class InsertOne implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/ListCollectionNames.php b/cache/stores/mongodb/MongoDB/Operation/ListCollectionNames.php
index 4bc5565a31e..d0700887bf1 100644
--- a/cache/stores/mongodb/MongoDB/Operation/ListCollectionNames.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class ListCollectionNames implements Executable
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return Iterator
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
diff --git a/cache/stores/mongodb/MongoDB/Operation/ListCollections.php b/cache/stores/mongodb/MongoDB/Operation/ListCollections.php
index 8a55f990801..e5702509b49 100644
--- a/cache/stores/mongodb/MongoDB/Operation/ListCollections.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class ListCollections implements Executable
* Execute the operation.
*
* @see Executable::execute()
- * @param Server $server
* @return CollectionInfoIterator
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
diff --git a/cache/stores/mongodb/MongoDB/Operation/ListDatabaseNames.php b/cache/stores/mongodb/MongoDB/Operation/ListDatabaseNames.php
index 950c82b7c48..ccace38f8dc 100644
--- a/cache/stores/mongodb/MongoDB/Operation/ListDatabaseNames.php
+++ b/cache/stores/mongodb/MongoDB/Operation/ListDatabaseNames.php
@@ -72,8 +72,6 @@ class ListDatabaseNames implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/ListDatabases.php b/cache/stores/mongodb/MongoDB/Operation/ListDatabases.php
index 6b0c4ba2c09..a19cf07bb3b 100644
--- a/cache/stores/mongodb/MongoDB/Operation/ListDatabases.php
+++ b/cache/stores/mongodb/MongoDB/Operation/ListDatabases.php
@@ -70,7 +70,6 @@ class ListDatabases implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/ListIndexes.php b/cache/stores/mongodb/MongoDB/Operation/ListIndexes.php
index b6e8a1ea00e..e762d9ca2f3 100644
--- a/cache/stores/mongodb/MongoDB/Operation/ListIndexes.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class ListIndexes implements Executable
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 @@ class ListIndexes implements Executable
* 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 @@ class ListIndexes implements Executable
* 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 @@ class ListIndexes implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/MapReduce.php b/cache/stores/mongodb/MongoDB/Operation/MapReduce.php
index b1e8319ce14..7b97dd0a9cc 100644
--- a/cache/stores/mongodb/MongoDB/Operation/MapReduce.php
+++ b/cache/stores/mongodb/MongoDB/Operation/MapReduce.php
@@ -32,6 +32,7 @@ use MongoDB\Exception\UnsupportedException;
use MongoDB\MapReduceResult;
use stdClass;
+use function assert;
use function current;
use function is_array;
use function is_bool;
@@ -158,7 +159,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 +252,8 @@ class MapReduce implements Executable
$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 +264,6 @@ class MapReduce implements Executable
* 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
@@ -302,6 +302,7 @@ class MapReduce implements Executable
}
$result = current($cursor->toArray());
+ assert($result instanceof stdClass);
$getIterator = $this->createGetIteratorCallable($result, $server);
@@ -310,9 +311,8 @@ class MapReduce implements Executable
/**
* @param string|array|object $out
- * @return void
*/
- private function checkOutDeprecations($out)
+ private function checkOutDeprecations($out): void
{
if (is_string($out)) {
return;
@@ -331,10 +331,8 @@ class MapReduce implements Executable
/**
* Create the mapReduce command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = [
'mapReduce' => $this->collectionName,
@@ -361,12 +359,9 @@ class MapReduce implements Executable
/**
* 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 +392,8 @@ class MapReduce implements Executable
*
* @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/cache/stores/mongodb/MongoDB/Operation/ModifyCollection.php b/cache/stores/mongodb/MongoDB/Operation/ModifyCollection.php
index cd52cb9a0e8..7933859bfda 100644
--- a/cache/stores/mongodb/MongoDB/Operation/ModifyCollection.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class ModifyCollection implements Executable
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 @@ class ModifyCollection implements Executable
* 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 @@ class ModifyCollection implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/RenameCollection.php b/cache/stores/mongodb/MongoDB/Operation/RenameCollection.php
index e489713a3d1..64758b0a788 100644
--- a/cache/stores/mongodb/MongoDB/Operation/RenameCollection.php
+++ b/cache/stores/mongodb/MongoDB/Operation/RenameCollection.php
@@ -18,6 +18,7 @@
namespace MongoDB\Operation;
use MongoDB\Driver\Command;
+use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Server;
use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern;
@@ -104,7 +105,6 @@ class RenameCollection implements Executable
* 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 +127,8 @@ class RenameCollection implements Executable
/**
* Create the renameCollection command.
- *
- * @return Command
*/
- private function createCommand()
+ private function createCommand(): Command
{
$cmd = [
'renameCollection' => $this->fromNamespace,
@@ -150,9 +148,8 @@ class RenameCollection implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/ReplaceOne.php b/cache/stores/mongodb/MongoDB/Operation/ReplaceOne.php
index ef7575ddcb9..d5d117b91d8 100644
--- a/cache/stores/mongodb/MongoDB/Operation/ReplaceOne.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class ReplaceOne implements Executable
* 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/cache/stores/mongodb/MongoDB/Operation/Update.php b/cache/stores/mongodb/MongoDB/Operation/Update.php
index 6ec9a2ac5fa..96a51c53ff7 100644
--- a/cache/stores/mongodb/MongoDB/Operation/Update.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class Update implements Executable, Explainable
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 @@ class Update implements Executable, Explainable
* 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 @@ class Update implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
@@ -241,9 +239,8 @@ class Update implements Executable, Explainable
* 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 @@ class Update implements Executable, Explainable
* 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 @@ class Update implements Executable, Explainable
*
* 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/cache/stores/mongodb/MongoDB/Operation/UpdateMany.php b/cache/stores/mongodb/MongoDB/Operation/UpdateMany.php
index 27a6955adae..e442365a1bf 100644
--- a/cache/stores/mongodb/MongoDB/Operation/UpdateMany.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class UpdateMany implements Executable, Explainable
* 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 @@ class UpdateMany implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/cache/stores/mongodb/MongoDB/Operation/UpdateOne.php b/cache/stores/mongodb/MongoDB/Operation/UpdateOne.php
index 22a01e2a053..a7bfab51827 100644
--- a/cache/stores/mongodb/MongoDB/Operation/UpdateOne.php
+++ b/cache/stores/mongodb/MongoDB/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 @@ class UpdateOne implements Executable, Explainable
* 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 @@ class UpdateOne implements Executable, Explainable
* Returns the command document for this operation.
*
* @see Explainable::getCommandDocument()
- * @param Server $server
* @return array
*/
public function getCommandDocument(Server $server)
diff --git a/cache/stores/mongodb/MongoDB/Operation/Watch.php b/cache/stores/mongodb/MongoDB/Operation/Watch.php
index 7c0ebea0413..9306a5312a6 100644
--- a/cache/stores/mongodb/MongoDB/Operation/Watch.php
+++ b/cache/stores/mongodb/MongoDB/Operation/Watch.php
@@ -36,6 +36,7 @@ use MongoDB\Model\ChangeStreamIterator;
use function array_intersect_key;
use function array_key_exists;
use function array_unshift;
+use function assert;
use function count;
use function is_array;
use function is_bool;
@@ -85,7 +86,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
/** @var string */
private $databaseName;
- /** @var integer|null */
+ /** @var integer */
private $firstBatchSize;
/** @var boolean */
@@ -201,7 +202,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,31 +264,31 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
}
$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();
}
/** @internal */
- final public function commandFailed(CommandFailedEvent $event)
+ final public function commandFailed(CommandFailedEvent $event): void
{
}
/** @internal */
- final public function commandStarted(CommandStartedEvent $event)
+ final public function commandStarted(CommandStartedEvent $event): void
{
if ($event->getCommandName() !== 'aggregate') {
return;
}
- $this->firstBatchSize = null;
+ $this->firstBatchSize = 0;
$this->postBatchResumeToken = null;
}
/** @internal */
- final public function commandSucceeded(CommandSucceededEvent $event)
+ final public function commandSucceeded(CommandSucceededEvent $event): void
{
if ($event->getCommandName() !== 'aggregate') {
return;
@@ -317,7 +318,6 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
* 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)
@@ -326,7 +326,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
{
return new ChangeStream(
$this->createChangeStreamIterator($server),
- function ($resumeToken, $hasAdvanced) {
+ function ($resumeToken, $hasAdvanced): ChangeStreamIterator {
return $this->resume($resumeToken, $hasAdvanced);
}
);
@@ -336,10 +336,8 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
* 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 +347,8 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
/**
* 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,16 +363,16 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
*
* 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);
try {
- return $this->aggregate->execute($server);
+ $cursor = $this->aggregate->execute($server);
+ assert($cursor instanceof Cursor);
+
+ return $cursor;
} finally {
removeSubscriber($this);
}
@@ -411,11 +406,9 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
*
* @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 +446,8 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
* 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/cache/stores/mongodb/MongoDB/Operation/WithTransaction.php b/cache/stores/mongodb/MongoDB/Operation/WithTransaction.php
index 6278972dda1..e31b01b9ee5 100644
--- a/cache/stores/mongodb/MongoDB/Operation/WithTransaction.php
+++ b/cache/stores/mongodb/MongoDB/Operation/WithTransaction.php
@@ -52,11 +52,10 @@ class WithTransaction
* @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 @@ class WithTransaction
* 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/cache/stores/mongodb/MongoDB/UpdateResult.php b/cache/stores/mongodb/MongoDB/UpdateResult.php
index de75afcbc9f..1fbbab600fb 100644
--- a/cache/stores/mongodb/MongoDB/UpdateResult.php
+++ b/cache/stores/mongodb/MongoDB/UpdateResult.php
@@ -43,7 +43,7 @@ class UpdateResult
* This method should only be called if the write was acknowledged.
*
* @see UpdateResult::isAcknowledged()
- * @return integer
+ * @return integer|null
* @throws BadMethodCallException is the write result is unacknowledged
*/
public function getMatchedCount()
@@ -82,7 +82,7 @@ class UpdateResult
* This method should only be called if the write was acknowledged.
*
* @see UpdateResult::isAcknowledged()
- * @return integer
+ * @return integer|null
* @throws BadMethodCallException is the write result is unacknowledged
*/
public function getUpsertedCount()
diff --git a/cache/stores/mongodb/MongoDB/functions.php b/cache/stores/mongodb/MongoDB/functions.php
index c0ab80e9a8c..dd2d94021e5 100644
--- a/cache/stores/mongodb/MongoDB/functions.php
+++ b/cache/stores/mongodb/MongoDB/functions.php
@@ -32,6 +32,7 @@ use MongoDB\Operation\WithTransaction;
use ReflectionClass;
use ReflectionException;
+use function assert;
use function end;
use function get_object_vars;
use function in_array;
@@ -98,7 +99,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 +178,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 +205,6 @@ function is_first_key_operator($document): bool
*
* @internal
* @param mixed $pipeline
- * @return boolean
*/
function is_pipeline($pipeline): bool
{
@@ -234,7 +232,7 @@ function is_pipeline($pipeline): bool
reset($stage);
$key = key($stage);
- if (! isset($key[0]) || $key[0] !== '$') {
+ if (! is_string($key) || substr($key, 0, 1) !== '$') {
return false;
}
}
@@ -247,7 +245,6 @@ function is_pipeline($pipeline): bool
*
* @internal
* @param array $options Command options
- * @return boolean
*/
function is_in_transaction(array $options): bool
{
@@ -266,7 +263,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 +285,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 +318,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 +333,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 +348,6 @@ function server_supports_feature(Server $server, int $feature): bool
*
* @internal
* @param mixed $input
- * @return boolean
*/
function is_string_array($input): bool
{
@@ -417,7 +408,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 +460,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 +473,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 +487,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,13 +502,13 @@ function extract_read_preference_from_options(array $options): ?ReadPreference
* (if given)
*
* @internal
- * @return Server
*/
function select_server(Manager $manager, array $options): Server
{
$session = extract_session_from_options($options);
- if ($session instanceof Session && $session->getServer() !== null) {
- return $session->getServer();
+ $server = $session instanceof Session ? $session->getServer() : null;
+ if ($server !== null) {
+ return $server;
}
$readPreference = extract_read_preference_from_options($options);
@@ -578,5 +563,7 @@ function select_server_for_aggregate_write_stage(Manager $manager, array &$optio
throw $serverSelectionError;
}
+ assert($server instanceof Server);
+
return $server;
}
diff --git a/cache/stores/mongodb/readme_moodle.txt b/cache/stores/mongodb/readme_moodle.txt
index f057b4a9df8..2389559cc0d 100644
--- a/cache/stores/mongodb/readme_moodle.txt
+++ b/cache/stores/mongodb/readme_moodle.txt
@@ -7,6 +7,7 @@ Import procedure:
- Copy all the files and folders from the folder mongodb/src in the cache/stores/mongodb/MongoDB directory.
- Copy the license file from the project root.
- Update thirdpartylibs.xml with the latest version.
-- Check the minim php driver version in https://docs.mongodb.com/drivers/php#compatibility and change the value in the "are_requirements_met" method if necessary.
+- Check the minim php driver version in https://docs.mongodb.com/drivers/php#compatibility and change the
+ value in the "are_requirements_met" method if necessary.
-This version (1.13.1) requires PHP mongodb extension >= 1.14.0
+This version (1.15.0) requires PHP mongodb extension >= 1.14.0
diff --git a/cache/stores/mongodb/thirdpartylibs.xml b/cache/stores/mongodb/thirdpartylibs.xml
index cc422e0ed56..3e4e8bedc42 100644
--- a/cache/stores/mongodb/thirdpartylibs.xml
+++ b/cache/stores/mongodb/thirdpartylibs.xml
@@ -4,7 +4,7 @@
MongoDB
MongoDB PHP Library
This library provides a high-level abstraction around the lower-level PHP driver, also known as the mongodb extension.
- 1.13.1
+ 1.15.0
Apache
2.0
https://github.com/mongodb/mongo-php-driver
diff --git a/cache/stores/mongodb/version.php b/cache/stores/mongodb/version.php
index 9d2a46cb6e6..e0e6b29a5be 100644
--- a/cache/stores/mongodb/version.php
+++ b/cache/stores/mongodb/version.php
@@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die;
-$plugin->version = 2022112800; // The current module version (Date: YYYYMMDDXX).
+$plugin->version = 2022112801; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2022111800; // Requires this Moodle version.
-$plugin->component = 'cachestore_mongodb'; // Full name of the plugin.
\ No newline at end of file
+$plugin->component = 'cachestore_mongodb'; // Full name of the plugin.