Skip to content

Commit 066c072

Browse files
committed
BulkWriteCommandBuilder::withCollection returns a new instance
1 parent d39e298 commit 066c072

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/BulkWriteCommandBuilder.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@
1111
use function is_bool;
1212
use function is_string;
1313

14-
class BulkWriteCommandBuilder
14+
readonly class BulkWriteCommandBuilder
1515
{
16-
private BulkWriteCommand $bulkWriteCommand;
17-
1816
private function __construct(
17+
public BulkWriteCommand $bulkWriteCommand,
1918
private string $namespace,
2019
private Encoder $builderEncoder,
2120
private ?DocumentCodec $codec,
22-
array $options,
2321
) {
22+
}
23+
24+
public static function createWithCollection(Collection $collection, array $options): self
25+
{
2426
$options += ['ordered' => true];
2527

2628
if (isset($options['bypassDocumentValidation']) && ! is_bool($options['bypassDocumentValidation'])) {
@@ -39,26 +41,22 @@ private function __construct(
3941
throw InvalidArgumentException::invalidType('"verboseResults" option', $options['verboseResults'], 'boolean');
4042
}
4143

42-
$this->bulkWriteCommand = new BulkWriteCommand($options);
43-
}
44-
45-
public static function createWithCollection(Collection $collection, array $options): self
46-
{
4744
return new self(
45+
new BulkWriteCommand($options),
4846
$collection->getNamespace(),
4947
$collection->getBuilderEncoder(),
5048
$collection->getCodec(),
51-
$options,
5249
);
5350
}
5451

5552
public function withCollection(Collection $collection): self
5653
{
57-
$this->namespace = $collection->getNamespace();
58-
$this->builderEncoder = $collection->getBuilderEncoder();
59-
$this->codec = $collection->getCodec();
60-
61-
return $this;
54+
return new self(
55+
$this->bulkWriteCommand,
56+
$collection->getNamespace(),
57+
$collection->getBuilderEncoder(),
58+
$collection->getCodec(),
59+
);
6260
}
6361

6462
public function deleteOne(array|object $filter, ?array $options = null): self

0 commit comments

Comments
 (0)