Skip to content

Commit 170d33f

Browse files
committed
operation refactoring
1 parent fafe5ab commit 170d33f

20 files changed

Lines changed: 459 additions & 83 deletions

phpstan-baseline.neon

Lines changed: 361 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,361 @@
1-
parameters:
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Parameter \#1 \$operation of method Patchlevel\\Rango\\Client\:\:run\(\) expects Patchlevel\\Rango\\Operation\\Operation\<list\<mixed\>\>, Patchlevel\\Rango\\Operation\\Distinct given\.$#'
5+
identifier: argument.type
6+
count: 1
7+
path: src/Collection.php
8+
9+
-
10+
message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#'
11+
identifier: foreach.nonIterable
12+
count: 18
13+
path: src/QueryBuilder.php
14+
15+
-
16+
message: '#^Binary operation "\." between ''\{'' and mixed results in an error\.$#'
17+
identifier: binaryOp.invalid
18+
count: 11
19+
path: src/QueryBuilder.php
20+
21+
-
22+
message: '#^Cannot access offset ''_id'' on mixed\.$#'
23+
identifier: offsetAccess.nonOffsetAccessible
24+
count: 3
25+
path: src/QueryBuilder.php
26+
27+
-
28+
message: '#^Cannot access offset ''as'' on mixed\.$#'
29+
identifier: offsetAccess.nonOffsetAccessible
30+
count: 1
31+
path: src/QueryBuilder.php
32+
33+
-
34+
message: '#^Cannot access offset ''foreignField'' on mixed\.$#'
35+
identifier: offsetAccess.nonOffsetAccessible
36+
count: 1
37+
path: src/QueryBuilder.php
38+
39+
-
40+
message: '#^Cannot access offset ''from'' on mixed\.$#'
41+
identifier: offsetAccess.nonOffsetAccessible
42+
count: 1
43+
path: src/QueryBuilder.php
44+
45+
-
46+
message: '#^Cannot access offset ''localField'' on mixed\.$#'
47+
identifier: offsetAccess.nonOffsetAccessible
48+
count: 1
49+
path: src/QueryBuilder.php
50+
51+
-
52+
message: '#^Cannot cast mixed to float\.$#'
53+
identifier: cast.double
54+
count: 1
55+
path: src/QueryBuilder.php
56+
57+
-
58+
message: '#^Cannot cast mixed to int\.$#'
59+
identifier: cast.int
60+
count: 8
61+
path: src/QueryBuilder.php
62+
63+
-
64+
message: '#^Cannot cast mixed to string\.$#'
65+
identifier: cast.string
66+
count: 5
67+
path: src/QueryBuilder.php
68+
69+
-
70+
message: '#^Parameter \#1 \$array of method Patchlevel\\Rango\\QueryBuilder\:\:isOperatorArray\(\) expects array\<string, mixed\>, array\<mixed, mixed\> given\.$#'
71+
identifier: argument.type
72+
count: 1
73+
path: src/QueryBuilder.php
74+
75+
-
76+
message: '#^Parameter \#1 \$filter of method Patchlevel\\Rango\\QueryBuilder\:\:buildFilter\(\) expects array\<string, mixed\>, mixed given\.$#'
77+
identifier: argument.type
78+
count: 1
79+
path: src/QueryBuilder.php
80+
81+
-
82+
message: '#^Parameter \#1 \$filter of method Patchlevel\\Rango\\QueryBuilder\:\:buildWhere\(\) expects array\<string, mixed\>, array\<mixed, mixed\> given\.$#'
83+
identifier: argument.type
84+
count: 1
85+
path: src/QueryBuilder.php
86+
87+
-
88+
message: '#^Parameter \#1 \$filter of method Patchlevel\\Rango\\QueryBuilder\:\:buildWhere\(\) expects array\<string, mixed\>, mixed given\.$#'
89+
identifier: argument.type
90+
count: 1
91+
path: src/QueryBuilder.php
92+
93+
-
94+
message: '#^Parameter \#1 \$haystack of function str_contains expects string, mixed given\.$#'
95+
identifier: argument.type
96+
count: 2
97+
path: src/QueryBuilder.php
98+
99+
-
100+
message: '#^Parameter \#1 \$identifier of method Patchlevel\\Rango\\QueryBuilder\:\:quoteIdentifier\(\) expects string, mixed given\.$#'
101+
identifier: argument.type
102+
count: 2
103+
path: src/QueryBuilder.php
104+
105+
-
106+
message: '#^Parameter \#1 \$queries of method Patchlevel\\Rango\\QueryBuilder\:\:buildLogicalOperator\(\) expects list\<array\<string, mixed\>\>, mixed given\.$#'
107+
identifier: argument.type
108+
count: 3
109+
path: src/QueryBuilder.php
110+
111+
-
112+
message: '#^Parameter \#1 \$string of function ltrim expects string, mixed given\.$#'
113+
identifier: argument.type
114+
count: 8
115+
path: src/QueryBuilder.php
116+
117+
-
118+
message: '#^Parameter \#1 \$string of method PDO\:\:quote\(\) expects string, mixed given\.$#'
119+
identifier: argument.type
120+
count: 25
121+
path: src/QueryBuilder.php
122+
123+
-
124+
message: '#^Parameter \#1 \$string of method PDO\:\:quote\(\) expects string, string\|false given\.$#'
125+
identifier: argument.type
126+
count: 22
127+
path: src/QueryBuilder.php
128+
129+
-
130+
message: '#^Parameter \#2 \$allInclusions of method Patchlevel\\Rango\\QueryBuilder\:\:buildNestedProjectionForTopKey\(\) expects list\<string\>, non\-empty\-list\<mixed\> given\.$#'
131+
identifier: argument.type
132+
count: 1
133+
path: src/QueryBuilder.php
134+
135+
-
136+
message: '#^Parameter \#2 \$string of function explode expects string, mixed given\.$#'
137+
identifier: argument.type
138+
count: 4
139+
path: src/QueryBuilder.php
140+
141+
-
142+
message: '#^Parameter \#2 \.\.\.\$arrays of function array_merge expects array, mixed given\.$#'
143+
identifier: argument.type
144+
count: 1
145+
path: src/QueryBuilder.php
146+
147+
-
148+
message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#'
149+
identifier: argument.type
150+
count: 1
151+
path: src/QueryBuilder.php
152+
153+
-
154+
message: '#^Parameter \#4 \$allOperators of method Patchlevel\\Rango\\QueryBuilder\:\:buildOperatorFilter\(\) expects array\<string, mixed\>, array\<mixed, mixed\> given\.$#'
155+
identifier: argument.type
156+
count: 1
157+
path: src/QueryBuilder.php
158+
159+
-
160+
message: '#^Possibly invalid array key type mixed\.$#'
161+
identifier: offsetAccess.invalidOffset
162+
count: 1
163+
path: src/QueryBuilder.php
164+
165+
-
166+
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertNotNull\(\) with MongoDB\\Collection\|Patchlevel\\Rango\\Collection will always evaluate to true\.$#'
167+
identifier: method.alreadyNarrowedType
168+
count: 1
169+
path: tests/IntegrationTest.php
170+
171+
-
172+
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertNotNull\(\) with MongoDB\\Database\|Patchlevel\\Rango\\Database will always evaluate to true\.$#'
173+
identifier: method.alreadyNarrowedType
174+
count: 1
175+
path: tests/IntegrationTest.php
176+
177+
-
178+
message: '#^Cannot access offset ''_id'' on array\|object\.$#'
179+
identifier: offsetAccess.nonOffsetAccessible
180+
count: 2
181+
path: tests/IntegrationTest.php
182+
183+
-
184+
message: '#^Cannot access offset ''_id'' on array\|object\|null\.$#'
185+
identifier: offsetAccess.nonOffsetAccessible
186+
count: 19
187+
path: tests/IntegrationTest.php
188+
189+
-
190+
message: '#^Cannot access offset ''age'' on array\|object\|null\.$#'
191+
identifier: offsetAccess.nonOffsetAccessible
192+
count: 2
193+
path: tests/IntegrationTest.php
194+
195+
-
196+
message: '#^Cannot access offset ''avg'' on array\|object\|null\.$#'
197+
identifier: offsetAccess.nonOffsetAccessible
198+
count: 1
199+
path: tests/IntegrationTest.php
200+
201+
-
202+
message: '#^Cannot access offset ''category'' on array\|object\|null\.$#'
203+
identifier: offsetAccess.nonOffsetAccessible
204+
count: 1
205+
path: tests/IntegrationTest.php
206+
207+
-
208+
message: '#^Cannot access offset ''count'' on array\|object\|null\.$#'
209+
identifier: offsetAccess.nonOffsetAccessible
210+
count: 2
211+
path: tests/IntegrationTest.php
212+
213+
-
214+
message: '#^Cannot access offset ''counter'' on array\|object\|null\.$#'
215+
identifier: offsetAccess.nonOffsetAccessible
216+
count: 2
217+
path: tests/IntegrationTest.php
218+
219+
-
220+
message: '#^Cannot access offset ''first'' on array\|object\|null\.$#'
221+
identifier: offsetAccess.nonOffsetAccessible
222+
count: 1
223+
path: tests/IntegrationTest.php
224+
225+
-
226+
message: '#^Cannot access offset ''items'' on array\|object\|null\.$#'
227+
identifier: offsetAccess.nonOffsetAccessible
228+
count: 3
229+
path: tests/IntegrationTest.php
230+
231+
-
232+
message: '#^Cannot access offset ''label'' on mixed\.$#'
233+
identifier: offsetAccess.nonOffsetAccessible
234+
count: 1
235+
path: tests/IntegrationTest.php
236+
237+
-
238+
message: '#^Cannot access offset ''last'' on array\|object\|null\.$#'
239+
identifier: offsetAccess.nonOffsetAccessible
240+
count: 1
241+
path: tests/IntegrationTest.php
242+
243+
-
244+
message: '#^Cannot access offset ''max'' on array\|object\|null\.$#'
245+
identifier: offsetAccess.nonOffsetAccessible
246+
count: 1
247+
path: tests/IntegrationTest.php
248+
249+
-
250+
message: '#^Cannot access offset ''metadata'' on array\|object\|null\.$#'
251+
identifier: offsetAccess.nonOffsetAccessible
252+
count: 2
253+
path: tests/IntegrationTest.php
254+
255+
-
256+
message: '#^Cannot access offset ''min'' on array\|object\|null\.$#'
257+
identifier: offsetAccess.nonOffsetAccessible
258+
count: 1
259+
path: tests/IntegrationTest.php
260+
261+
-
262+
message: '#^Cannot access offset ''name'' on array\|object\.$#'
263+
identifier: offsetAccess.nonOffsetAccessible
264+
count: 5
265+
path: tests/IntegrationTest.php
266+
267+
-
268+
message: '#^Cannot access offset ''name'' on array\|object\|null\.$#'
269+
identifier: offsetAccess.nonOffsetAccessible
270+
count: 7
271+
path: tests/IntegrationTest.php
272+
273+
-
274+
message: '#^Cannot access offset ''name'' on mixed\.$#'
275+
identifier: offsetAccess.nonOffsetAccessible
276+
count: 4
277+
path: tests/IntegrationTest.php
278+
279+
-
280+
message: '#^Cannot access offset ''nickname'' on array\|object\|null\.$#'
281+
identifier: offsetAccess.nonOffsetAccessible
282+
count: 1
283+
path: tests/IntegrationTest.php
284+
285+
-
286+
message: '#^Cannot access offset ''product'' on array\|object\|null\.$#'
287+
identifier: offsetAccess.nonOffsetAccessible
288+
count: 1
289+
path: tests/IntegrationTest.php
290+
291+
-
292+
message: '#^Cannot access offset ''product_details'' on array\|object\|null\.$#'
293+
identifier: offsetAccess.nonOffsetAccessible
294+
count: 4
295+
path: tests/IntegrationTest.php
296+
297+
-
298+
message: '#^Cannot access offset ''score'' on array\|object\|null\.$#'
299+
identifier: offsetAccess.nonOffsetAccessible
300+
count: 1
301+
path: tests/IntegrationTest.php
302+
303+
-
304+
message: '#^Cannot access offset ''tags'' on array\|object\|null\.$#'
305+
identifier: offsetAccess.nonOffsetAccessible
306+
count: 8
307+
path: tests/IntegrationTest.php
308+
309+
-
310+
message: '#^Cannot access offset ''total'' on array\|object\|null\.$#'
311+
identifier: offsetAccess.nonOffsetAccessible
312+
count: 5
313+
path: tests/IntegrationTest.php
314+
315+
-
316+
message: '#^Cannot access offset ''v'' on array\|object\|null\.$#'
317+
identifier: offsetAccess.nonOffsetAccessible
318+
count: 8
319+
path: tests/IntegrationTest.php
320+
321+
-
322+
message: '#^Cannot access offset ''val'' on array\|object\|null\.$#'
323+
identifier: offsetAccess.nonOffsetAccessible
324+
count: 4
325+
path: tests/IntegrationTest.php
326+
327+
-
328+
message: '#^Cannot access offset 0 on mixed\.$#'
329+
identifier: offsetAccess.nonOffsetAccessible
330+
count: 2
331+
path: tests/IntegrationTest.php
332+
333+
-
334+
message: '#^Cannot cast mixed to string\.$#'
335+
identifier: cast.string
336+
count: 4
337+
path: tests/IntegrationTest.php
338+
339+
-
340+
message: '#^Parameter \#2 \$array of method PHPUnit\\Framework\\Assert\:\:assertArrayHasKey\(\) expects array\<mixed\>\|ArrayAccess\<\(int\|string\), mixed\>, array\|object\|null given\.$#'
341+
identifier: argument.type
342+
count: 5
343+
path: tests/IntegrationTest.php
344+
345+
-
346+
message: '#^Parameter \#2 \$array of method PHPUnit\\Framework\\Assert\:\:assertArrayNotHasKey\(\) expects array\<mixed\>\|ArrayAccess\<\(int\|string\), mixed\>, array\|object\|null given\.$#'
347+
identifier: argument.type
348+
count: 4
349+
path: tests/IntegrationTest.php
350+
351+
-
352+
message: '#^Parameter \#2 \$array of method PHPUnit\\Framework\\Assert\:\:assertArrayNotHasKey\(\) expects array\<mixed\>\|ArrayAccess\<\(int\|string\), mixed\>, mixed given\.$#'
353+
identifier: argument.type
354+
count: 1
355+
path: tests/IntegrationTest.php
356+
357+
-
358+
message: '#^Parameter \#2 \$haystack of method PHPUnit\\Framework\\Assert\:\:assertCount\(\) expects Countable\|iterable, mixed given\.$#'
359+
identifier: argument.type
360+
count: 2
361+
path: tests/IntegrationTest.php

src/Client.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,15 @@ public function renameCollection(string $database, string $oldName, string $newN
6060
}
6161

6262
/**
63-
* @template TReturn
6463
* @param Operation\Operation<TReturn> $operation
64+
*
6565
* @return TReturn
66+
*
67+
* @template TReturn
6668
*/
6769
public function run(Operation\Operation $operation): mixed
6870
{
69-
if (
70-
$operation instanceof Operation\InsertOne ||
71-
$operation instanceof Operation\InsertMany ||
72-
$operation instanceof Operation\Find ||
73-
$operation instanceof Operation\FindOne ||
74-
$operation instanceof Operation\Update ||
75-
$operation instanceof Operation\ReplaceOne ||
76-
$operation instanceof Operation\Delete ||
77-
$operation instanceof Operation\Count ||
78-
$operation instanceof Operation\Aggregate ||
79-
$operation instanceof Operation\Distinct ||
80-
$operation instanceof Operation\FindOneAndDelete ||
81-
$operation instanceof Operation\FindOneAndReplace ||
82-
$operation instanceof Operation\FindOneAndUpdate ||
83-
$operation instanceof Operation\BulkWrite ||
84-
$operation instanceof Operation\CreateIndex
85-
) {
71+
if ($operation instanceof Operation\CollectionOperation) {
8672
$this->run(new Operation\CreateCollection($operation->database, $operation->collection));
8773
}
8874

0 commit comments

Comments
 (0)