17
17
18
18
namespace MongoDB ;
19
19
20
+ use MongoDB \Driver \Exception \LogicException ;
20
21
use MongoDB \Driver \WriteResult ;
21
- use MongoDB \Exception \BadMethodCallException ;
22
22
23
23
/**
24
24
* Result class for a bulk write operation.
25
25
*/
26
26
class BulkWriteResult
27
27
{
28
- private bool $ isAcknowledged ;
29
-
30
28
public function __construct (private WriteResult $ writeResult , private array $ insertedIds )
31
29
{
32
- $ this ->isAcknowledged = $ writeResult ->isAcknowledged ();
33
30
}
34
31
35
32
/**
@@ -38,15 +35,11 @@ public function __construct(private WriteResult $writeResult, private array $ins
38
35
* This method should only be called if the write was acknowledged.
39
36
*
40
37
* @see BulkWriteResult::isAcknowledged()
41
- * @throws BadMethodCallException if the write result is unacknowledged
38
+ * @throws LogicException if the write result is unacknowledged
42
39
*/
43
- public function getDeletedCount (): ? int
40
+ public function getDeletedCount (): int
44
41
{
45
- if ($ this ->isAcknowledged ) {
46
- return $ this ->writeResult ->getDeletedCount ();
47
- }
48
-
49
- throw BadMethodCallException::unacknowledgedWriteResultAccess (__METHOD__ );
42
+ return $ this ->writeResult ->getDeletedCount ();
50
43
}
51
44
52
45
/**
@@ -55,15 +48,11 @@ public function getDeletedCount(): ?int
55
48
* This method should only be called if the write was acknowledged.
56
49
*
57
50
* @see BulkWriteResult::isAcknowledged()
58
- * @throws BadMethodCallException if the write result is unacknowledged
51
+ * @throws LogicException if the write result is unacknowledged
59
52
*/
60
- public function getInsertedCount (): ? int
53
+ public function getInsertedCount (): int
61
54
{
62
- if ($ this ->isAcknowledged ) {
63
- return $ this ->writeResult ->getInsertedCount ();
64
- }
65
-
66
- throw BadMethodCallException::unacknowledgedWriteResultAccess (__METHOD__ );
55
+ return $ this ->writeResult ->getInsertedCount ();
67
56
}
68
57
69
58
/**
@@ -86,15 +75,11 @@ public function getInsertedIds(): array
86
75
* This method should only be called if the write was acknowledged.
87
76
*
88
77
* @see BulkWriteResult::isAcknowledged()
89
- * @throws BadMethodCallException if the write result is unacknowledged
78
+ * @throws LogicException if the write result is unacknowledged
90
79
*/
91
- public function getMatchedCount (): ? int
80
+ public function getMatchedCount (): int
92
81
{
93
- if ($ this ->isAcknowledged ) {
94
- return $ this ->writeResult ->getMatchedCount ();
95
- }
96
-
97
- throw BadMethodCallException::unacknowledgedWriteResultAccess (__METHOD__ );
82
+ return $ this ->writeResult ->getMatchedCount ();
98
83
}
99
84
100
85
/**
@@ -106,15 +91,11 @@ public function getMatchedCount(): ?int
106
91
* This method should only be called if the write was acknowledged.
107
92
*
108
93
* @see BulkWriteResult::isAcknowledged()
109
- * @throws BadMethodCallException if the write result is unacknowledged
94
+ * @throws LogicException if the write result is unacknowledged
110
95
*/
111
- public function getModifiedCount (): ? int
96
+ public function getModifiedCount (): int
112
97
{
113
- if ($ this ->isAcknowledged ) {
114
- return $ this ->writeResult ->getModifiedCount ();
115
- }
116
-
117
- throw BadMethodCallException::unacknowledgedWriteResultAccess (__METHOD__ );
98
+ return $ this ->writeResult ->getModifiedCount ();
118
99
}
119
100
120
101
/**
@@ -123,15 +104,11 @@ public function getModifiedCount(): ?int
123
104
* This method should only be called if the write was acknowledged.
124
105
*
125
106
* @see BulkWriteResult::isAcknowledged()
126
- * @throws BadMethodCallException if the write result is unacknowledged
107
+ * @throws LogicException if the write result is unacknowledged
127
108
*/
128
- public function getUpsertedCount (): ? int
109
+ public function getUpsertedCount (): int
129
110
{
130
- if ($ this ->isAcknowledged ) {
131
- return $ this ->writeResult ->getUpsertedCount ();
132
- }
133
-
134
- throw BadMethodCallException::unacknowledgedWriteResultAccess (__METHOD__ );
111
+ return $ this ->writeResult ->getUpsertedCount ();
135
112
}
136
113
137
114
/**
@@ -145,15 +122,11 @@ public function getUpsertedCount(): ?int
145
122
* This method should only be called if the write was acknowledged.
146
123
*
147
124
* @see BulkWriteResult::isAcknowledged()
148
- * @throws BadMethodCallException if the write result is unacknowledged
125
+ * @throws LogicException if the write result is unacknowledged
149
126
*/
150
127
public function getUpsertedIds (): array
151
128
{
152
- if ($ this ->isAcknowledged ) {
153
- return $ this ->writeResult ->getUpsertedIds ();
154
- }
155
-
156
- throw BadMethodCallException::unacknowledgedWriteResultAccess (__METHOD__ );
129
+ return $ this ->writeResult ->getUpsertedIds ();
157
130
}
158
131
159
132
/**
@@ -164,6 +137,6 @@ public function getUpsertedIds(): array
164
137
*/
165
138
public function isAcknowledged (): bool
166
139
{
167
- return $ this ->isAcknowledged ;
140
+ return $ this ->writeResult -> isAcknowledged () ;
168
141
}
169
142
}
0 commit comments