Skip to content

Commit 14667e3

Browse files
committed
Replace magic string with a private constant and comments
1 parent 53c481c commit 14667e3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Operation/DropCollection.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
class DropCollection implements Executable
1919
{
20+
private static $errorMessageNamespaceNotFound = 'ns not found';
2021
private $databaseName;
2122
private $collectionName;
2223

@@ -44,7 +45,11 @@ public function execute(Server $server)
4445
try {
4546
$cursor = $server->executeCommand($this->databaseName, new Command(array('drop' => $this->collectionName)));
4647
} catch (DriverRuntimeException $e) {
47-
if ($e->getMessage() === 'ns not found') {
48+
/* The server may return an error if the collection does not exist.
49+
* Check for an error message (unfortunately, there isn't a code)
50+
* and NOP instead of throwing.
51+
*/
52+
if ($e->getMessage() === self::$errorMessageNamespaceNotFound) {
4853
return (object) ['ok' => 0, 'errmsg' => 'ns not found'];
4954
}
5055

0 commit comments

Comments
 (0)