@@ -137,7 +137,7 @@ final class BulkWrite
137137     * 
138138     * @param string $databaseName   Database name 
139139     * @param string $collectionName Collection name 
140-      * @param array $operations List of write operations 
140+      * @param array   $operations      List of write operations 
141141     * @psalm-param list<OperationType> $operations 
142142     * @param array  $options        Command options 
143143     * @throws InvalidArgumentException for parameter/option parsing errors 
@@ -285,7 +285,7 @@ private function createExecuteOptions(): array
285285     */ 
286286    private  function  validateOperations (array  $ operations , ?DocumentCodec   $ codec , Encoder   $ builderEncoder ): array 
287287    {
288-         foreach  ($ operations  as  $ i  => $ operation ) {
288+         foreach  ($ operations  as  $ i  => & $ operation ) {
289289            if  (! is_array ($ operation )) {
290290                throw  InvalidArgumentException::invalidType (sprintf ('$operations[%d] ' , $ i ), $ operation , 'array ' );
291291            }
@@ -310,14 +310,14 @@ private function validateOperations(array $operations, ?DocumentCodec $codec, En
310310                    // $args[0] was already validated above. Since DocumentCodec::encode will always return a Document 
311311                    // instance, there is no need to re-validate the returned value here. 
312312                    if  ($ codec ) {
313-                         $ operations [ $ i ] [$ type ][0 ] = $ codec ->encode ($ args [0 ]);
313+                         $ operation  [$ type ][0 ] = $ codec ->encode ($ args [0 ]);
314314                    }
315315
316316                    break ;
317317
318318                case  self ::DELETE_MANY :
319319                case  self ::DELETE_ONE :
320-                     $ operations [ $ i ] [$ type ][0 ] = $ builderEncoder ->encodeIfSupported ($ args [0 ]);
320+                     $ operation  [$ type ][0 ] = $ builderEncoder ->encodeIfSupported ($ args [0 ]);
321321
322322                    if  (! isset ($ args [1 ])) {
323323                        $ args [1 ] = [];
@@ -333,19 +333,19 @@ private function validateOperations(array $operations, ?DocumentCodec $codec, En
333333                        throw  InvalidArgumentException::expectedDocumentType (sprintf ('$operations[%d]["%s"][1]["collation"] ' , $ i , $ type ), $ args [1 ]['collation ' ]);
334334                    }
335335
336-                     $ operations [ $ i ] [$ type ][1 ] = $ args [1 ];
336+                     $ operation  [$ type ][1 ] = $ args [1 ];
337337
338338                    break ;
339339
340340                case  self ::REPLACE_ONE :
341-                     $ operations [ $ i ] [$ type ][0 ] = $ builderEncoder ->encodeIfSupported ($ args [0 ]);
341+                     $ operation  [$ type ][0 ] = $ builderEncoder ->encodeIfSupported ($ args [0 ]);
342342
343343                    if  (! isset ($ args [1 ]) && ! array_key_exists (1 , $ args )) {
344344                        throw  new  InvalidArgumentException (sprintf ('Missing second argument for $operations[%d]["%s"] ' , $ i , $ type ));
345345                    }
346346
347347                    if  ($ codec ) {
348-                         $ operations [ $ i ] [$ type ][1 ] = $ codec ->encode ($ args [1 ]);
348+                         $ operation  [$ type ][1 ] = $ codec ->encode ($ args [1 ]);
349349                    }
350350
351351                    if  (! is_document ($ args [1 ])) {
@@ -388,19 +388,19 @@ private function validateOperations(array $operations, ?DocumentCodec $codec, En
388388                        throw  InvalidArgumentException::invalidType (sprintf ('$operations[%d]["%s"][2]["upsert"] ' , $ i , $ type ), $ args [2 ]['upsert ' ], 'boolean ' );
389389                    }
390390
391-                     $ operations [ $ i ] [$ type ][2 ] = $ args [2 ];
391+                     $ operation  [$ type ][2 ] = $ args [2 ];
392392
393393                    break ;
394394
395395                case  self ::UPDATE_MANY :
396396                case  self ::UPDATE_ONE :
397-                     $ operations [ $ i ] [$ type ][0 ] = $ builderEncoder ->encodeIfSupported ($ args [0 ]);
397+                     $ operation  [$ type ][0 ] = $ builderEncoder ->encodeIfSupported ($ args [0 ]);
398398
399399                    if  (! isset ($ args [1 ]) && ! array_key_exists (1 , $ args )) {
400400                        throw  new  InvalidArgumentException (sprintf ('Missing second argument for $operations[%d]["%s"] ' , $ i , $ type ));
401401                    }
402402
403-                     $ operations [ $ i ] [$ type ][1 ] = $ args [1 ] = $ builderEncoder ->encodeIfSupported ($ args [1 ]);
403+                     $ operation  [$ type ][1 ] = $ args [1 ] = $ builderEncoder ->encodeIfSupported ($ args [1 ]);
404404
405405                    if  ((! is_document ($ args [1 ]) || ! is_first_key_operator ($ args [1 ])) && ! is_pipeline ($ args [1 ])) {
406406                        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
437437                        throw  InvalidArgumentException::invalidType (sprintf ('$operations[%d]["%s"][2]["upsert"] ' , $ i , $ type ), $ args [2 ]['upsert ' ], 'boolean ' );
438438                    }
439439
440-                     $ operations [ $ i ] [$ type ][2 ] = $ args [2 ];
440+                     $ operation  [$ type ][2 ] = $ args [2 ];
441441
442442                    break ;
443443
0 commit comments