44
55namespace Patchlevel \Rango ;
66
7- /** @template T of array */
87final class Collection
98{
109 public function __construct (
@@ -20,7 +19,10 @@ public function __construct(
2019 */
2120 public function countDocuments (array $ filter = [], array $ options = []): int
2221 {
23- return $ this ->client ->run (new Operation \Count ($ this ->databaseName , $ this ->collectionName , $ filter , $ options ));
22+ /** @var int $count */
23+ $ count = $ this ->client ->run (new Operation \Count ($ this ->databaseName , $ this ->collectionName , $ filter , $ options ));
24+
25+ return $ count ;
2426 }
2527
2628 /**
@@ -29,7 +31,10 @@ public function countDocuments(array $filter = [], array $options = []): int
2931 */
3032 public function deleteMany (array $ filter , array $ options = []): DeleteResult
3133 {
32- return $ this ->client ->run (new Operation \Delete ($ this ->databaseName , $ this ->collectionName , $ filter , true ));
34+ /** @var DeleteResult $result */
35+ $ result = $ this ->client ->run (new Operation \Delete ($ this ->databaseName , $ this ->collectionName , $ filter , true ));
36+
37+ return $ result ;
3338 }
3439
3540 /**
@@ -38,7 +43,10 @@ public function deleteMany(array $filter, array $options = []): DeleteResult
3843 */
3944 public function deleteOne (array $ filter , array $ options = []): DeleteResult
4045 {
41- return $ this ->client ->run (new Operation \Delete ($ this ->databaseName , $ this ->collectionName , $ filter , false ));
46+ /** @var DeleteResult $result */
47+ $ result = $ this ->client ->run (new Operation \Delete ($ this ->databaseName , $ this ->collectionName , $ filter , false ));
48+
49+ return $ result ;
4250 }
4351
4452 public function drop (): void
@@ -50,21 +58,25 @@ public function drop(): void
5058 * @param array<string, mixed> $filter
5159 * @param array<string, mixed> $options
5260 *
53- * @return Cursor<T>
61+ * @return Cursor
5462 */
5563 public function find (array $ filter = [], array $ options = []): Cursor
5664 {
57- return $ this ->client ->run (new Operation \Find ($ this ->databaseName , $ this ->collectionName , $ filter , $ options ));
65+ /** @var Cursor $cursor */
66+ $ cursor = $ this ->client ->run (new Operation \Find ($ this ->databaseName , $ this ->collectionName , $ filter , $ options ));
67+
68+ return $ cursor ;
5869 }
5970
6071 /**
6172 * @param array<string, mixed> $filter
6273 * @param array<string, mixed> $options
6374 *
64- * @return T |null
75+ * @return array<string, mixed> |null
6576 */
6677 public function findOne (array $ filter = [], array $ options = []): array |null
6778 {
79+ /** @var Cursor|null $result */
6880 $ result = $ this ->client ->run (new Operation \FindOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ options ));
6981
7082 if (!$ result instanceof Cursor) {
@@ -82,7 +94,10 @@ public function findOne(array $filter = [], array $options = []): array|null
8294 */
8395 public function insertMany (array $ documents , array $ options = []): InsertManyResult
8496 {
85- return $ this ->client ->run (new Operation \InsertMany ($ this ->databaseName , $ this ->collectionName , $ documents , $ options ));
97+ /** @var InsertManyResult $result */
98+ $ result = $ this ->client ->run (new Operation \InsertMany ($ this ->databaseName , $ this ->collectionName , $ documents , $ options ));
99+
100+ return $ result ;
86101 }
87102
88103 /**
@@ -91,7 +106,10 @@ public function insertMany(array $documents, array $options = []): InsertManyRes
91106 */
92107 public function insertOne (array $ document , array $ options = []): InsertOneResult
93108 {
94- return $ this ->client ->run (new Operation \InsertOne ($ this ->databaseName , $ this ->collectionName , $ document , $ options ));
109+ /** @var InsertOneResult $result */
110+ $ result = $ this ->client ->run (new Operation \InsertOne ($ this ->databaseName , $ this ->collectionName , $ document , $ options ));
111+
112+ return $ result ;
95113 }
96114
97115 /**
@@ -101,7 +119,10 @@ public function insertOne(array $document, array $options = []): InsertOneResult
101119 */
102120 public function replaceOne (array $ filter , array $ replacement , array $ options = []): UpdateResult
103121 {
104- return $ this ->client ->run (new Operation \ReplaceOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ replacement , $ options ));
122+ /** @var UpdateResult $result */
123+ $ result = $ this ->client ->run (new Operation \ReplaceOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ replacement , $ options ));
124+
125+ return $ result ;
105126 }
106127
107128 /**
@@ -111,7 +132,10 @@ public function replaceOne(array $filter, array $replacement, array $options = [
111132 */
112133 public function updateMany (array $ filter , array $ update , array $ options = []): UpdateResult
113134 {
114- return $ this ->client ->run (new Operation \Update ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options , true ));
135+ /** @var UpdateResult $result */
136+ $ result = $ this ->client ->run (new Operation \Update ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options , true ));
137+
138+ return $ result ;
115139 }
116140
117141 /**
@@ -121,18 +145,24 @@ public function updateMany(array $filter, array $update, array $options = []): U
121145 */
122146 public function updateOne (array $ filter , array $ update , array $ options = []): UpdateResult
123147 {
124- return $ this ->client ->run (new Operation \Update ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options , false ));
148+ /** @var UpdateResult $result */
149+ $ result = $ this ->client ->run (new Operation \Update ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options , false ));
150+
151+ return $ result ;
125152 }
126153
127154 /**
128155 * @param list<array<string, mixed>> $pipeline
129156 * @param array<string, mixed> $options
130157 *
131- * @return Cursor<T>
158+ * @return Cursor
132159 */
133160 public function aggregate (array $ pipeline , array $ options = []): Cursor
134161 {
135- return $ this ->client ->run (new Operation \Aggregate ($ this ->databaseName , $ this ->collectionName , $ pipeline , $ options ));
162+ /** @var Cursor $cursor */
163+ $ cursor = $ this ->client ->run (new Operation \Aggregate ($ this ->databaseName , $ this ->collectionName , $ pipeline , $ options ));
164+
165+ return $ cursor ;
136166 }
137167
138168 /**
@@ -143,17 +173,21 @@ public function aggregate(array $pipeline, array $options = []): Cursor
143173 */
144174 public function distinct (string $ fieldName , array $ filter = [], array $ options = []): array
145175 {
146- return $ this ->client ->run (new Operation \Distinct ($ this ->databaseName , $ this ->collectionName , $ fieldName , $ filter , $ options ));
176+ /** @var list<mixed> $result */
177+ $ result = $ this ->client ->run (new Operation \Distinct ($ this ->databaseName , $ this ->collectionName , $ fieldName , $ filter , $ options ));
178+
179+ return $ result ;
147180 }
148181
149182 /**
150183 * @param array<string, mixed> $filter
151184 * @param array<string, mixed> $options
152185 *
153- * @return T |null
186+ * @return array<string, mixed> |null
154187 */
155188 public function findOneAndDelete (array $ filter , array $ options = []): array |null
156189 {
190+ /** @var Cursor|null $result */
157191 $ result = $ this ->client ->run (new Operation \FindOneAndDelete ($ this ->databaseName , $ this ->collectionName , $ filter , $ options ));
158192
159193 if (!$ result instanceof Cursor) {
@@ -170,10 +204,11 @@ public function findOneAndDelete(array $filter, array $options = []): array|null
170204 * @param array<string, mixed> $replacement
171205 * @param array<string, mixed> $options
172206 *
173- * @return T |null
207+ * @return array<string, mixed> |null
174208 */
175209 public function findOneAndReplace (array $ filter , array $ replacement , array $ options = []): array |null
176210 {
211+ /** @var Cursor|null $result */
177212 $ result = $ this ->client ->run (new Operation \FindOneAndReplace ($ this ->databaseName , $ this ->collectionName , $ filter , $ replacement , $ options ));
178213
179214 if (!$ result instanceof Cursor) {
@@ -190,10 +225,11 @@ public function findOneAndReplace(array $filter, array $replacement, array $opti
190225 * @param array<string, mixed> $update
191226 * @param array<string, mixed> $options
192227 *
193- * @return T |null
228+ * @return array<string, mixed> |null
194229 */
195230 public function findOneAndUpdate (array $ filter , array $ update , array $ options = []): array |null
196231 {
232+ /** @var Cursor|null $result */
197233 $ result = $ this ->client ->run (new Operation \FindOneAndUpdate ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options ));
198234
199235 if (!$ result instanceof Cursor) {
@@ -206,12 +242,15 @@ public function findOneAndUpdate(array $filter, array $update, array $options =
206242 }
207243
208244 /**
209- * @param list<array<string, array<string, mixed>>> $operations
210- * @param array<string, mixed> $options
245+ * @param list<array<string, list< array<string, mixed> >>> $operations
246+ * @param array<string, mixed> $options
211247 */
212248 public function bulkWrite (array $ operations , array $ options = []): BulkWriteResult
213249 {
214- return $ this ->client ->run (new Operation \BulkWrite ($ this ->databaseName , $ this ->collectionName , $ operations , $ options ));
250+ /** @var BulkWriteResult $result */
251+ $ result = $ this ->client ->run (new Operation \BulkWrite ($ this ->databaseName , $ this ->collectionName , $ operations , $ options ));
252+
253+ return $ result ;
215254 }
216255
217256 /**
@@ -231,6 +270,9 @@ public function dropIndex(string $name): void
231270 /** @return list<array{name: string}> */
232271 public function listIndexes (): array
233272 {
234- return $ this ->client ->run (new Operation \ListIndexes ($ this ->databaseName , $ this ->collectionName ));
273+ /** @var list<array{name: string}> $indexes */
274+ $ indexes = $ this ->client ->run (new Operation \ListIndexes ($ this ->databaseName , $ this ->collectionName ));
275+
276+ return $ indexes ;
235277 }
236278}
0 commit comments