1717
1818namespace MongoDB ;
1919
20+ use MongoDB \Driver \Exception \LogicException ;
2021use MongoDB \Driver \WriteResult ;
21- use MongoDB \Exception \BadMethodCallException ;
2222
2323/**
2424 * Result class for a bulk write operation.
2525 */
2626class BulkWriteResult
2727{
28- private bool $ isAcknowledged ;
29-
3028 public function __construct (private WriteResult $ writeResult , private array $ insertedIds )
3129 {
32- $ this ->isAcknowledged = $ writeResult ->isAcknowledged ();
3330 }
3431
3532 /**
@@ -38,15 +35,11 @@ public function __construct(private WriteResult $writeResult, private array $ins
3835 * This method should only be called if the write was acknowledged.
3936 *
4037 * @see BulkWriteResult::isAcknowledged()
41- * @throws BadMethodCallException if the write result is unacknowledged
38+ * @throws LogicException if the write result is unacknowledged
4239 */
43- public function getDeletedCount (): ? int
40+ public function getDeletedCount (): int
4441 {
45- if ($ this ->isAcknowledged ) {
46- return $ this ->writeResult ->getDeletedCount ();
47- }
48-
49- throw BadMethodCallException::unacknowledgedWriteResultAccess (__METHOD__ );
42+ return $ this ->writeResult ->getDeletedCount ();
5043 }
5144
5245 /**
@@ -55,15 +48,11 @@ public function getDeletedCount(): ?int
5548 * This method should only be called if the write was acknowledged.
5649 *
5750 * @see BulkWriteResult::isAcknowledged()
58- * @throws BadMethodCallException if the write result is unacknowledged
51+ * @throws LogicException if the write result is unacknowledged
5952 */
60- public function getInsertedCount (): ? int
53+ public function getInsertedCount (): int
6154 {
62- if ($ this ->isAcknowledged ) {
63- return $ this ->writeResult ->getInsertedCount ();
64- }
65-
66- throw BadMethodCallException::unacknowledgedWriteResultAccess (__METHOD__ );
55+ return $ this ->writeResult ->getInsertedCount ();
6756 }
6857
6958 /**
@@ -86,15 +75,11 @@ public function getInsertedIds(): array
8675 * This method should only be called if the write was acknowledged.
8776 *
8877 * @see BulkWriteResult::isAcknowledged()
89- * @throws BadMethodCallException if the write result is unacknowledged
78+ * @throws LogicException if the write result is unacknowledged
9079 */
91- public function getMatchedCount (): ? int
80+ public function getMatchedCount (): int
9281 {
93- if ($ this ->isAcknowledged ) {
94- return $ this ->writeResult ->getMatchedCount ();
95- }
96-
97- throw BadMethodCallException::unacknowledgedWriteResultAccess (__METHOD__ );
82+ return $ this ->writeResult ->getMatchedCount ();
9883 }
9984
10085 /**
@@ -106,15 +91,11 @@ public function getMatchedCount(): ?int
10691 * This method should only be called if the write was acknowledged.
10792 *
10893 * @see BulkWriteResult::isAcknowledged()
109- * @throws BadMethodCallException if the write result is unacknowledged
94+ * @throws LogicException if the write result is unacknowledged
11095 */
111- public function getModifiedCount (): ? int
96+ public function getModifiedCount (): int
11297 {
113- if ($ this ->isAcknowledged ) {
114- return $ this ->writeResult ->getModifiedCount ();
115- }
116-
117- throw BadMethodCallException::unacknowledgedWriteResultAccess (__METHOD__ );
98+ return $ this ->writeResult ->getModifiedCount ();
11899 }
119100
120101 /**
@@ -123,15 +104,11 @@ public function getModifiedCount(): ?int
123104 * This method should only be called if the write was acknowledged.
124105 *
125106 * @see BulkWriteResult::isAcknowledged()
126- * @throws BadMethodCallException if the write result is unacknowledged
107+ * @throws LogicException if the write result is unacknowledged
127108 */
128- public function getUpsertedCount (): ? int
109+ public function getUpsertedCount (): int
129110 {
130- if ($ this ->isAcknowledged ) {
131- return $ this ->writeResult ->getUpsertedCount ();
132- }
133-
134- throw BadMethodCallException::unacknowledgedWriteResultAccess (__METHOD__ );
111+ return $ this ->writeResult ->getUpsertedCount ();
135112 }
136113
137114 /**
@@ -145,15 +122,11 @@ public function getUpsertedCount(): ?int
145122 * This method should only be called if the write was acknowledged.
146123 *
147124 * @see BulkWriteResult::isAcknowledged()
148- * @throws BadMethodCallException if the write result is unacknowledged
125+ * @throws LogicException if the write result is unacknowledged
149126 */
150127 public function getUpsertedIds (): array
151128 {
152- if ($ this ->isAcknowledged ) {
153- return $ this ->writeResult ->getUpsertedIds ();
154- }
155-
156- throw BadMethodCallException::unacknowledgedWriteResultAccess (__METHOD__ );
129+ return $ this ->writeResult ->getUpsertedIds ();
157130 }
158131
159132 /**
@@ -164,6 +137,6 @@ public function getUpsertedIds(): array
164137 */
165138 public function isAcknowledged (): bool
166139 {
167- return $ this ->isAcknowledged ;
140+ return $ this ->writeResult -> isAcknowledged () ;
168141 }
169142}
0 commit comments