diff --git a/.evergreen/config.yml b/.evergreen/config.yml
index 2c7fcb3b9..1c4e2a22a 100644
--- a/.evergreen/config.yml
+++ b/.evergreen/config.yml
@@ -71,5 +71,3 @@ include:
- filename: .evergreen/config/generated/test/require-api-version.yml
- filename: .evergreen/config/generated/test/csfle.yml
- filename: .evergreen/config/generated/test-variant/modern-php-full.yml
- - filename: .evergreen/config/generated/test-variant/phpc.yml
- - filename: .evergreen/config/generated/test-variant/lowest.yml
diff --git a/.evergreen/config/generate-config.php b/.evergreen/config/generate-config.php
index 3bd1c710b..3629bf13f 100644
--- a/.evergreen/config/generate-config.php
+++ b/.evergreen/config/generate-config.php
@@ -55,8 +55,9 @@
// Test variants
$allFiles[] = generateConfigs('buildvariants', 'test-variant', 'phpVersion', 'modern-php-full.yml', $supportedPhpVersions);
-$allFiles[] = generateConfigs('buildvariants', 'test-variant', 'phpVersion', 'phpc.yml', [$latestPhpVersion]);
-$allFiles[] = generateConfigs('buildvariants', 'test-variant', 'phpVersion', 'lowest.yml', [$lowestPhpVersion]);
+// TODO: Re-enable when 2.0.0 is released
+// $allFiles[] = generateConfigs('buildvariants', 'test-variant', 'phpVersion', 'phpc.yml', [$latestPhpVersion]);
+// $allFiles[] = generateConfigs('buildvariants', 'test-variant', 'phpVersion', 'lowest.yml', [$lowestPhpVersion]);
echo "Generated config. Use the following list to import files:\n";
echo implode("\n", array_map('getImportConfig', $allFiles)) . "\n";
diff --git a/.evergreen/config/generated/build/build-extension.yml b/.evergreen/config/generated/build/build-extension.yml
index 22adcfc8a..02033b002 100644
--- a/.evergreen/config/generated/build/build-extension.yml
+++ b/.evergreen/config/generated/build/build-extension.yml
@@ -7,37 +7,41 @@ tasks:
vars:
PHP_VERSION: "8.3"
- func: "compile extension"
- - func: "upload extension"
- - name: "build-php-8.3-lowest"
- tags: ["build", "php8.3", "lowest", "pr", "tag"]
- commands:
- - func: "locate PHP binaries"
- vars:
- PHP_VERSION: "8.3"
- - func: "compile extension"
- vars:
- EXTENSION_VERSION: "1.20.0"
- - func: "upload extension"
- - name: "build-php-8.3-next-stable"
- tags: ["build", "php8.3", "next-stable", "pr", "tag"]
- commands:
- - func: "locate PHP binaries"
- vars:
- PHP_VERSION: "8.3"
- - func: "compile extension"
- vars:
- EXTENSION_BRANCH: "v1.20"
- - func: "upload extension"
- - name: "build-php-8.3-next-minor"
- tags: ["build", "php8.3", "next-minor"]
- commands:
- - func: "locate PHP binaries"
- vars:
- PHP_VERSION: "8.3"
- - func: "compile extension"
+ # TODO: remove once 2.0.0 is released
vars:
- EXTENSION_BRANCH: "v1.x"
+ EXTENSION_BRANCH: "v2.x"
- func: "upload extension"
+ # TODO: re-enable once 2.0.0 is released
+# - name: "build-php-8.3-lowest"
+# tags: ["build", "php8.3", "lowest", "pr", "tag"]
+# commands:
+# - func: "locate PHP binaries"
+# vars:
+# PHP_VERSION: "8.3"
+# - func: "compile extension"
+# vars:
+# EXTENSION_VERSION: "2.0.0"
+# - func: "upload extension"
+# - name: "build-php-8.3-next-stable"
+# tags: ["build", "php8.3", "next-stable", "pr", "tag"]
+# commands:
+# - func: "locate PHP binaries"
+# vars:
+# PHP_VERSION: "8.3"
+# - func: "compile extension"
+# vars:
+# EXTENSION_BRANCH: "v2.0"
+# - func: "upload extension"
+# - name: "build-php-8.3-next-minor"
+# tags: ["build", "php8.3", "next-minor"]
+# commands:
+# - func: "locate PHP binaries"
+# vars:
+# PHP_VERSION: "8.3"
+# - func: "compile extension"
+# vars:
+# EXTENSION_BRANCH: "v2.x"
+# - func: "upload extension"
- name: "build-php-8.2"
tags: ["build", "php8.2", "stable", "pr", "tag"]
commands:
@@ -45,37 +49,41 @@ tasks:
vars:
PHP_VERSION: "8.2"
- func: "compile extension"
- - func: "upload extension"
- - name: "build-php-8.2-lowest"
- tags: ["build", "php8.2", "lowest", "pr", "tag"]
- commands:
- - func: "locate PHP binaries"
- vars:
- PHP_VERSION: "8.2"
- - func: "compile extension"
- vars:
- EXTENSION_VERSION: "1.20.0"
- - func: "upload extension"
- - name: "build-php-8.2-next-stable"
- tags: ["build", "php8.2", "next-stable", "pr", "tag"]
- commands:
- - func: "locate PHP binaries"
- vars:
- PHP_VERSION: "8.2"
- - func: "compile extension"
+ # TODO: remove once 2.0.0 is released
vars:
- EXTENSION_BRANCH: "v1.20"
- - func: "upload extension"
- - name: "build-php-8.2-next-minor"
- tags: ["build", "php8.2", "next-minor"]
- commands:
- - func: "locate PHP binaries"
- vars:
- PHP_VERSION: "8.2"
- - func: "compile extension"
- vars:
- EXTENSION_BRANCH: "v1.x"
+ EXTENSION_BRANCH: "v2.x"
- func: "upload extension"
+ # TODO: re-enable once 2.0.0 is released
+# - name: "build-php-8.2-lowest"
+# tags: ["build", "php8.2", "lowest", "pr", "tag"]
+# commands:
+# - func: "locate PHP binaries"
+# vars:
+# PHP_VERSION: "8.2"
+# - func: "compile extension"
+# vars:
+# EXTENSION_VERSION: "2.0.0"
+# - func: "upload extension"
+# - name: "build-php-8.2-next-stable"
+# tags: ["build", "php8.2", "next-stable", "pr", "tag"]
+# commands:
+# - func: "locate PHP binaries"
+# vars:
+# PHP_VERSION: "8.2"
+# - func: "compile extension"
+# vars:
+# EXTENSION_BRANCH: "v2.0"
+# - func: "upload extension"
+# - name: "build-php-8.2-next-minor"
+# tags: ["build", "php8.2", "next-minor"]
+# commands:
+# - func: "locate PHP binaries"
+# vars:
+# PHP_VERSION: "8.2"
+# - func: "compile extension"
+# vars:
+# EXTENSION_BRANCH: "v2.x"
+# - func: "upload extension"
- name: "build-php-8.1"
tags: ["build", "php8.1", "stable", "pr", "tag"]
commands:
@@ -83,34 +91,38 @@ tasks:
vars:
PHP_VERSION: "8.1"
- func: "compile extension"
- - func: "upload extension"
- - name: "build-php-8.1-lowest"
- tags: ["build", "php8.1", "lowest", "pr", "tag"]
- commands:
- - func: "locate PHP binaries"
- vars:
- PHP_VERSION: "8.1"
- - func: "compile extension"
- vars:
- EXTENSION_VERSION: "1.20.0"
- - func: "upload extension"
- - name: "build-php-8.1-next-stable"
- tags: ["build", "php8.1", "next-stable", "pr", "tag"]
- commands:
- - func: "locate PHP binaries"
- vars:
- PHP_VERSION: "8.1"
- - func: "compile extension"
- vars:
- EXTENSION_BRANCH: "v1.20"
- - func: "upload extension"
- - name: "build-php-8.1-next-minor"
- tags: ["build", "php8.1", "next-minor"]
- commands:
- - func: "locate PHP binaries"
- vars:
- PHP_VERSION: "8.1"
- - func: "compile extension"
+ # TODO: remove once 2.0.0 is released
vars:
- EXTENSION_BRANCH: "v1.x"
+ EXTENSION_BRANCH: "v2.x"
- func: "upload extension"
+ # TODO: re-enable once 2.0.0 is released
+# - name: "build-php-8.1-lowest"
+# tags: ["build", "php8.1", "lowest", "pr", "tag"]
+# commands:
+# - func: "locate PHP binaries"
+# vars:
+# PHP_VERSION: "8.1"
+# - func: "compile extension"
+# vars:
+# EXTENSION_VERSION: "2.0.0"
+# - func: "upload extension"
+# - name: "build-php-8.1-next-stable"
+# tags: ["build", "php8.1", "next-stable", "pr", "tag"]
+# commands:
+# - func: "locate PHP binaries"
+# vars:
+# PHP_VERSION: "8.1"
+# - func: "compile extension"
+# vars:
+# EXTENSION_BRANCH: "v2.0"
+# - func: "upload extension"
+# - name: "build-php-8.1-next-minor"
+# tags: ["build", "php8.1", "next-minor"]
+# commands:
+# - func: "locate PHP binaries"
+# vars:
+# PHP_VERSION: "8.1"
+# - func: "compile extension"
+# vars:
+# EXTENSION_BRANCH: "v2.x"
+# - func: "upload extension"
diff --git a/.evergreen/config/generated/test-variant/lowest.yml b/.evergreen/config/generated/test-variant/lowest.yml
deleted file mode 100644
index ce3b5fc69..000000000
--- a/.evergreen/config/generated/test-variant/lowest.yml
+++ /dev/null
@@ -1,16 +0,0 @@
-# This file is generated automatically - please edit the "templates/test-variant/lowest.yml" template file instead.
-buildvariants:
- - name: test-rhel80-php-8.1-local-lowest
- tags: ["test", "rhel", "x64", "php8.1", "pr", "tag"]
- display_name: "Test: RHEL 8.0, PHP 8.1, Lowest Dependencies"
- run_on: rhel80-small
- expansions:
- FETCH_BUILD_VARIANT: "build-rhel80"
- FETCH_BUILD_TASK: "build-php-8.1-lowest"
- PHP_VERSION: "8.1"
- DEPENDENCIES: "lowest"
- depends_on:
- - variant: "build-rhel80"
- name: "build-php-8.1-lowest"
- tasks:
- - ".replicaset .local .4.0 !.csfle"
diff --git a/.evergreen/config/generated/test-variant/phpc.yml b/.evergreen/config/generated/test-variant/phpc.yml
deleted file mode 100644
index e0eb428ce..000000000
--- a/.evergreen/config/generated/test-variant/phpc.yml
+++ /dev/null
@@ -1,42 +0,0 @@
-# This file is generated automatically - please edit the "templates/test-variant/phpc.yml" template file instead.
-buildvariants:
- # Variants with different PHPC versions
- - name: test-debian12-php-8.3-phpc-next-stable
- tags: ["test", "debian", "x64", "php8.3", "pr", "tag"]
- display_name: "Test: Debian 12, PHP 8.3, PHPC next-stable"
- run_on: debian12-small
- expansions:
- FETCH_BUILD_VARIANT: "build-debian12"
- FETCH_BUILD_TASK: "build-php-8.3-next-stable"
- PHP_VERSION: "8.3"
- depends_on:
- - variant: "build-debian12"
- name: "build-php-8.3-next-stable"
- tasks:
- - ".standalone .local !.csfle !.4.0 !.4.2 !.4.4 !.5.0 !.6.0"
- - ".replicaset .local !.csfle !.4.0 !.4.2 !.4.4 !.5.0 !.6.0"
- - ".sharded .local !.csfle !.4.0 !.4.2 !.4.4 !.5.0 !.6.0"
- - ".loadbalanced .local !.csfle !.4.0 !.4.2 !.4.4 !.5.0 !.6.0"
- - "test_serverless_task_group"
- - "test_serverless_proxy_task_group"
- - "test-atlas-data-lake"
-
- - name: test-debian12-php-8.3-phpc-next-minor
- tags: ["test", "debian", "x64", "php8.3"]
- display_name: "Test: Debian 12, PHP 8.3, PHPC next-minor"
- run_on: debian12-small
- expansions:
- FETCH_BUILD_VARIANT: "build-debian12"
- FETCH_BUILD_TASK: "build-php-8.3-next-minor"
- PHP_VERSION: "8.3"
- depends_on:
- - variant: "build-debian12"
- name: "build-php-8.3-next-minor"
- tasks:
- - ".standalone .local !.csfle !.4.0 !.4.2 !.4.4 !.5.0 !.6.0"
- - ".replicaset .local !.csfle !.4.0 !.4.2 !.4.4 !.5.0 !.6.0"
- - ".sharded .local !.csfle !.4.0 !.4.2 !.4.4 !.5.0 !.6.0"
- - ".loadbalanced .local !.csfle !.4.0 !.4.2 !.4.4 !.5.0 !.6.0"
- - "test_serverless_task_group"
- - "test_serverless_proxy_task_group"
- - "test-atlas-data-lake"
diff --git a/.evergreen/config/templates/build/build-extension.yml b/.evergreen/config/templates/build/build-extension.yml
index 869c0a9e4..1599967ab 100644
--- a/.evergreen/config/templates/build/build-extension.yml
+++ b/.evergreen/config/templates/build/build-extension.yml
@@ -5,34 +5,38 @@
vars:
PHP_VERSION: "%phpVersion%"
- func: "compile extension"
- - func: "upload extension"
- - name: "build-php-%phpVersion%-lowest"
- tags: ["build", "php%phpVersion%", "lowest", "pr", "tag"]
- commands:
- - func: "locate PHP binaries"
- vars:
- PHP_VERSION: "%phpVersion%"
- - func: "compile extension"
- vars:
- EXTENSION_VERSION: "1.20.0"
- - func: "upload extension"
- - name: "build-php-%phpVersion%-next-stable"
- tags: ["build", "php%phpVersion%", "next-stable", "pr", "tag"]
- commands:
- - func: "locate PHP binaries"
- vars:
- PHP_VERSION: "%phpVersion%"
- - func: "compile extension"
- vars:
- EXTENSION_BRANCH: "v1.20"
- - func: "upload extension"
- - name: "build-php-%phpVersion%-next-minor"
- tags: ["build", "php%phpVersion%", "next-minor"]
- commands:
- - func: "locate PHP binaries"
- vars:
- PHP_VERSION: "%phpVersion%"
- - func: "compile extension"
+ # TODO: remove once 2.0.0 is released
vars:
- EXTENSION_BRANCH: "v1.x"
+ EXTENSION_BRANCH: "v2.x"
- func: "upload extension"
+ # TODO: re-enable once 2.0.0 is released
+# - name: "build-php-%phpVersion%-lowest"
+# tags: ["build", "php%phpVersion%", "lowest", "pr", "tag"]
+# commands:
+# - func: "locate PHP binaries"
+# vars:
+# PHP_VERSION: "%phpVersion%"
+# - func: "compile extension"
+# vars:
+# EXTENSION_VERSION: "2.0.0"
+# - func: "upload extension"
+# - name: "build-php-%phpVersion%-next-stable"
+# tags: ["build", "php%phpVersion%", "next-stable", "pr", "tag"]
+# commands:
+# - func: "locate PHP binaries"
+# vars:
+# PHP_VERSION: "%phpVersion%"
+# - func: "compile extension"
+# vars:
+# EXTENSION_BRANCH: "v2.0"
+# - func: "upload extension"
+# - name: "build-php-%phpVersion%-next-minor"
+# tags: ["build", "php%phpVersion%", "next-minor"]
+# commands:
+# - func: "locate PHP binaries"
+# vars:
+# PHP_VERSION: "%phpVersion%"
+# - func: "compile extension"
+# vars:
+# EXTENSION_BRANCH: "v2.x"
+# - func: "upload extension"
diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml
index 462e4d67e..b03f7779f 100644
--- a/.github/workflows/coding-standards.yml
+++ b/.github/workflows/coding-standards.yml
@@ -13,7 +13,9 @@ on:
env:
PHP_VERSION: "8.2"
- DRIVER_VERSION: "stable"
+ # TODO: change to "stable" once 2.0.0 is released
+ # DRIVER_VERSION: "stable"
+ DRIVER_VERSION: "mongodb/mongo-php-driver@v2.x"
jobs:
phpcs:
diff --git a/.github/workflows/generator.yml b/.github/workflows/generator.yml
index 2427a41eb..711befabd 100644
--- a/.github/workflows/generator.yml
+++ b/.github/workflows/generator.yml
@@ -13,9 +13,9 @@ on:
env:
PHP_VERSION: "8.2"
- # TODO: change to "stable" once 1.20.0 is released
+ # TODO: change to "stable" once 2.0.0 is released
# DRIVER_VERSION: "stable"
- DRIVER_VERSION: "mongodb/mongo-php-driver@v1.20"
+ DRIVER_VERSION: "mongodb/mongo-php-driver@v2.x"
jobs:
psalm:
diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml
index 0103bdcd1..82919098f 100644
--- a/.github/workflows/static-analysis.yml
+++ b/.github/workflows/static-analysis.yml
@@ -19,7 +19,9 @@ on:
env:
PHP_VERSION: "8.2"
- DRIVER_VERSION: "stable"
+ # TODO: change to "stable" once 2.0.0 is released
+ # DRIVER_VERSION: "stable"
+ DRIVER_VERSION: "mongodb/mongo-php-driver@v2.x"
jobs:
psalm:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index e198604e3..e9cf73916 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -12,7 +12,9 @@ on:
- "feature/*"
env:
- DRIVER_VERSION: "stable"
+ # TODO: change to "stable" once 2.0.0 is released
+ # DRIVER_VERSION: "stable"
+ DRIVER_VERSION: "mongodb/mongo-php-driver@v2.x"
jobs:
phpunit:
diff --git a/UPGRADE-2.0.md b/UPGRADE-2.0.md
new file mode 100644
index 000000000..516b57929
--- /dev/null
+++ b/UPGRADE-2.0.md
@@ -0,0 +1,83 @@
+UPGRADE FROM 1.x to 2.0
+========================
+
+ * Classes in the namespace `MongoDB\Operation\` are `final`.
+ * All methods in interfaces and classes now define a return type.
+ * The `MongoDB\ChangeStream::CURSOR_NOT_FOUND` constant is now private.
+ * The `MongoDB\Operation\Watch::FULL_DOCUMENT_DEFAULT` constant has been
+ removed.
+ * The `getNamespace` and `isGeoHaystack` methods have been removed from the
+ `MongoDB\Model\IndexInfo` class.
+ * The `maxScan`, `modifiers`, `oplogReplay`, and `snapshot` options for `find`
+ and `findOne` operations have been removed.
+ * The `MongoDB\Collection::mapReduce` method has been removed. Use
+ [aggregation pipeline](https://www.mongodb.com/docs/manual/reference/map-reduce-to-aggregation-pipeline/)
+ instead.
+ * The following classes and interfaces have been removed without replacement:
+ * `MongoDB\MapReduceResult`
+ * `MongoDB\Model\CollectionInfoCommandIterator`
+ * `MongoDB\Model\CollectionInfoIterator`
+ * `MongoDB\Model\DatabaseInfoIterator`
+ * `MongoDB\Model\DatabaseInfoLegacyIterator`
+ * `MongoDB\Model\IndexInfoIterator`
+ * `MongoDB\Model\IndexInfoIteratorIterator`
+ * `MongoDB\Operation\Executable`
+ * The `flags` and `autoIndexId` options for
+ `MongoDB\Database::createCollection()` have been removed. Additionally, the
+ `USE_POWER_OF_2_SIZES` and `NO_PADDING` constants in
+ `MongoDB\Operation\CreateCollection` have been removed.
+
+Operations with no result
+-------------------------
+
+The following operations no longer return the raw command result. The return
+type changed to `void`. In case of an error, an exception is thrown.
+
+ * `MongoDB\Client`: `dropDatabase`
+ * `MongoDB\Collection`: `drop`, `dropIndex`, `dropIndexes`, `dropSearchIndex`, `rename`
+ * `MongoDB\Database`: `createCollection`, `drop`, `dropCollection`, `renameCollection`
+ * `MongoDB\Database::createEncryptedCollection()` returns the list of encrypted fields
+
+If you still need to access the raw command result, you can use a
+[`CommandSubscriber`](https://www.php.net/manual/en/class.mongodb-driver-monitoring-commandsubscriber.php).
+
+GridFS
+------
+
+ * The `md5` is no longer calculated when a file is uploaded to GridFS.
+ Applications that require a file digest should implement it outside GridFS
+ and store in metadata.
+
+ ```php
+ $hash = hash_file('sha256', $filename);
+ $bucket->openUploadStream($fileId, ['metadata' => ['hash' => $hash]]);
+ ```
+
+ * The fields `contentType` and `aliases` are no longer stored in the `files`
+ collection. Applications that require this information should store it in
+ metadata.
+
+ **Before:**
+ ```php
+ $bucket->openUploadStream($fileId, ['contentType' => 'image/png']);
+ ```
+
+ **After:**
+ ```php
+ $bucket->openUploadStream($fileId, ['metadata' => ['contentType' => 'image/png']]);
+ ```
+
+UnsupportedException method removals
+------------------------------------
+
+The following methods have been removed from the
+`MongoDB\Exception\UnsupportedException` class:
+ * `allowDiskUseNotSupported`
+ * `arrayFiltersNotSupported`
+ * `collationNotSupported`
+ * `explainNotSupported`
+ * `readConcernNotSupported`
+ * `writeConcernNotSupported`
+
+The remaining methods have been marked as internal and may be removed in a
+future minor version. Only the class itself is covered by the BC promise.
diff --git a/composer.json b/composer.json
index 5a2c10def..cc7fabf52 100644
--- a/composer.json
+++ b/composer.json
@@ -11,9 +11,8 @@
],
"require": {
"php": "^8.1",
- "ext-hash": "*",
"ext-json": "*",
- "ext-mongodb": "^1.20.0",
+ "ext-mongodb": "^2.0",
"composer-runtime-api": "^2.0",
"psr/log": "^1.1.4|^2|^3",
"symfony/polyfill-php80": "^1.27",
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index de542ac64..3c2b9441b 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -133,14 +133,6 @@
-
-
-
-
- src
-
-
-
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 039b43007..6521b8544 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -5,11 +5,7 @@
name]]>
-
-
-
-
@@ -23,6 +19,9 @@
+
+
+
@@ -180,14 +179,6 @@
count($queriesOrArrayOfQueries[0]) > 0]]>
-
-
-
-
-
-
-
-
@@ -324,6 +315,7 @@
getArrayCopy()]]>
+ getArrayCopy()]]>
@@ -331,6 +323,7 @@
+
@@ -339,6 +332,15 @@
+
+
+
+
+ ]]>
+
+
+ ]]>
+
cursor->nextBatch]]>
@@ -354,39 +356,6 @@
current()]]>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- databases)]]>
-
-
-
- databases)]]>
-
-
-
-
-
-
-
index]]>
@@ -550,9 +519,6 @@
-
- options['typeMap']]]>
-
@@ -624,9 +590,6 @@
-
- options['typeMap']]]>
-
@@ -637,9 +600,6 @@
-
- options['typeMap']]]>
-
@@ -652,9 +612,6 @@
-
- options['typeMap']]]>
-
@@ -684,11 +641,7 @@
options['codec']]]>
options['typeMap']]]>
-
-
-
-
@@ -724,18 +677,6 @@
value ?? null) : null]]>
-
-
-
-
-
-
-
-
-
-
-
-
@@ -785,44 +726,12 @@
-
-
- listCollections->execute($server), $this->databaseName)]]>
-
-
-
-
- listDatabases->execute($server))]]>
-
-
-
-
- databaseName . '.' . $this->collectionName)]]>
-
-
-
-
- result->collection]]>
- result->db]]>
- options['typeMap']]]>
-
-
-
-
-
-
-
-
-
-
-
-
options['typeMap']]]>
@@ -834,9 +743,6 @@
-
- options['typeMap']]]>
-
diff --git a/psalm.xml.dist b/psalm.xml.dist
index 83d825d51..9aa4d0a7e 100644
--- a/psalm.xml.dist
+++ b/psalm.xml.dist
@@ -21,6 +21,9 @@
+
+
+
diff --git a/src/BulkWriteResult.php b/src/BulkWriteResult.php
index 4fb556e0b..43c60ea2d 100644
--- a/src/BulkWriteResult.php
+++ b/src/BulkWriteResult.php
@@ -17,19 +17,16 @@
namespace MongoDB;
+use MongoDB\Driver\Exception\LogicException;
use MongoDB\Driver\WriteResult;
-use MongoDB\Exception\BadMethodCallException;
/**
* Result class for a bulk write operation.
*/
class BulkWriteResult
{
- private bool $isAcknowledged;
-
public function __construct(private WriteResult $writeResult, private array $insertedIds)
{
- $this->isAcknowledged = $writeResult->isAcknowledged();
}
/**
@@ -38,16 +35,11 @@ public function __construct(private WriteResult $writeResult, private array $ins
* This method should only be called if the write was acknowledged.
*
* @see BulkWriteResult::isAcknowledged()
- * @return integer|null
- * @throws BadMethodCallException if the write result is unacknowledged
+ * @throws LogicException if the write result is unacknowledged
*/
- public function getDeletedCount()
+ public function getDeletedCount(): int
{
- if ($this->isAcknowledged) {
- return $this->writeResult->getDeletedCount();
- }
-
- throw BadMethodCallException::unacknowledgedWriteResultAccess(__METHOD__);
+ return $this->writeResult->getDeletedCount();
}
/**
@@ -56,16 +48,11 @@ public function getDeletedCount()
* This method should only be called if the write was acknowledged.
*
* @see BulkWriteResult::isAcknowledged()
- * @return integer|null
- * @throws BadMethodCallException if the write result is unacknowledged
+ * @throws LogicException if the write result is unacknowledged
*/
- public function getInsertedCount()
+ public function getInsertedCount(): int
{
- if ($this->isAcknowledged) {
- return $this->writeResult->getInsertedCount();
- }
-
- throw BadMethodCallException::unacknowledgedWriteResultAccess(__METHOD__);
+ return $this->writeResult->getInsertedCount();
}
/**
@@ -76,10 +63,8 @@ public function getInsertedCount()
* the driver did not generate an ID), the index will contain its "_id"
* field value. Any driver-generated ID will be a MongoDB\BSON\ObjectId
* instance.
- *
- * @return array
*/
- public function getInsertedIds()
+ public function getInsertedIds(): array
{
return $this->insertedIds;
}
@@ -90,16 +75,11 @@ public function getInsertedIds()
* This method should only be called if the write was acknowledged.
*
* @see BulkWriteResult::isAcknowledged()
- * @return integer|null
- * @throws BadMethodCallException if the write result is unacknowledged
+ * @throws LogicException if the write result is unacknowledged
*/
- public function getMatchedCount()
+ public function getMatchedCount(): int
{
- if ($this->isAcknowledged) {
- return $this->writeResult->getMatchedCount();
- }
-
- throw BadMethodCallException::unacknowledgedWriteResultAccess(__METHOD__);
+ return $this->writeResult->getMatchedCount();
}
/**
@@ -111,16 +91,11 @@ public function getMatchedCount()
* This method should only be called if the write was acknowledged.
*
* @see BulkWriteResult::isAcknowledged()
- * @return integer|null
- * @throws BadMethodCallException if the write result is unacknowledged
+ * @throws LogicException if the write result is unacknowledged
*/
- public function getModifiedCount()
+ public function getModifiedCount(): int
{
- if ($this->isAcknowledged) {
- return $this->writeResult->getModifiedCount();
- }
-
- throw BadMethodCallException::unacknowledgedWriteResultAccess(__METHOD__);
+ return $this->writeResult->getModifiedCount();
}
/**
@@ -129,16 +104,11 @@ public function getModifiedCount()
* This method should only be called if the write was acknowledged.
*
* @see BulkWriteResult::isAcknowledged()
- * @return integer|null
- * @throws BadMethodCallException if the write result is unacknowledged
+ * @throws LogicException if the write result is unacknowledged
*/
- public function getUpsertedCount()
+ public function getUpsertedCount(): int
{
- if ($this->isAcknowledged) {
- return $this->writeResult->getUpsertedCount();
- }
-
- throw BadMethodCallException::unacknowledgedWriteResultAccess(__METHOD__);
+ return $this->writeResult->getUpsertedCount();
}
/**
@@ -152,16 +122,11 @@ public function getUpsertedCount()
* This method should only be called if the write was acknowledged.
*
* @see BulkWriteResult::isAcknowledged()
- * @return array
- * @throws BadMethodCallException if the write result is unacknowledged
+ * @throws LogicException if the write result is unacknowledged
*/
- public function getUpsertedIds()
+ public function getUpsertedIds(): array
{
- if ($this->isAcknowledged) {
- return $this->writeResult->getUpsertedIds();
- }
-
- throw BadMethodCallException::unacknowledgedWriteResultAccess(__METHOD__);
+ return $this->writeResult->getUpsertedIds();
}
/**
@@ -169,11 +134,9 @@ public function getUpsertedIds()
*
* If the update was not acknowledged, other fields from the WriteResult
* (e.g. matchedCount) will be undefined.
- *
- * @return boolean
*/
- public function isAcknowledged()
+ public function isAcknowledged(): bool
{
- return $this->isAcknowledged;
+ return $this->writeResult->isAcknowledged();
}
}
diff --git a/src/ChangeStream.php b/src/ChangeStream.php
index 55f25b031..c48cd1483 100644
--- a/src/ChangeStream.php
+++ b/src/ChangeStream.php
@@ -21,22 +21,16 @@
use MongoDB\BSON\Document;
use MongoDB\BSON\Int64;
use MongoDB\Codec\DocumentCodec;
-use MongoDB\Driver\CursorId;
use MongoDB\Driver\Exception\ConnectionException;
use MongoDB\Driver\Exception\RuntimeException;
use MongoDB\Driver\Exception\ServerException;
use MongoDB\Exception\BadMethodCallException;
use MongoDB\Exception\ResumeTokenException;
use MongoDB\Model\ChangeStreamIterator;
-use ReturnTypeWillChange;
use function assert;
use function call_user_func;
use function in_array;
-use function sprintf;
-use function trigger_error;
-
-use const E_USER_DEPRECATED;
/**
* Iterator for a change stream.
@@ -49,11 +43,7 @@
*/
class ChangeStream implements Iterator
{
- /**
- * @deprecated 1.4
- * @todo make this constant private in 2.0 (see: PHPLIB-360)
- */
- public const CURSOR_NOT_FOUND = 43;
+ private const CURSOR_NOT_FOUND = 43;
private const RESUMABLE_ERROR_CODES = [
6, // HostUnreachable
@@ -88,12 +78,8 @@ class ChangeStream implements Iterator
*/
private bool $hasAdvanced = false;
- /**
- * @see https://php.net/iterator.current
- * @return array|object|null
- */
- #[ReturnTypeWillChange]
- public function current()
+ /** @see https://php.net/iterator.current */
+ public function current(): array|object|null
{
$value = $this->iterator->current();
@@ -106,26 +92,9 @@ public function current()
return $this->codec->decode($value);
}
- /**
- * @return CursorId|Int64
- * @psalm-return ($asInt64 is true ? Int64 : CursorId)
- */
- #[ReturnTypeWillChange]
- public function getCursorId(bool $asInt64 = false)
+ public function getCursorId(): Int64
{
- if (! $asInt64) {
- @trigger_error(
- sprintf(
- 'The method "%s" will no longer return a "%s" instance in the future. Pass "true" as argument to change to the new behavior and receive a "%s" instance instead.',
- __METHOD__,
- CursorId::class,
- Int64::class,
- ),
- E_USER_DEPRECATED,
- );
- }
-
- return $this->iterator->getInnerIterator()->getId($asInt64);
+ return $this->iterator->getInnerIterator()->getId();
}
/**
@@ -134,20 +103,14 @@ public function getCursorId(bool $asInt64 = false)
* Null may be returned if no change documents have been iterated and the
* server did not include a postBatchResumeToken in its aggregate or getMore
* command response.
- *
- * @return array|object|null
*/
- public function getResumeToken()
+ public function getResumeToken(): array|object|null
{
return $this->iterator->getResumeToken();
}
- /**
- * @see https://php.net/iterator.key
- * @return int|null
- */
- #[ReturnTypeWillChange]
- public function key()
+ /** @see https://php.net/iterator.key */
+ public function key(): ?int
{
if ($this->valid()) {
return $this->key;
@@ -158,11 +121,9 @@ public function key()
/**
* @see https://php.net/iterator.next
- * @return void
* @throws ResumeTokenException
*/
- #[ReturnTypeWillChange]
- public function next()
+ public function next(): void
{
try {
$this->iterator->next();
@@ -174,11 +135,9 @@ public function next()
/**
* @see https://php.net/iterator.rewind
- * @return void
* @throws ResumeTokenException
*/
- #[ReturnTypeWillChange]
- public function rewind()
+ public function rewind(): void
{
try {
$this->iterator->rewind();
@@ -191,12 +150,8 @@ public function rewind()
}
}
- /**
- * @see https://php.net/iterator.valid
- * @return boolean
- */
- #[ReturnTypeWillChange]
- public function valid()
+ /** @see https://php.net/iterator.valid */
+ public function valid(): bool
{
return $this->iterator->valid();
}
@@ -255,7 +210,8 @@ private function onIteration(bool $incrementKey): void
* have been received in the last response. Therefore, we can unset the
* resumeCallable. This will free any reference to Watch as well as the
* only reference to any implicit session created therein. */
- if ((string) $this->getCursorId(true) === '0') {
+ // Use a type-unsafe comparison to compare with Int64 instances
+ if ($this->getCursorId() == 0) {
$this->resumeCallable = null;
}
diff --git a/src/Client.php b/src/Client.php
index f21d09d72..43856439b 100644
--- a/src/Client.php
+++ b/src/Client.php
@@ -49,10 +49,6 @@
use function array_diff_key;
use function is_array;
use function is_string;
-use function sprintf;
-use function trigger_error;
-
-use const E_USER_DEPRECATED;
class Client
{
@@ -147,9 +143,8 @@ public function __construct(?string $uri = null, array $uriOptions = [], array $
* 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 [
'manager' => $this->manager,
@@ -170,19 +165,16 @@ public function __debugInfo()
* @see https://php.net/oop5.overloading#object.get
* @see https://php.net/types.string#language.types.string.parsing.complex
* @param string $databaseName Name of the database to select
- * @return Database
*/
- public function __get(string $databaseName)
+ public function __get(string $databaseName): Database
{
return $this->selectDatabase($databaseName);
}
/**
* Return the connection string (i.e. URI).
- *
- * @return string
*/
- public function __toString()
+ public function __toString(): string
{
return $this->uri;
}
@@ -201,10 +193,8 @@ final public function addSubscriber(Subscriber $subscriber): void
* Returns a ClientEncryption instance for explicit encryption and decryption
*
* @param array $options Encryption options
- *
- * @return ClientEncryption
*/
- public function createClientEncryption(array $options)
+ public function createClientEncryption(array $options): ClientEncryption
{
if (isset($options['keyVaultClient'])) {
if ($options['keyVaultClient'] instanceof self) {
@@ -223,19 +213,12 @@ public function createClientEncryption(array $options)
* @see DropDatabase::__construct() for supported options
* @param string $databaseName Database name
* @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
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function dropDatabase(string $databaseName, array $options = [])
+ public function dropDatabase(string $databaseName, array $options = []): void
{
- if (! isset($options['typeMap'])) {
- $options['typeMap'] = $this->typeMap;
- } else {
- @trigger_error(sprintf('The function %s() will return nothing in mongodb/mongodb v2.0, the "typeMap" option is deprecated', __FUNCTION__), E_USER_DEPRECATED);
- }
-
$server = select_server_for_write($this->manager, $options);
if (! isset($options['writeConcern']) && ! is_in_transaction($options)) {
@@ -244,15 +227,13 @@ public function dropDatabase(string $databaseName, array $options = [])
$operation = new DropDatabase($databaseName, $options);
- return $operation->execute($server);
+ $operation->execute($server);
}
/**
* Return the Manager.
- *
- * @return Manager
*/
- public function getManager()
+ public function getManager(): Manager
{
return $this->manager;
}
@@ -261,29 +242,24 @@ public function getManager()
* Return the read concern for this client.
*
* @see https://php.net/manual/en/mongodb-driver-readconcern.isdefault.php
- * @return ReadConcern
*/
- public function getReadConcern()
+ public function getReadConcern(): ReadConcern
{
return $this->readConcern;
}
/**
* Return the read preference for this client.
- *
- * @return ReadPreference
*/
- public function getReadPreference()
+ public function getReadPreference(): ReadPreference
{
return $this->readPreference;
}
/**
* Return the type map for this client.
- *
- * @return array
*/
- public function getTypeMap()
+ public function getTypeMap(): array
{
return $this->typeMap;
}
@@ -292,9 +268,8 @@ public function getTypeMap()
* Return the write concern for this client.
*
* @see https://php.net/manual/en/mongodb-driver-writeconcern.isdefault.php
- * @return WriteConcern
*/
- public function getWriteConcern()
+ public function getWriteConcern(): WriteConcern
{
return $this->writeConcern;
}
@@ -303,6 +278,7 @@ public function getWriteConcern()
* List database names.
*
* @see ListDatabaseNames::__construct() for supported options
+ * @return Iterator
* @throws UnexpectedValueException if the command response was malformed
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -324,7 +300,7 @@ public function listDatabaseNames(array $options = []): Iterator
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function listDatabases(array $options = [])
+ public function listDatabases(array $options = []): Iterator
{
$operation = new ListDatabases($options);
$server = select_server($this->manager, $options);
@@ -349,10 +325,9 @@ final public function removeSubscriber(Subscriber $subscriber): void
* @param string $databaseName Name of the database containing the collection
* @param string $collectionName Name of the collection to select
* @param array $options Collection constructor options
- * @return Collection
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function selectCollection(string $databaseName, string $collectionName, array $options = [])
+ public function selectCollection(string $databaseName, string $collectionName, array $options = []): Collection
{
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];
@@ -365,10 +340,9 @@ public function selectCollection(string $databaseName, string $collectionName, a
* @see Database::__construct() for supported options
* @param string $databaseName Name of the database to select
* @param array $options Database constructor options
- * @return Database
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function selectDatabase(string $databaseName, array $options = [])
+ public function selectDatabase(string $databaseName, array $options = []): Database
{
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];
@@ -380,9 +354,8 @@ public function selectDatabase(string $databaseName, array $options = [])
*
* @see https://php.net/manual/en/mongodb-driver-manager.startsession.php
* @param array $options Session options
- * @return Session
*/
- public function startSession(array $options = [])
+ public function startSession(array $options = []): Session
{
return $this->manager->startSession($options);
}
@@ -393,10 +366,9 @@ public function startSession(array $options = [])
* @see Watch::__construct() for supported options
* @param array $pipeline Aggregation pipeline
* @param array $options Command options
- * @return ChangeStream
* @throws InvalidArgumentException for parameter/option parsing errors
*/
- public function watch(array $pipeline = [], array $options = [])
+ public function watch(array $pipeline = [], array $options = []): ChangeStream
{
if (is_builder_pipeline($pipeline)) {
$pipeline = new Pipeline(...$pipeline);
diff --git a/src/Codec/DecodeIfSupported.php b/src/Codec/DecodeIfSupported.php
index 7fd768011..ea8dde15c 100644
--- a/src/Codec/DecodeIfSupported.php
+++ b/src/Codec/DecodeIfSupported.php
@@ -30,17 +30,13 @@ abstract public function canDecode(mixed $value): bool;
/**
* @psalm-param BSONType $value
- * @return mixed
* @psalm-return NativeType
* @throws UnsupportedValueException if the decoder does not support the value
*/
- abstract public function decode(mixed $value);
+ abstract public function decode(mixed $value): mixed;
- /**
- * @return mixed
- * @psalm-return ($value is BSONType ? NativeType : $value)
- */
- public function decodeIfSupported(mixed $value)
+ /** @psalm-return ($value is BSONType ? NativeType : $value) */
+ public function decodeIfSupported(mixed $value): mixed
{
return $this->canDecode($value) ? $this->decode($value) : $value;
}
diff --git a/src/Codec/Decoder.php b/src/Codec/Decoder.php
index 432fb2dd7..37ff9b263 100644
--- a/src/Codec/Decoder.php
+++ b/src/Codec/Decoder.php
@@ -37,11 +37,10 @@ public function canDecode(mixed $value): bool;
* should throw an exception.
*
* @psalm-param BSONType $value
- * @return mixed
* @psalm-return NativeType
* @throws UnsupportedValueException if the decoder does not support the value
*/
- public function decode(mixed $value);
+ public function decode(mixed $value): mixed;
/**
* Decodes a given value if supported, otherwise returns the value as-is.
@@ -49,8 +48,7 @@ public function decode(mixed $value);
* The DecodeIfSupported trait provides a default implementation of this
* method.
*
- * @return mixed
* @psalm-return ($value is BSONType ? NativeType : $value)
*/
- public function decodeIfSupported(mixed $value);
+ public function decodeIfSupported(mixed $value): mixed;
}
diff --git a/src/Codec/EncodeIfSupported.php b/src/Codec/EncodeIfSupported.php
index 33823cfd6..2ce1fcf53 100644
--- a/src/Codec/EncodeIfSupported.php
+++ b/src/Codec/EncodeIfSupported.php
@@ -30,17 +30,13 @@ abstract public function canEncode(mixed $value): bool;
/**
* @psalm-param NativeType $value
- * @return mixed
* @psalm-return BSONType
* @throws UnsupportedValueException if the encoder does not support the value
*/
- abstract public function encode(mixed $value);
+ abstract public function encode(mixed $value): mixed;
- /**
- * @return mixed
- * @psalm-return ($value is NativeType ? BSONType : $value)
- */
- public function encodeIfSupported(mixed $value)
+ /** @psalm-return ($value is NativeType ? BSONType : $value) */
+ public function encodeIfSupported(mixed $value): mixed
{
return $this->canEncode($value) ? $this->encode($value) : $value;
}
diff --git a/src/Codec/Encoder.php b/src/Codec/Encoder.php
index 0cd0d58cb..c8ee0917b 100644
--- a/src/Codec/Encoder.php
+++ b/src/Codec/Encoder.php
@@ -37,11 +37,10 @@ public function canEncode(mixed $value): bool;
* should throw an exception.
*
* @psalm-param NativeType $value
- * @return mixed
* @psalm-return BSONType
* @throws UnsupportedValueException if the encoder does not support the value
*/
- public function encode(mixed $value);
+ public function encode(mixed $value): mixed;
/**
* Encodes a given value if supported, otherwise returns the value as-is.
@@ -49,8 +48,7 @@ public function encode(mixed $value);
* The EncodeIfSupported trait provides a default implementation of this
* method.
*
- * @return mixed
* @psalm-return ($value is NativeType ? BSONType : $value)
*/
- public function encodeIfSupported(mixed $value);
+ public function encodeIfSupported(mixed $value): mixed;
}
diff --git a/src/Collection.php b/src/Collection.php
index a4ff6326f..055ade77a 100644
--- a/src/Collection.php
+++ b/src/Collection.php
@@ -20,7 +20,6 @@
use Countable;
use Iterator;
use MongoDB\BSON\Document;
-use MongoDB\BSON\JavascriptInterface;
use MongoDB\BSON\PackedArray;
use MongoDB\Builder\BuilderEncoder;
use MongoDB\Builder\Pipeline;
@@ -63,7 +62,6 @@
use MongoDB\Operation\InsertOne;
use MongoDB\Operation\ListIndexes;
use MongoDB\Operation\ListSearchIndexes;
-use MongoDB\Operation\MapReduce;
use MongoDB\Operation\RenameCollection;
use MongoDB\Operation\ReplaceOne;
use MongoDB\Operation\UpdateMany;
@@ -77,11 +75,7 @@
use function array_key_exists;
use function current;
use function is_array;
-use function sprintf;
use function strlen;
-use function trigger_error;
-
-use const E_USER_DEPRECATED;
class Collection
{
@@ -185,9 +179,8 @@ public function __construct(private Manager $manager, private string $databaseNa
* 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 [
'builderEncoder' => $this->builderEncoder,
@@ -206,9 +199,8 @@ public function __debugInfo()
* Return the collection namespace (e.g. "db.collection").
*
* @see https://mongodb.com/docs/manual/core/databases-and-collections/
- * @return string
*/
- public function __toString()
+ public function __toString(): string
{
return $this->databaseName . '.' . $this->collectionName;
}
@@ -219,13 +211,12 @@ public function __toString()
* @see Aggregate::__construct() for supported options
* @param array $pipeline Aggregation pipeline
* @param array $options Command options
- * @return CursorInterface&Iterator
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function aggregate(array $pipeline, array $options = [])
+ public function aggregate(array $pipeline, array $options = []): CursorInterface
{
if (is_builder_pipeline($pipeline)) {
$pipeline = new Pipeline(...$pipeline);
@@ -265,12 +256,11 @@ public function aggregate(array $pipeline, array $options = [])
* @see BulkWrite::__construct() for supported options
* @param array[] $operations List of write operations
* @param array $options Command options
- * @return BulkWriteResult
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function bulkWrite(array $operations, array $options = [])
+ public function bulkWrite(array $operations, array $options = []): BulkWriteResult
{
$options = $this->inheritBuilderEncoder($options);
$options = $this->inheritWriteOptions($options);
@@ -287,7 +277,6 @@ public function bulkWrite(array $operations, array $options = [])
* @see Count::__construct() for supported options
* @param array|object $filter Query by which to filter documents
* @param array $options Command options
- * @return integer
* @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
@@ -295,7 +284,7 @@ public function bulkWrite(array $operations, array $options = [])
*
* @deprecated 1.4
*/
- public function count(array|object $filter = [], array $options = [])
+ public function count(array|object $filter = [], array $options = []): int
{
$filter = $this->builderEncoder->encodeIfSupported($filter);
$options = $this->inheritReadOptions($options);
@@ -311,13 +300,12 @@ public function count(array|object $filter = [], array $options = [])
* @see CountDocuments::__construct() for supported options
* @param array|object $filter Query by which to filter documents
* @param array $options Command options
- * @return integer
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function countDocuments(array|object $filter = [], array $options = [])
+ public function countDocuments(array|object $filter = [], array $options = []): int
{
$filter = $this->builderEncoder->encodeIfSupported($filter);
$options = $this->inheritReadOptions($options);
@@ -340,7 +328,7 @@ public function countDocuments(array|object $filter = [], array $options = [])
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function createIndex(array|object $key, array $options = [])
+ public function createIndex(array|object $key, array $options = []): string
{
$operationOptionKeys = ['comment' => 1, 'commitQuorum' => 1, 'maxTimeMS' => 1, 'session' => 1, 'writeConcern' => 1];
$indexOptions = array_diff_key($options, $operationOptionKeys);
@@ -376,7 +364,7 @@ public function createIndex(array|object $key, array $options = [])
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function createIndexes(array $indexes, array $options = [])
+ public function createIndexes(array $indexes, array $options = []): array
{
$options = $this->inheritWriteOptions($options);
@@ -450,12 +438,11 @@ public function createSearchIndexes(array $indexes, array $options = []): array
* @see https://mongodb.com/docs/manual/reference/command/delete/
* @param array|object $filter Query by which to delete documents
* @param array $options Command options
- * @return DeleteResult
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function deleteMany(array|object $filter, array $options = [])
+ public function deleteMany(array|object $filter, array $options = []): DeleteResult
{
$filter = $this->builderEncoder->encodeIfSupported($filter);
$options = $this->inheritWriteOptions($options);
@@ -472,12 +459,11 @@ public function deleteMany(array|object $filter, array $options = [])
* @see https://mongodb.com/docs/manual/reference/command/delete/
* @param array|object $filter Query by which to delete documents
* @param array $options Command options
- * @return DeleteResult
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function deleteOne(array|object $filter, array $options = [])
+ public function deleteOne(array|object $filter, array $options = []): DeleteResult
{
$filter = $this->builderEncoder->encodeIfSupported($filter);
$options = $this->inheritWriteOptions($options);
@@ -494,13 +480,12 @@ public function deleteOne(array|object $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 array
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function distinct(string $fieldName, array|object $filter = [], array $options = [])
+ public function distinct(string $fieldName, array|object $filter = [], array $options = []): array
{
$filter = $this->builderEncoder->encodeIfSupported($filter);
$options = $this->inheritReadOptions($options);
@@ -516,15 +501,13 @@ public function distinct(string $fieldName, array|object $filter = [], array $op
*
* @see DropCollection::__construct() for supported options
* @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
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function drop(array $options = [])
+ public function drop(array $options = []): void
{
$options = $this->inheritWriteOptions($options);
- $options = $this->inheritTypeMap($options, __FUNCTION__);
$server = select_server_for_write($this->manager, $options);
@@ -537,7 +520,7 @@ public function drop(array $options = [])
? new DropEncryptedCollection($this->databaseName, $this->collectionName, $options)
: new DropCollection($this->databaseName, $this->collectionName, $options);
- return $operation->execute($server);
+ $operation->execute($server);
}
/**
@@ -546,12 +529,11 @@ public function drop(array $options = [])
* @see DropIndexes::__construct() for supported options
* @param string|IndexInfo $indexName Index name or model object
* @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
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function dropIndex(string|IndexInfo $indexName, array $options = [])
+ public function dropIndex(string|IndexInfo $indexName, array $options = []): void
{
$indexName = (string) $indexName;
@@ -560,11 +542,10 @@ public function dropIndex(string|IndexInfo $indexName, array $options = [])
}
$options = $this->inheritWriteOptions($options);
- $options = $this->inheritTypeMap($options, __FUNCTION__);
$operation = new DropIndexes($this->databaseName, $this->collectionName, $indexName, $options);
- return $operation->execute(select_server_for_write($this->manager, $options));
+ $operation->execute(select_server_for_write($this->manager, $options));
}
/**
@@ -572,19 +553,17 @@ public function dropIndex(string|IndexInfo $indexName, array $options = [])
*
* @see DropIndexes::__construct() for supported options
* @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
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function dropIndexes(array $options = [])
+ public function dropIndexes(array $options = []): void
{
$options = $this->inheritWriteOptions($options);
- $options = $this->inheritTypeMap($options, __FUNCTION__);
$operation = new DropIndexes($this->databaseName, $this->collectionName, '*', $options);
- return $operation->execute(select_server_for_write($this->manager, $options));
+ $operation->execute(select_server_for_write($this->manager, $options));
}
/**
@@ -610,13 +589,12 @@ public function dropSearchIndex(string $name, array $options = []): void
*
* @see EstimatedDocumentCount::__construct() for supported options
* @param array $options Command options
- * @return integer
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function estimatedDocumentCount(array $options = [])
+ public function estimatedDocumentCount(array $options = []): int
{
$options = $this->inheritReadOptions($options);
@@ -632,12 +610,11 @@ public function estimatedDocumentCount(array $options = [])
* @see https://mongodb.com/docs/manual/reference/command/explain/
* @param Explainable $explainable Command on which to run explain
* @param array $options Additional options
- * @return array|object
* @throws UnsupportedException if explainable or options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function explain(Explainable $explainable, array $options = [])
+ public function explain(Explainable $explainable, array $options = []): array|object
{
$options = $this->inheritReadPreference($options);
$options = $this->inheritTypeMap($options);
@@ -654,12 +631,11 @@ public function explain(Explainable $explainable, array $options = [])
* @see https://mongodb.com/docs/manual/crud/#read-operations
* @param array|object $filter Query by which to filter documents
* @param array $options Additional options
- * @return CursorInterface&Iterator
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function find(array|object $filter = [], array $options = [])
+ public function find(array|object $filter = [], array $options = []): CursorInterface
{
$filter = $this->builderEncoder->encodeIfSupported($filter);
$options = $this->inheritReadOptions($options);
@@ -677,12 +653,11 @@ public function find(array|object $filter = [], array $options = [])
* @see https://mongodb.com/docs/manual/crud/#read-operations
* @param array|object $filter Query by which to filter documents
* @param array $options Additional options
- * @return array|object|null
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function findOne(array|object $filter = [], array $options = [])
+ public function findOne(array|object $filter = [], array $options = []): array|object|null
{
$filter = $this->builderEncoder->encodeIfSupported($filter);
$options = $this->inheritReadOptions($options);
@@ -702,13 +677,12 @@ public function findOne(array|object $filter = [], array $options = [])
* @see https://mongodb.com/docs/manual/reference/command/findAndModify/
* @param array|object $filter Query by which to filter documents
* @param array $options Command options
- * @return array|object|null
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function findOneAndDelete(array|object $filter, array $options = [])
+ public function findOneAndDelete(array|object $filter, array $options = []): array|object|null
{
$filter = $this->builderEncoder->encodeIfSupported($filter);
$options = $this->inheritWriteOptions($options);
@@ -733,13 +707,12 @@ public function findOneAndDelete(array|object $filter, array $options = [])
* @param array|object $filter Query by which to filter documents
* @param array|object $replacement Replacement document
* @param array $options Command options
- * @return array|object|null
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function findOneAndReplace(array|object $filter, array|object $replacement, array $options = [])
+ public function findOneAndReplace(array|object $filter, array|object $replacement, array $options = []): array|object|null
{
$filter = $this->builderEncoder->encodeIfSupported($filter);
$options = $this->inheritWriteOptions($options);
@@ -764,13 +737,12 @@ public function findOneAndReplace(array|object $filter, array|object $replacemen
* @param array|object $filter Query by which to filter documents
* @param array|object $update Update to apply to the matched document
* @param array $options Command options
- * @return array|object|null
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if options are not supported by the selected server
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
- public function findOneAndUpdate(array|object $filter, array|object $update, array $options = [])
+ public function findOneAndUpdate(array|object $filter, array|object $update, array $options = []): array|object|null
{
$filter = $this->builderEncoder->encodeIfSupported($filter);
$options = $this->inheritWriteOptions($options);
@@ -783,30 +755,24 @@ public function findOneAndUpdate(array|object $filter, array|object $update, arr
/**
* Return the collection name.
- *
- * @return string
*/
- public function getCollectionName()
+ public function getCollectionName(): string
{
return $this->collectionName;
}
/**
* Return the database name.
- *
- * @return string
*/
- public function getDatabaseName()
+ public function getDatabaseName(): string
{
return $this->databaseName;
}
/**
* Return the Manager.
- *
- * @return Manager
*/
- public function getManager()
+ public function getManager(): Manager
{
return $this->manager;
}
@@ -815,9 +781,8 @@ public function getManager()
* Return the collection namespace.
*
* @see https://mongodb.com/docs/manual/reference/glossary/#term-namespace
- * @return string
*/
- public function getNamespace()
+ public function getNamespace(): string
{
return $this->databaseName . '.' . $this->collectionName;
}
@@ -826,29 +791,24 @@ public function getNamespace()
* Return the read concern for this collection.
*
* @see https://php.net/manual/en/mongodb-driver-readconcern.isdefault.php
- * @return ReadConcern
*/
- public function getReadConcern()
+ public function getReadConcern(): ReadConcern
{
return $this->readConcern;
}
/**
* Return the read preference for this collection.
- *
- * @return ReadPreference
*/
- public function getReadPreference()
+ public function getReadPreference(): ReadPreference
{
return $this->readPreference;
}
/**
* Return the type map for this collection.
- *
- * @return array
*/
- public function getTypeMap()
+ public function getTypeMap(): array
{
return $this->typeMap;
}
@@ -857,9 +817,8 @@ public function getTypeMap()
* Return the write concern for this collection.
*
* @see https://php.net/manual/en/mongodb-driver-writeconcern.isdefault.php
- * @return WriteConcern
*/
- public function getWriteConcern()
+ public function getWriteConcern(): WriteConcern
{
return $this->writeConcern;
}
@@ -871,11 +830,10 @@ public function getWriteConcern()
* @see https://mongodb.com/docs/manual/reference/command/insert/
* @param list