We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 943a069 commit 422b030Copy full SHA for 422b030
src/Write/Result/InsertOneResult.php
@@ -15,15 +15,17 @@ class InsertOneResult
15
*/
16
public function getInsertedId()
17
{
18
- foreach ($this->writeResult->getInsertedIds() as $id) {
19
- return $id;
+ $insertedIds = $this->writeResult->getInsertedIds();
+
20
+ if (0 === count($insertedIds)) {
21
+ throw new UnexpectedResultException(
22
+ sprintf(
23
+ '%s::getInsertedIds() returned empty array, though there was an insert operation.',
24
+ WriteResult::class
25
+ )
26
+ );
27
}
28
- throw new UnexpectedResultException(
- sprintf(
- '%s::getInsertedIds() returned empty array, though there was an insert operation.',
- WriteResult::class
- )
- );
29
+ return reset($insertedIds);
30
-}
31
+}
0 commit comments