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