@@ -137,7 +137,7 @@ final class BulkWrite
137
137
*
138
138
* @param string $databaseName Database name
139
139
* @param string $collectionName Collection name
140
- * @param array $operations List of write operations
140
+ * @param array $operations List of write operations
141
141
* @psalm-param list<OperationType> $operations
142
142
* @param array $options Command options
143
143
* @throws InvalidArgumentException for parameter/option parsing errors
@@ -285,7 +285,7 @@ private function createExecuteOptions(): array
285
285
*/
286
286
private function validateOperations (array $ operations , ?DocumentCodec $ codec , Encoder $ builderEncoder ): array
287
287
{
288
- foreach ($ operations as $ i => $ operation ) {
288
+ foreach ($ operations as $ i => & $ operation ) {
289
289
if (! is_array ($ operation )) {
290
290
throw InvalidArgumentException::invalidType (sprintf ('$operations[%d] ' , $ i ), $ operation , 'array ' );
291
291
}
@@ -310,14 +310,14 @@ private function validateOperations(array $operations, ?DocumentCodec $codec, En
310
310
// $args[0] was already validated above. Since DocumentCodec::encode will always return a Document
311
311
// instance, there is no need to re-validate the returned value here.
312
312
if ($ codec ) {
313
- $ operations [ $ i ] [$ type ][0 ] = $ codec ->encode ($ args [0 ]);
313
+ $ operation [$ type ][0 ] = $ codec ->encode ($ args [0 ]);
314
314
}
315
315
316
316
break ;
317
317
318
318
case self ::DELETE_MANY :
319
319
case self ::DELETE_ONE :
320
- $ operations [ $ i ] [$ type ][0 ] = $ builderEncoder ->encodeIfSupported ($ args [0 ]);
320
+ $ operation [$ type ][0 ] = $ builderEncoder ->encodeIfSupported ($ args [0 ]);
321
321
322
322
if (! isset ($ args [1 ])) {
323
323
$ args [1 ] = [];
@@ -333,19 +333,19 @@ private function validateOperations(array $operations, ?DocumentCodec $codec, En
333
333
throw InvalidArgumentException::expectedDocumentType (sprintf ('$operations[%d]["%s"][1]["collation"] ' , $ i , $ type ), $ args [1 ]['collation ' ]);
334
334
}
335
335
336
- $ operations [ $ i ] [$ type ][1 ] = $ args [1 ];
336
+ $ operation [$ type ][1 ] = $ args [1 ];
337
337
338
338
break ;
339
339
340
340
case self ::REPLACE_ONE :
341
- $ operations [ $ i ] [$ type ][0 ] = $ builderEncoder ->encodeIfSupported ($ args [0 ]);
341
+ $ operation [$ type ][0 ] = $ builderEncoder ->encodeIfSupported ($ args [0 ]);
342
342
343
343
if (! isset ($ args [1 ]) && ! array_key_exists (1 , $ args )) {
344
344
throw new InvalidArgumentException (sprintf ('Missing second argument for $operations[%d]["%s"] ' , $ i , $ type ));
345
345
}
346
346
347
347
if ($ codec ) {
348
- $ operations [ $ i ] [$ type ][1 ] = $ codec ->encode ($ args [1 ]);
348
+ $ operation [$ type ][1 ] = $ codec ->encode ($ args [1 ]);
349
349
}
350
350
351
351
if (! is_document ($ args [1 ])) {
@@ -388,19 +388,19 @@ private function validateOperations(array $operations, ?DocumentCodec $codec, En
388
388
throw InvalidArgumentException::invalidType (sprintf ('$operations[%d]["%s"][2]["upsert"] ' , $ i , $ type ), $ args [2 ]['upsert ' ], 'boolean ' );
389
389
}
390
390
391
- $ operations [ $ i ] [$ type ][2 ] = $ args [2 ];
391
+ $ operation [$ type ][2 ] = $ args [2 ];
392
392
393
393
break ;
394
394
395
395
case self ::UPDATE_MANY :
396
396
case self ::UPDATE_ONE :
397
- $ operations [ $ i ] [$ type ][0 ] = $ builderEncoder ->encodeIfSupported ($ args [0 ]);
397
+ $ operation [$ type ][0 ] = $ builderEncoder ->encodeIfSupported ($ args [0 ]);
398
398
399
399
if (! isset ($ args [1 ]) && ! array_key_exists (1 , $ args )) {
400
400
throw new InvalidArgumentException (sprintf ('Missing second argument for $operations[%d]["%s"] ' , $ i , $ type ));
401
401
}
402
402
403
- $ operations [ $ i ] [$ type ][1 ] = $ args [1 ] = $ builderEncoder ->encodeIfSupported ($ args [1 ]);
403
+ $ operation [$ type ][1 ] = $ args [1 ] = $ builderEncoder ->encodeIfSupported ($ args [1 ]);
404
404
405
405
if ((! is_document ($ args [1 ]) || ! is_first_key_operator ($ args [1 ])) && ! is_pipeline ($ args [1 ])) {
406
406
throw new InvalidArgumentException (sprintf ('Expected update operator(s) or non-empty pipeline for $operations[%d]["%s"][1] ' , $ i , $ type ));
@@ -437,7 +437,7 @@ private function validateOperations(array $operations, ?DocumentCodec $codec, En
437
437
throw InvalidArgumentException::invalidType (sprintf ('$operations[%d]["%s"][2]["upsert"] ' , $ i , $ type ), $ args [2 ]['upsert ' ], 'boolean ' );
438
438
}
439
439
440
- $ operations [ $ i ] [$ type ][2 ] = $ args [2 ];
440
+ $ operation [$ type ][2 ] = $ args [2 ];
441
441
442
442
break ;
443
443
0 commit comments