Skip to content

Commit 5949533

Browse files
committed
Ignore static analysis issues
1 parent 26bb3a1 commit 5949533

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

psalm-baseline.xml

+18-2
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@
223223
<MixedPropertyTypeCoercion>
224224
<code><![CDATA[$options['builderEncoder'] ?? new BuilderEncoder()]]></code>
225225
</MixedPropertyTypeCoercion>
226+
<PossiblyInvalidArgument>
227+
<code><![CDATA[$pipeline]]></code>
228+
<code><![CDATA[$pipeline]]></code>
229+
<code><![CDATA[$pipeline]]></code>
230+
</PossiblyInvalidArgument>
226231
</file>
227232
<file src="src/Command/ListCollections.php">
228233
<MixedAssignment>
@@ -417,8 +422,9 @@
417422
<code><![CDATA[$args[0]]]></code>
418423
<code><![CDATA[$args[0]]]></code>
419424
<code><![CDATA[$args[0]]]></code>
420-
<code><![CDATA[$args[1]]]></code>
421-
<code><![CDATA[$args[1]]]></code>
425+
<code><![CDATA[$args[0]]]></code>
426+
<code><![CDATA[$args[0]]]></code>
427+
<code><![CDATA[$args[0]]]></code>
422428
<code><![CDATA[$args[1]]]></code>
423429
<code><![CDATA[$args[1]]]></code>
424430
<code><![CDATA[$args[1]]]></code>
@@ -448,6 +454,7 @@
448454
<code><![CDATA[$args[1]]]></code>
449455
<code><![CDATA[$args[1]]]></code>
450456
<code><![CDATA[$args[1]]]></code>
457+
<code><![CDATA[$args[1]]]></code>
451458
<code><![CDATA[$args[1]['limit']]]></code>
452459
<code><![CDATA[$args[2]]]></code>
453460
<code><![CDATA[$args[2]]]></code>
@@ -458,6 +465,10 @@
458465
<code><![CDATA[$args[2]['multi']]]></code>
459466
<code><![CDATA[$args[2]['multi']]]></code>
460467
<code><![CDATA[$operations[$i][$type][0]]]></code>
468+
<code><![CDATA[$operations[$i][$type][0]]]></code>
469+
<code><![CDATA[$operations[$i][$type][0]]]></code>
470+
<code><![CDATA[$operations[$i][$type][0]]]></code>
471+
<code><![CDATA[$operations[$i][$type][1]]]></code>
461472
<code><![CDATA[$operations[$i][$type][1]]]></code>
462473
<code><![CDATA[$operations[$i][$type][1]]]></code>
463474
<code><![CDATA[$operations[$i][$type][2]]]></code>
@@ -466,9 +477,14 @@
466477
<MixedAssignment>
467478
<code><![CDATA[$args]]></code>
468479
<code><![CDATA[$args]]></code>
480+
<code><![CDATA[$args[1]]]></code>
469481
<code><![CDATA[$args[2]]]></code>
470482
<code><![CDATA[$args[2]]]></code>
471483
<code><![CDATA[$insertedIds[$i]]]></code>
484+
<code><![CDATA[$operations[$i][$type][0]]]></code>
485+
<code><![CDATA[$operations[$i][$type][0]]]></code>
486+
<code><![CDATA[$operations[$i][$type][0]]]></code>
487+
<code><![CDATA[$operations[$i][$type][1]]]></code>
472488
<code><![CDATA[$operations[$i][$type][1]]]></code>
473489
<code><![CDATA[$operations[$i][$type][2]]]></code>
474490
<code><![CDATA[$operations[$i][$type][2]]]></code>

src/Operation/BulkWrite.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function __construct(private string $databaseName, private string $collec
178178
unset($options['writeConcern']);
179179
}
180180

181-
$this->operations = $this->validateOperations($operations, $options['codec'] ?? null);
181+
$this->operations = $this->validateOperations($operations, $options['codec'] ?? null, $options['builderEncoder'] ?? new BuilderEncoder());
182182
$this->options = $options;
183183
}
184184

@@ -197,8 +197,6 @@ public function execute(Server $server)
197197
throw UnsupportedException::writeConcernNotSupportedInTransaction();
198198
}
199199

200-
$builderEncoder = $operation['builderEncoder'] ?? new BuilderEncoder();
201-
202200
$bulk = new Bulk($this->createBulkWriteOptions());
203201
$insertedIds = [];
204202

@@ -209,7 +207,6 @@ public function execute(Server $server)
209207
switch ($type) {
210208
case self::DELETE_MANY:
211209
case self::DELETE_ONE:
212-
$args[0] = $builderEncoder->encodeIfSupported($args[0]);
213210
$bulk->delete($args[0], $args[1]);
214211
break;
215212

@@ -220,8 +217,6 @@ public function execute(Server $server)
220217
case self::UPDATE_MANY:
221218
case self::UPDATE_ONE:
222219
case self::REPLACE_ONE:
223-
$args[0] = $builderEncoder->encodeIfSupported($args[0]);
224-
$args[1] = $builderEncoder->encodeIfSupported($args[1]);
225220
$bulk->update($args[0], $args[1], $args[2]);
226221
break;
227222
}
@@ -278,7 +273,7 @@ private function createExecuteOptions(): array
278273
* @param array[] $operations
279274
* @return array[]
280275
*/
281-
private function validateOperations(array $operations, ?DocumentCodec $codec): array
276+
private function validateOperations(array $operations, ?DocumentCodec $codec, Encoder $builderEncoder): array
282277
{
283278
foreach ($operations as $i => $operation) {
284279
if (! is_array($operation)) {
@@ -312,6 +307,8 @@ private function validateOperations(array $operations, ?DocumentCodec $codec): a
312307

313308
case self::DELETE_MANY:
314309
case self::DELETE_ONE:
310+
$operations[$i][$type][0] = $builderEncoder->encodeIfSupported($args[0]);
311+
315312
if (! isset($args[1])) {
316313
$args[1] = [];
317314
}
@@ -331,6 +328,8 @@ private function validateOperations(array $operations, ?DocumentCodec $codec): a
331328
break;
332329

333330
case self::REPLACE_ONE:
331+
$operations[$i][$type][0] = $builderEncoder->encodeIfSupported($args[0]);
332+
334333
if (! isset($args[1]) && ! array_key_exists(1, $args)) {
335334
throw new InvalidArgumentException(sprintf('Missing second argument for $operations[%d]["%s"]', $i, $type));
336335
}
@@ -381,10 +380,14 @@ private function validateOperations(array $operations, ?DocumentCodec $codec): a
381380

382381
case self::UPDATE_MANY:
383382
case self::UPDATE_ONE:
383+
$operations[$i][$type][0] = $builderEncoder->encodeIfSupported($args[0]);
384+
384385
if (! isset($args[1]) && ! array_key_exists(1, $args)) {
385386
throw new InvalidArgumentException(sprintf('Missing second argument for $operations[%d]["%s"]', $i, $type));
386387
}
387388

389+
$operations[$i][$type][1] = $args[1] = $builderEncoder->encodeIfSupported($args[1]);
390+
388391
if ((! is_document($args[1]) || ! is_first_key_operator($args[1])) && ! is_pipeline($args[1])) {
389392
throw new InvalidArgumentException(sprintf('Expected update operator(s) or non-empty pipeline for $operations[%d]["%s"][1]', $i, $type));
390393
}

0 commit comments

Comments
 (0)