Skip to content

Commit bcae84c

Browse files
committed
PHPLIB-77: Use namespaced exceptions
1 parent 5b6f54e commit bcae84c

File tree

6 files changed

+31
-16
lines changed

6 files changed

+31
-16
lines changed

src/Client.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
use MongoDB\Driver\Manager;
88
use MongoDB\Driver\ReadPreference;
99
use MongoDB\Driver\WriteConcern;
10+
use MongoDB\Exception\UnexpectedValueException;
1011
use MongoDB\Model\DatabaseInfoIterator;
1112
use MongoDB\Model\DatabaseInfoLegacyIterator;
12-
use stdClass;
13-
use UnexpectedValueException;
1413

1514
class Client
1615
{

src/Collection.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function bulkWrite(array $bulk, array $options = array())
163163
foreach ($bulk as $n => $op) {
164164
foreach ($op as $opname => $args) {
165165
if (!isset($args[0])) {
166-
throw new \InvalidArgumentException(sprintf("Missing argument#1 for '%s' (operation#%d)", $opname, $n));
166+
throw new InvalidArgumentException(sprintf("Missing argument#1 for '%s' (operation#%d)", $opname, $n));
167167
}
168168

169169
switch ($opname) {
@@ -173,7 +173,7 @@ public function bulkWrite(array $bulk, array $options = array())
173173

174174
case "updateMany":
175175
if (!isset($args[1])) {
176-
throw new \InvalidArgumentException(sprintf("Missing argument#2 for '%s' (operation#%d)", $opname, $n));
176+
throw new InvalidArgumentException(sprintf("Missing argument#2 for '%s' (operation#%d)", $opname, $n));
177177
}
178178
$options = array_merge($this->getWriteOptions(), isset($args[2]) ? $args[2] : array(), array("limit" => 0));
179179

@@ -182,25 +182,25 @@ public function bulkWrite(array $bulk, array $options = array())
182182

183183
case "updateOne":
184184
if (!isset($args[1])) {
185-
throw new \InvalidArgumentException(sprintf("Missing argument#2 for '%s' (operation#%d)", $opname, $n));
185+
throw new InvalidArgumentException(sprintf("Missing argument#2 for '%s' (operation#%d)", $opname, $n));
186186
}
187187
$options = array_merge($this->getWriteOptions(), isset($args[2]) ? $args[2] : array(), array("limit" => 1));
188188
$firstKey = key($args[1]);
189189
if (!isset($firstKey[0]) || $firstKey[0] != '$') {
190-
throw new \InvalidArgumentException("First key in \$update must be a \$operator");
190+
throw new InvalidArgumentException("First key in \$update must be a \$operator");
191191
}
192192

193193
$bulk->update($args[0], $args[1], $options);
194194
break;
195195

196196
case "replaceOne":
197197
if (!isset($args[1])) {
198-
throw new \InvalidArgumentException(sprintf("Missing argument#2 for '%s' (operation#%d)", $opname, $n));
198+
throw new InvalidArgumentException(sprintf("Missing argument#2 for '%s' (operation#%d)", $opname, $n));
199199
}
200200
$options = array_merge($this->getWriteOptions(), isset($args[2]) ? $args[2] : array(), array("limit" => 1));
201201
$firstKey = key($args[1]);
202202
if (isset($firstKey[0]) && $firstKey[0] == '$') {
203-
throw new \InvalidArgumentException("First key in \$update must NOT be a \$operator");
203+
throw new InvalidArgumentException("First key in \$update must NOT be a \$operator");
204204
}
205205

206206
$bulk->update($args[0], $args[1], $options);
@@ -217,7 +217,7 @@ public function bulkWrite(array $bulk, array $options = array())
217217
break;
218218

219219
default:
220-
throw new \InvalidArgumentException(sprintf("Unknown operation type called '%s' (operation#%d)", $opname, $n));
220+
throw new InvalidArgumentException(sprintf("Unknown operation type called '%s' (operation#%d)", $opname, $n));
221221
}
222222
}
223223
}
@@ -521,7 +521,7 @@ public function findOneAndReplace(array $filter, array $replacement, array $opti
521521
{
522522
$firstKey = key($replacement);
523523
if (isset($firstKey[0]) && $firstKey[0] == '$') {
524-
throw new \InvalidArgumentException("First key in \$replacement must NOT be a \$operator");
524+
throw new InvalidArgumentException("First key in \$replacement must NOT be a \$operator");
525525
}
526526

527527
$options = array_merge($this->getFindOneAndReplaceOptions(), $options);
@@ -559,7 +559,7 @@ public function findOneAndUpdate(array $filter, array $update, array $options =
559559
{
560560
$firstKey = key($update);
561561
if (!isset($firstKey[0]) || $firstKey[0] != '$') {
562-
throw new \InvalidArgumentException("First key in \$update must be a \$operator");
562+
throw new InvalidArgumentException("First key in \$update must be a \$operator");
563563
}
564564

565565
$options = array_merge($this->getFindOneAndUpdateOptions(), $options);
@@ -1036,7 +1036,7 @@ public function replaceOne(array $filter, array $update, array $options = array(
10361036
{
10371037
$firstKey = key($update);
10381038
if (isset($firstKey[0]) && $firstKey[0] == '$') {
1039-
throw new \InvalidArgumentException("First key in \$update must NOT be a \$operator");
1039+
throw new InvalidArgumentException("First key in \$update must NOT be a \$operator");
10401040
}
10411041
$wr = $this->_update($filter, $update, $options);
10421042

@@ -1078,7 +1078,7 @@ public function updateOne(array $filter, array $update, array $options = array()
10781078
{
10791079
$firstKey = key($update);
10801080
if (!isset($firstKey[0]) || $firstKey[0] != '$') {
1081-
throw new \InvalidArgumentException("First key in \$update must be a \$operator");
1081+
throw new InvalidArgumentException("First key in \$update must be a \$operator");
10821082
}
10831083
$wr = $this->_update($filter, $update, $options);
10841084

@@ -1134,10 +1134,10 @@ final protected function _delete($filter, $limit = 1)
11341134
final protected function _generateCommandException($doc)
11351135
{
11361136
if ($doc["errmsg"]) {
1137-
return new Exception($doc["errmsg"]);
1137+
return new RuntimeException($doc["errmsg"]);
11381138
}
11391139
var_dump($doc);
1140-
return new \Exception("FIXME: Unknown error");
1140+
return new RuntimeException("FIXME: Unknown error");
11411141
}
11421142

11431143
/**

src/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
use MongoDB\Driver\ReadPreference;
1111
use MongoDB\Driver\Server;
1212
use MongoDB\Driver\WriteConcern;
13+
use MongoDB\Exception\InvalidArgumentException;
1314
use MongoDB\Model\CollectionInfoIterator;
1415
use MongoDB\Model\CollectionInfoCommandIterator;
1516
use MongoDB\Model\CollectionInfoLegacyIterator;
16-
use InvalidArgumentException;
1717

1818
class Database
1919
{

src/Exception/RuntimeException.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace MongoDB\Exception;
4+
5+
class RuntimeException extends \RuntimeException implements Exception
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace MongoDB\Exception;
4+
5+
class UnexpectedValueException extends \UnexpectedValueException implements Exception
6+
{
7+
}

src/Model/IndexInput.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace MongoDB\Model;
44

55
use BSON\Serializable;
6+
use MongoDB\Exception\InvalidArgumentException;
7+
use MongoDB\Exception\UnexpectedTypeException;
68

79
/**
810
* Index input model class.

0 commit comments

Comments
 (0)