2626use function is_bool ;
2727use function is_string ;
2828
29- class BulkWriteCommandBuilder
29+ readonly class BulkWriteCommandBuilder
3030{
31- private BulkWriteCommand $ bulkWriteCommand ;
32-
3331 private function __construct (
32+ public BulkWriteCommand $ bulkWriteCommand ,
3433 private string $ namespace ,
3534 private Encoder $ builderEncoder ,
3635 private ?DocumentCodec $ codec ,
37- array $ options ,
3836 ) {
37+ }
38+
39+ public static function createWithCollection (Collection $ collection , array $ options ): self
40+ {
3941 $ options += ['ordered ' => true ];
4042
4143 if (isset ($ options ['bypassDocumentValidation ' ]) && ! is_bool ($ options ['bypassDocumentValidation ' ])) {
@@ -54,26 +56,22 @@ private function __construct(
5456 throw InvalidArgumentException::invalidType ('"verboseResults" option ' , $ options ['verboseResults ' ], 'boolean ' );
5557 }
5658
57- $ this ->bulkWriteCommand = new BulkWriteCommand ($ options );
58- }
59-
60- public static function createWithCollection (Collection $ collection , array $ options ): self
61- {
6259 return new self (
60+ new BulkWriteCommand ($ options ),
6361 $ collection ->getNamespace (),
6462 $ collection ->getBuilderEncoder (),
6563 $ collection ->getCodec (),
66- $ options ,
6764 );
6865 }
6966
7067 public function withCollection (Collection $ collection ): self
7168 {
72- $ this ->namespace = $ collection ->getNamespace ();
73- $ this ->builderEncoder = $ collection ->getBuilderEncoder ();
74- $ this ->codec = $ collection ->getCodec ();
75-
76- return $ this ;
69+ return new self (
70+ $ this ->bulkWriteCommand ,
71+ $ collection ->getNamespace (),
72+ $ collection ->getBuilderEncoder (),
73+ $ collection ->getCodec (),
74+ );
7775 }
7876
7977 public function deleteOne (array |object $ filter , ?array $ options = null ): self
0 commit comments