44
55namespace Patchlevel \Rango ;
66
7+ use function assert ;
8+ use function is_int ;
9+
710final class Collection
811{
912 public function __construct (
@@ -19,8 +22,8 @@ public function __construct(
1922 */
2023 public function countDocuments (array $ filter = [], array $ options = []): int
2124 {
22- /** @var int $count */
2325 $ count = $ this ->client ->run (new Operation \Count ($ this ->databaseName , $ this ->collectionName , $ filter , $ options ));
26+ assert (is_int ($ count ));
2427
2528 return $ count ;
2629 }
@@ -31,8 +34,8 @@ public function countDocuments(array $filter = [], array $options = []): int
3134 */
3235 public function deleteMany (array $ filter , array $ options = []): DeleteResult
3336 {
34- /** @var DeleteResult $result */
3537 $ result = $ this ->client ->run (new Operation \Delete ($ this ->databaseName , $ this ->collectionName , $ filter , true ));
38+ assert ($ result instanceof DeleteResult);
3639
3740 return $ result ;
3841 }
@@ -43,8 +46,8 @@ public function deleteMany(array $filter, array $options = []): DeleteResult
4346 */
4447 public function deleteOne (array $ filter , array $ options = []): DeleteResult
4548 {
46- /** @var DeleteResult $result */
4749 $ result = $ this ->client ->run (new Operation \Delete ($ this ->databaseName , $ this ->collectionName , $ filter , false ));
50+ assert ($ result instanceof DeleteResult);
4851
4952 return $ result ;
5053 }
@@ -57,13 +60,11 @@ public function drop(): void
5760 /**
5861 * @param array<string, mixed> $filter
5962 * @param array<string, mixed> $options
60- *
61- * @return Cursor
6263 */
6364 public function find (array $ filter = [], array $ options = []): Cursor
6465 {
65- /** @var Cursor $cursor */
6666 $ cursor = $ this ->client ->run (new Operation \Find ($ this ->databaseName , $ this ->collectionName , $ filter , $ options ));
67+ assert ($ cursor instanceof Cursor);
6768
6869 return $ cursor ;
6970 }
@@ -76,8 +77,8 @@ public function find(array $filter = [], array $options = []): Cursor
7677 */
7778 public function findOne (array $ filter = [], array $ options = []): array |null
7879 {
79- /** @var Cursor|null $result */
8080 $ result = $ this ->client ->run (new Operation \FindOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ options ));
81+ assert ($ result instanceof Cursor || $ result === null );
8182
8283 if (!$ result instanceof Cursor) {
8384 return null ;
@@ -94,8 +95,8 @@ public function findOne(array $filter = [], array $options = []): array|null
9495 */
9596 public function insertMany (array $ documents , array $ options = []): InsertManyResult
9697 {
97- /** @var InsertManyResult $result */
9898 $ result = $ this ->client ->run (new Operation \InsertMany ($ this ->databaseName , $ this ->collectionName , $ documents , $ options ));
99+ assert ($ result instanceof InsertManyResult);
99100
100101 return $ result ;
101102 }
@@ -106,8 +107,8 @@ public function insertMany(array $documents, array $options = []): InsertManyRes
106107 */
107108 public function insertOne (array $ document , array $ options = []): InsertOneResult
108109 {
109- /** @var InsertOneResult $result */
110110 $ result = $ this ->client ->run (new Operation \InsertOne ($ this ->databaseName , $ this ->collectionName , $ document , $ options ));
111+ assert ($ result instanceof InsertOneResult);
111112
112113 return $ result ;
113114 }
@@ -119,8 +120,8 @@ public function insertOne(array $document, array $options = []): InsertOneResult
119120 */
120121 public function replaceOne (array $ filter , array $ replacement , array $ options = []): UpdateResult
121122 {
122- /** @var UpdateResult $result */
123123 $ result = $ this ->client ->run (new Operation \ReplaceOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ replacement , $ options ));
124+ assert ($ result instanceof UpdateResult);
124125
125126 return $ result ;
126127 }
@@ -132,8 +133,8 @@ public function replaceOne(array $filter, array $replacement, array $options = [
132133 */
133134 public function updateMany (array $ filter , array $ update , array $ options = []): UpdateResult
134135 {
135- /** @var UpdateResult $result */
136136 $ result = $ this ->client ->run (new Operation \Update ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options , true ));
137+ assert ($ result instanceof UpdateResult);
137138
138139 return $ result ;
139140 }
@@ -145,22 +146,20 @@ public function updateMany(array $filter, array $update, array $options = []): U
145146 */
146147 public function updateOne (array $ filter , array $ update , array $ options = []): UpdateResult
147148 {
148- /** @var UpdateResult $result */
149149 $ result = $ this ->client ->run (new Operation \Update ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options , false ));
150+ assert ($ result instanceof UpdateResult);
150151
151152 return $ result ;
152153 }
153154
154155 /**
155156 * @param list<array<string, mixed>> $pipeline
156157 * @param array<string, mixed> $options
157- *
158- * @return Cursor
159158 */
160159 public function aggregate (array $ pipeline , array $ options = []): Cursor
161160 {
162- /** @var Cursor $cursor */
163161 $ cursor = $ this ->client ->run (new Operation \Aggregate ($ this ->databaseName , $ this ->collectionName , $ pipeline , $ options ));
162+ assert ($ cursor instanceof Cursor);
164163
165164 return $ cursor ;
166165 }
@@ -187,8 +186,8 @@ public function distinct(string $fieldName, array $filter = [], array $options =
187186 */
188187 public function findOneAndDelete (array $ filter , array $ options = []): array |null
189188 {
190- /** @var Cursor|null $result */
191189 $ result = $ this ->client ->run (new Operation \FindOneAndDelete ($ this ->databaseName , $ this ->collectionName , $ filter , $ options ));
190+ assert ($ result instanceof Cursor || $ result === null );
192191
193192 if (!$ result instanceof Cursor) {
194193 return null ;
@@ -208,8 +207,8 @@ public function findOneAndDelete(array $filter, array $options = []): array|null
208207 */
209208 public function findOneAndReplace (array $ filter , array $ replacement , array $ options = []): array |null
210209 {
211- /** @var Cursor|null $result */
212210 $ result = $ this ->client ->run (new Operation \FindOneAndReplace ($ this ->databaseName , $ this ->collectionName , $ filter , $ replacement , $ options ));
211+ assert ($ result instanceof Cursor || $ result === null );
213212
214213 if (!$ result instanceof Cursor) {
215214 return null ;
@@ -229,8 +228,8 @@ public function findOneAndReplace(array $filter, array $replacement, array $opti
229228 */
230229 public function findOneAndUpdate (array $ filter , array $ update , array $ options = []): array |null
231230 {
232- /** @var Cursor|null $result */
233231 $ result = $ this ->client ->run (new Operation \FindOneAndUpdate ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options ));
232+ assert ($ result instanceof Cursor || $ result === null );
234233
235234 if (!$ result instanceof Cursor) {
236235 return null ;
@@ -243,12 +242,12 @@ public function findOneAndUpdate(array $filter, array $update, array $options =
243242
244243 /**
245244 * @param list<array<string, list<array<string, mixed>>>> $operations
246- * @param array<string, mixed> $options
245+ * @param array<string, mixed> $options
247246 */
248247 public function bulkWrite (array $ operations , array $ options = []): BulkWriteResult
249248 {
250- /** @var BulkWriteResult $result */
251249 $ result = $ this ->client ->run (new Operation \BulkWrite ($ this ->databaseName , $ this ->collectionName , $ operations , $ options ));
250+ assert ($ result instanceof BulkWriteResult);
252251
253252 return $ result ;
254253 }
0 commit comments