Skip to content

Commit e81fce2

Browse files
committed
Re-order BulkWriteCommandBuilder methods to satisfy PedantryTest
1 parent dd60db1 commit e81fce2

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/BulkWriteCommandBuilder.php

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,7 @@ public static function createWithCollection(Collection $collection, array $optio
5252
);
5353
}
5454

55-
public function withCollection(Collection $collection): self
56-
{
57-
/* Prohibit mixing Collections associated with different Manager
58-
* objects. This is not technically necessary, since the Collection is
59-
* only used to derive a namespace and encoding options; however, it
60-
* may prevent a user from inadvertently mixing writes destined for
61-
* different deployments. */
62-
if ($this->manager !== $collection->getManager()) {
63-
throw new InvalidArgumentException('$collection is associated with a different MongoDB\Driver\Manager');
64-
}
65-
66-
return new self(
67-
$this->bulkWriteCommand,
68-
$this->manager,
69-
$collection->getNamespace(),
70-
$collection->getBuilderEncoder(),
71-
$collection->getCodec(),
72-
);
73-
}
74-
75-
public function deleteOne(array|object $filter, ?array $options = null): self
55+
public function deleteMany(array|object $filter, ?array $options = null): self
7656
{
7757
$filter = $this->builderEncoder->encodeIfSupported($filter);
7858

@@ -84,12 +64,12 @@ public function deleteOne(array|object $filter, ?array $options = null): self
8464
throw InvalidArgumentException::expectedDocumentOrStringType('"hint" option', $options['hint']);
8565
}
8666

87-
$this->bulkWriteCommand->deleteOne($this->namespace, $filter, $options);
67+
$this->bulkWriteCommand->deleteMany($this->namespace, $filter, $options);
8868

8969
return $this;
9070
}
9171

92-
public function deleteMany(array|object $filter, ?array $options = null): self
72+
public function deleteOne(array|object $filter, ?array $options = null): self
9373
{
9474
$filter = $this->builderEncoder->encodeIfSupported($filter);
9575

@@ -101,7 +81,7 @@ public function deleteMany(array|object $filter, ?array $options = null): self
10181
throw InvalidArgumentException::expectedDocumentOrStringType('"hint" option', $options['hint']);
10282
}
10383

104-
$this->bulkWriteCommand->deleteMany($this->namespace, $filter, $options);
84+
$this->bulkWriteCommand->deleteOne($this->namespace, $filter, $options);
10585

10686
return $this;
10787
}
@@ -160,7 +140,7 @@ public function replaceOne(array|object $filter, array|object $replacement, ?arr
160140
return $this;
161141
}
162142

163-
public function updateOne(array|object $filter, array|object $update, ?array $options = null): self
143+
public function updateMany(array|object $filter, array|object $update, ?array $options = null): self
164144
{
165145
$filter = $this->builderEncoder->encodeIfSupported($filter);
166146
$update = $this->builderEncoder->encodeIfSupported($update);
@@ -181,20 +161,16 @@ public function updateOne(array|object $filter, array|object $update, ?array $op
181161
throw InvalidArgumentException::expectedDocumentOrStringType('"hint" option', $options['hint']);
182162
}
183163

184-
if (isset($options['sort']) && ! is_document($options['sort'])) {
185-
throw InvalidArgumentException::expectedDocumentType('"sort" option', $options['sort']);
186-
}
187-
188164
if (isset($options['upsert']) && ! is_bool($options['upsert'])) {
189165
throw InvalidArgumentException::invalidType('"upsert" option', $options['upsert'], 'boolean');
190166
}
191167

192-
$this->bulkWriteCommand->updateOne($this->namespace, $filter, $update, $options);
168+
$this->bulkWriteCommand->updateMany($this->namespace, $filter, $update, $options);
193169

194170
return $this;
195171
}
196172

197-
public function updateMany(array|object $filter, array|object $update, ?array $options = null): self
173+
public function updateOne(array|object $filter, array|object $update, ?array $options = null): self
198174
{
199175
$filter = $this->builderEncoder->encodeIfSupported($filter);
200176
$update = $this->builderEncoder->encodeIfSupported($update);
@@ -215,12 +191,36 @@ public function updateMany(array|object $filter, array|object $update, ?array $o
215191
throw InvalidArgumentException::expectedDocumentOrStringType('"hint" option', $options['hint']);
216192
}
217193

194+
if (isset($options['sort']) && ! is_document($options['sort'])) {
195+
throw InvalidArgumentException::expectedDocumentType('"sort" option', $options['sort']);
196+
}
197+
218198
if (isset($options['upsert']) && ! is_bool($options['upsert'])) {
219199
throw InvalidArgumentException::invalidType('"upsert" option', $options['upsert'], 'boolean');
220200
}
221201

222-
$this->bulkWriteCommand->updateMany($this->namespace, $filter, $update, $options);
202+
$this->bulkWriteCommand->updateOne($this->namespace, $filter, $update, $options);
223203

224204
return $this;
225205
}
206+
207+
public function withCollection(Collection $collection): self
208+
{
209+
/* Prohibit mixing Collections associated with different Manager
210+
* objects. This is not technically necessary, since the Collection is
211+
* only used to derive a namespace and encoding options; however, it
212+
* may prevent a user from inadvertently mixing writes destined for
213+
* different deployments. */
214+
if ($this->manager !== $collection->getManager()) {
215+
throw new InvalidArgumentException('$collection is associated with a different MongoDB\Driver\Manager');
216+
}
217+
218+
return new self(
219+
$this->bulkWriteCommand,
220+
$this->manager,
221+
$collection->getNamespace(),
222+
$collection->getBuilderEncoder(),
223+
$collection->getCodec(),
224+
);
225+
}
226226
}

0 commit comments

Comments
 (0)