Commit 8f646a38 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-141: Replace InvalidArgumentTypeException with a factory method

parent 74af87db
......@@ -7,6 +7,7 @@ use MongoDB\Driver\Cursor;
use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\DatabaseInfoIterator;
use MongoDB\Operation\DropDatabase;
use MongoDB\Operation\ListDatabases;
......@@ -49,7 +50,7 @@ class Client
];
if (isset($driverOptions['typeMap']) && ! is_array($driverOptions['typeMap'])) {
throw new InvalidArgumentTypeException('"typeMap" driver option', $driverOptions['typeMap'], 'array');
throw InvalidArgumentException::invalidType('"typeMap" driver option', $driverOptions['typeMap'], 'array');
}
$this->manager = new Manager($uri, $uriOptions, $driverOptions);
......
......@@ -10,7 +10,6 @@ use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Model\IndexInfoIterator;
use MongoDB\Model\IndexInput;
use MongoDB\Operation\Aggregate;
......@@ -85,19 +84,19 @@ class Collection
$this->collectionName = $parts[1];
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
throw new InvalidArgumentTypeException('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
}
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
throw new InvalidArgumentTypeException('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
}
if (isset($options['typeMap']) && ! is_array($options['typeMap'])) {
throw new InvalidArgumentTypeException('"typeMap" option', $options['typeMap'], 'array');
throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
}
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
throw new InvalidArgumentTypeException('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
}
$this->manager = $manager;
......
......@@ -11,7 +11,6 @@ use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Model\CollectionInfoIterator;
use MongoDB\Operation\CreateCollection;
use MongoDB\Operation\DatabaseCommand;
......@@ -62,19 +61,19 @@ class Database
}
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
throw new InvalidArgumentTypeException('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
}
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
throw new InvalidArgumentTypeException('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
}
if (isset($options['typeMap']) && ! is_array($options['typeMap'])) {
throw new InvalidArgumentTypeException('"typeMap" option', $options['typeMap'], 'array');
throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
}
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
throw new InvalidArgumentTypeException('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
}
$this->manager = $manager;
......
......@@ -4,4 +4,16 @@ namespace MongoDB\Exception;
class InvalidArgumentException extends \MongoDB\Driver\Exception\InvalidArgumentException implements Exception
{
/**
* Thrown when an argument or option has an invalid type.
*
* @param string $name Name of the argument or option
* @param mixed $value Actual value (used to derive the type)
* @param string $expectedType Expected type
* @return self
*/
public static function invalidType($name, $value, $expectedType)
{
return new static(sprintf('Expected %s to have type "%s" but found "%s"', $name, $expectedType, is_object($value) ? get_class($value) : gettype($value)));
}
}
<?php
namespace MongoDB\Exception;
class InvalidArgumentTypeException extends InvalidArgumentException
{
public function __construct($name, $value, $expectedType)
{
parent::__construct(sprintf('Expected %s to have type "%s" but found "%s"', $name, $expectedType, is_object($value) ? get_class($value) : gettype($value)));
}
}
......@@ -4,7 +4,6 @@ namespace MongoDB\Model;
use MongoDB\BSON\Serializable;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Index input model class.
......@@ -24,6 +23,7 @@ class IndexInput implements Serializable
* Constructor.
*
* @param array $index Index specification
* @throws InvalidArgumentException
*/
public function __construct(array $index)
{
......@@ -32,12 +32,12 @@ class IndexInput implements Serializable
}
if ( ! is_array($index['key']) && ! is_object($index['key'])) {
throw new InvalidArgumentTypeException('"key" option', $index['key'], 'array or object');
throw InvalidArgumentException::invalidType('"key" option', $index['key'], 'array or object');
}
foreach ($index['key'] as $fieldName => $order) {
if ( ! is_int($order) && ! is_float($order) && ! is_string($order)) {
throw new InvalidArgumentTypeException(sprintf('order value for "%s" field within "key" option', $fieldName), $order, 'numeric or string');
throw InvalidArgumentException::invalidType(sprintf('order value for "%s" field within "key" option', $fieldName), $order, 'numeric or string');
}
}
......@@ -46,7 +46,7 @@ class IndexInput implements Serializable
}
if ( ! is_string($index['ns'])) {
throw new InvalidArgumentTypeException('"ns" option', $index['ns'], 'string');
throw InvalidArgumentException::invalidType('"ns" option', $index['ns'], 'string');
}
if ( ! isset($index['name'])) {
......@@ -54,7 +54,7 @@ class IndexInput implements Serializable
}
if ( ! is_string($index['name'])) {
throw new InvalidArgumentTypeException('"name" option', $index['name'], 'string');
throw InvalidArgumentException::invalidType('"name" option', $index['name'], 'string');
}
$this->index = $index;
......
......@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Exception\UnexpectedValueException;
use ArrayIterator;
use stdClass;
......@@ -95,7 +94,7 @@ class Aggregate implements Executable
}
if ( ! is_array($operation) && ! is_object($operation)) {
throw new InvalidArgumentTypeException(sprintf('$pipeline[%d]', $i), $operation, 'array or object');
throw InvalidArgumentException::invalidType(sprintf('$pipeline[%d]', $i), $operation, 'array or object');
}
$expectedIndex += 1;
......@@ -107,35 +106,35 @@ class Aggregate implements Executable
];
if ( ! is_bool($options['allowDiskUse'])) {
throw new InvalidArgumentTypeException('"allowDiskUse" option', $options['allowDiskUse'], 'boolean');
throw InvalidArgumentException::invalidType('"allowDiskUse" option', $options['allowDiskUse'], 'boolean');
}
if (isset($options['batchSize']) && ! is_integer($options['batchSize'])) {
throw new InvalidArgumentTypeException('"batchSize" option', $options['batchSize'], 'integer');
throw InvalidArgumentException::invalidType('"batchSize" option', $options['batchSize'], 'integer');
}
if (isset($options['bypassDocumentValidation']) && ! is_bool($options['bypassDocumentValidation'])) {
throw new InvalidArgumentTypeException('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
}
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw new InvalidArgumentTypeException('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
}
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
throw new InvalidArgumentTypeException('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
}
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
throw new InvalidArgumentTypeException('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
}
if (isset($options['typeMap']) && ! is_array($options['typeMap'])) {
throw new InvalidArgumentTypeException('"typeMap" option', $options['typeMap'], 'array');
throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
}
if ( ! is_bool($options['useCursor'])) {
throw new InvalidArgumentTypeException('"useCursor" option', $options['useCursor'], 'boolean');
throw InvalidArgumentException::invalidType('"useCursor" option', $options['useCursor'], 'boolean');
}
if (isset($options['batchSize']) && ! $options['useCursor']) {
......
......@@ -7,7 +7,6 @@ use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Operation for executing multiple write operations.
......@@ -85,7 +84,7 @@ class BulkWrite implements Executable
}
if ( ! is_array($operation)) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]', $i), $operation, 'array');
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]', $i), $operation, 'array');
}
if (count($operation) !== 1) {
......@@ -100,7 +99,7 @@ class BulkWrite implements Executable
}
if ( ! is_array($args[0]) && ! is_object($args[0])) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]["%s"][0]', $i, $type), $args[0], 'array or object');
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][0]', $i, $type), $args[0], 'array or object');
}
switch ($type) {
......@@ -119,7 +118,7 @@ class BulkWrite implements Executable
}
if ( ! is_array($args[1]) && ! is_object($args[1])) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]["%s"][1]', $i, $type), $args[1], 'array or object');
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][1]', $i, $type), $args[1], 'array or object');
}
if (\MongoDB\is_first_key_operator($args[1])) {
......@@ -131,14 +130,14 @@ class BulkWrite implements Executable
}
if ( ! is_array($args[2])) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]["%s"][2]', $i, $type), $args[2], 'array');
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]', $i, $type), $args[2], 'array');
}
$args[2]['multi'] = false;
$args[2] += ['upsert' => false];
if ( ! is_bool($args[2]['upsert'])) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean');
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean');
}
$operations[$i][$type][2] = $args[2];
......@@ -152,7 +151,7 @@ class BulkWrite implements Executable
}
if ( ! is_array($args[1]) && ! is_object($args[1])) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]["%s"][1]', $i, $type), $args[1], 'array or object');
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][1]', $i, $type), $args[1], 'array or object');
}
if ( ! \MongoDB\is_first_key_operator($args[1])) {
......@@ -164,14 +163,14 @@ class BulkWrite implements Executable
}
if ( ! is_array($args[2])) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]["%s"][2]', $i, $type), $args[2], 'array');
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]', $i, $type), $args[2], 'array');
}
$args[2]['multi'] = ($type === self::UPDATE_MANY);
$args[2] += ['upsert' => false];
if ( ! is_bool($args[2]['upsert'])) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean');
throw InvalidArgumentException::invalidType(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean');
}
$operations[$i][$type][2] = $args[2];
......@@ -188,15 +187,15 @@ class BulkWrite implements Executable
$options += ['ordered' => true];
if (isset($options['bypassDocumentValidation']) && ! is_bool($options['bypassDocumentValidation'])) {
throw new InvalidArgumentTypeException('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
}
if ( ! is_bool($options['ordered'])) {
throw new InvalidArgumentTypeException('"ordered" option', $options['ordered'], 'boolean');
throw InvalidArgumentException::invalidType('"ordered" option', $options['ordered'], 'boolean');
}
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
throw new InvalidArgumentTypeException('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
}
$this->databaseName = (string) $databaseName;
......
......@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Exception\UnexpectedValueException;
/**
......@@ -58,7 +57,7 @@ class Count implements Executable
public function __construct($databaseName, $collectionName, $filter = [], array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
}
if (isset($options['hint'])) {
......@@ -67,28 +66,28 @@ class Count implements Executable
}
if ( ! is_string($options['hint'])) {
throw new InvalidArgumentTypeException('"hint" option', $options['hint'], 'string or array or object');
throw InvalidArgumentException::invalidType('"hint" option', $options['hint'], 'string or array or object');
}
}
if (isset($options['limit']) && ! is_integer($options['limit'])) {
throw new InvalidArgumentTypeException('"limit" option', $options['limit'], 'integer');
throw InvalidArgumentException::invalidType('"limit" option', $options['limit'], 'integer');
}
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw new InvalidArgumentTypeException('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
}
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
throw new InvalidArgumentTypeException('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
}
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
throw new InvalidArgumentTypeException('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
}
if (isset($options['skip']) && ! is_integer($options['skip'])) {
throw new InvalidArgumentTypeException('"skip" option', $options['skip'], 'integer');
throw InvalidArgumentException::invalidType('"skip" option', $options['skip'], 'integer');
}
$this->databaseName = (string) $databaseName;
......
......@@ -5,7 +5,6 @@ namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Operation for the create command.
......@@ -68,47 +67,47 @@ class CreateCollection implements Executable
public function __construct($databaseName, $collectionName, array $options = [])
{
if (isset($options['autoIndexId']) && ! is_bool($options['autoIndexId'])) {
throw new InvalidArgumentTypeException('"autoIndexId" option', $options['autoIndexId'], 'boolean');
throw InvalidArgumentException::invalidType('"autoIndexId" option', $options['autoIndexId'], 'boolean');
}
if (isset($options['capped']) && ! is_bool($options['capped'])) {
throw new InvalidArgumentTypeException('"capped" option', $options['capped'], 'boolean');
throw InvalidArgumentException::invalidType('"capped" option', $options['capped'], 'boolean');
}
if (isset($options['flags']) && ! is_integer($options['flags'])) {
throw new InvalidArgumentTypeException('"flags" option', $options['flags'], 'integer');
throw InvalidArgumentException::invalidType('"flags" option', $options['flags'], 'integer');
}
if (isset($options['indexOptionDefaults']) && ! is_array($options['indexOptionDefaults']) && ! is_object($options['indexOptionDefaults'])) {
throw new InvalidArgumentTypeException('"indexOptionDefaults" option', $options['indexOptionDefaults'], 'array or object');
throw InvalidArgumentException::invalidType('"indexOptionDefaults" option', $options['indexOptionDefaults'], 'array or object');
}
if (isset($options['max']) && ! is_integer($options['max'])) {
throw new InvalidArgumentTypeException('"max" option', $options['max'], 'integer');
throw InvalidArgumentException::invalidType('"max" option', $options['max'], 'integer');
}
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw new InvalidArgumentTypeException('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
}
if (isset($options['size']) && ! is_integer($options['size'])) {
throw new InvalidArgumentTypeException('"size" option', $options['size'], 'integer');
throw InvalidArgumentException::invalidType('"size" option', $options['size'], 'integer');
}
if (isset($options['storageEngine']) && ! is_array($options['storageEngine']) && ! is_object($options['storageEngine'])) {
throw new InvalidArgumentTypeException('"storageEngine" option', $options['storageEngine'], 'array or object');
throw InvalidArgumentException::invalidType('"storageEngine" option', $options['storageEngine'], 'array or object');
}
if (isset($options['validationAction']) && ! is_string($options['validationAction'])) {
throw new InvalidArgumentTypeException('"validationAction" option', $options['validationAction'], 'string');
throw InvalidArgumentException::invalidType('"validationAction" option', $options['validationAction'], 'string');
}
if (isset($options['validationLevel']) && ! is_string($options['validationLevel'])) {
throw new InvalidArgumentTypeException('"validationLevel" option', $options['validationLevel'], 'string');
throw InvalidArgumentException::invalidType('"validationLevel" option', $options['validationLevel'], 'string');
}
if (isset($options['validator']) && ! is_array($options['validator']) && ! is_object($options['validator'])) {
throw new InvalidArgumentTypeException('"validator" option', $options['validator'], 'array or object');
throw InvalidArgumentException::invalidType('"validator" option', $options['validator'], 'array or object');
}
$this->databaseName = (string) $databaseName;
......
......@@ -7,7 +7,6 @@ use MongoDB\Driver\Server;
use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Model\IndexInput;
/**
......@@ -48,7 +47,7 @@ class CreateIndexes implements Executable
}
if ( ! is_array($index)) {
throw new InvalidArgumentTypeException(sprintf('$index[%d]', $i), $index, 'array');
throw InvalidArgumentException::invalidType(sprintf('$index[%d]', $i), $index, 'array');
}
if ( ! isset($index['ns'])) {
......
......@@ -6,7 +6,6 @@ use MongoDB\Driver\Command;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Operation for executing a database command.
......@@ -42,15 +41,15 @@ class DatabaseCommand implements Executable
public function __construct($databaseName, $command, array $options = [])
{
if ( ! is_array($command) && ! is_object($command)) {
throw new InvalidArgumentTypeException('$command', $command, 'array or object');
throw InvalidArgumentException::invalidType('$command', $command, 'array or object');
}
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
throw new InvalidArgumentTypeException('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
}
if (isset($options['typeMap']) && ! is_array($options['typeMap'])) {
throw new InvalidArgumentTypeException('"typeMap" option', $options['typeMap'], 'array');
throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
}
$this->databaseName = (string) $databaseName;
......
......@@ -7,7 +7,6 @@ use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Operation for the delete command.
......@@ -45,7 +44,7 @@ class Delete implements Executable
public function __construct($databaseName, $collectionName, $filter, $limit, array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
}
if ($limit !== 0 && $limit !== 1) {
......@@ -53,7 +52,7 @@ class Delete implements Executable
}
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
throw new InvalidArgumentTypeException('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
}
$this->databaseName = (string) $databaseName;
......
......@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Exception\UnexpectedValueException;
/**
......@@ -52,19 +51,19 @@ class Distinct implements Executable
public function __construct($databaseName, $collectionName, $fieldName, $filter = [], array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
}
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw new InvalidArgumentTypeException('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
}
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
throw new InvalidArgumentTypeException('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
}
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
throw new InvalidArgumentTypeException('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
}
$this->databaseName = (string) $databaseName;
......
......@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Exception\RuntimeException;
use MongoDB\Exception\UnexpectedValueException;
......@@ -91,24 +90,24 @@ class Find implements Executable
public function __construct($databaseName, $collectionName, $filter, array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
}
if (isset($options['allowPartialResults']) && ! is_bool($options['allowPartialResults'])) {
throw new InvalidArgumentTypeException('"allowPartialResults" option', $options['allowPartialResults'], 'boolean');
throw InvalidArgumentException::invalidType('"allowPartialResults" option', $options['allowPartialResults'], 'boolean');
}
if (isset($options['batchSize']) && ! is_integer($options['batchSize'])) {
throw new InvalidArgumentTypeException('"batchSize" option', $options['batchSize'], 'integer');
throw InvalidArgumentException::invalidType('"batchSize" option', $options['batchSize'], 'integer');
}
if (isset($options['comment']) && ! is_string($options['comment'])) {
throw new InvalidArgumentTypeException('"comment" option', $options['comment'], 'comment');
throw InvalidArgumentException::invalidType('"comment" option', $options['comment'], 'comment');
}
if (isset($options['cursorType'])) {
if ( ! is_integer($options['cursorType'])) {
throw new InvalidArgumentTypeException('"cursorType" option', $options['cursorType'], 'integer');
throw InvalidArgumentException::invalidType('"cursorType" option', $options['cursorType'], 'integer');
}
if ($options['cursorType'] !== self::NON_TAILABLE &&
......@@ -119,47 +118,47 @@ class Find implements Executable
}
if (isset($options['limit']) && ! is_integer($options['limit'])) {
throw new InvalidArgumentTypeException('"limit" option', $options['limit'], 'integer');
throw InvalidArgumentException::invalidType('"limit" option', $options['limit'], 'integer');
}
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw new InvalidArgumentTypeException('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
}
if (isset($options['modifiers']) && ! is_array($options['modifiers']) && ! is_object($options['modifiers'])) {
throw new InvalidArgumentTypeException('"modifiers" option', $options['modifiers'], 'array or object');
throw InvalidArgumentException::invalidType('"modifiers" option', $options['modifiers'], 'array or object');
}
if (isset($options['noCursorTimeout']) && ! is_bool($options['noCursorTimeout'])) {
throw new InvalidArgumentTypeException('"noCursorTimeout" option', $options['noCursorTimeout'], 'boolean');
throw InvalidArgumentException::invalidType('"noCursorTimeout" option', $options['noCursorTimeout'], 'boolean');
}
if (isset($options['oplogReplay']) && ! is_bool($options['oplogReplay'])) {
throw new InvalidArgumentTypeException('"oplogReplay" option', $options['oplogReplay'], 'boolean');
throw InvalidArgumentException::invalidType('"oplogReplay" option', $options['oplogReplay'], 'boolean');
}
if (isset($options['projection']) && ! is_array($options['projection']) && ! is_object($options['projection'])) {
throw new InvalidArgumentTypeException('"projection" option', $options['projection'], 'array or object');
throw InvalidArgumentException::invalidType('"projection" option', $options['projection'], 'array or object');
}
if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
throw new InvalidArgumentTypeException('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
}
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
throw new InvalidArgumentTypeException('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
}
if (isset($options['skip']) && ! is_integer($options['skip'])) {
throw new InvalidArgumentTypeException('"skip" option', $options['skip'], 'integer');
throw InvalidArgumentException::invalidType('"skip" option', $options['skip'], 'integer');
}
if (isset($options['sort']) && ! is_array($options['sort']) && ! is_object($options['sort'])) {
throw new InvalidArgumentTypeException('"sort" option', $options['sort'], 'array or object');
throw InvalidArgumentException::invalidType('"sort" option', $options['sort'], 'array or object');
}
if (isset($options['typeMap']) && ! is_array($options['typeMap'])) {
throw new InvalidArgumentTypeException('"typeMap" option', $options['typeMap'], 'array');
throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
}
$this->databaseName = (string) $databaseName;
......
......@@ -6,7 +6,6 @@ use MongoDB\Driver\Command;
use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Exception\UnexpectedValueException;
/**
......@@ -77,43 +76,43 @@ class FindAndModify implements Executable
];
if (isset($options['bypassDocumentValidation']) && ! is_bool($options['bypassDocumentValidation'])) {
throw new InvalidArgumentTypeException('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
}
if (isset($options['fields']) && ! is_array($options['fields']) && ! is_object($options['fields'])) {
throw new InvalidArgumentTypeException('"fields" option', $options['fields'], 'array or object');
throw InvalidArgumentException::invalidType('"fields" option', $options['fields'], 'array or object');
}
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw new InvalidArgumentTypeException('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
}
if ( ! is_bool($options['new'])) {
throw new InvalidArgumentTypeException('"new" option', $options['new'], 'boolean');
throw InvalidArgumentException::invalidType('"new" option', $options['new'], 'boolean');
}
if (isset($options['query']) && ! is_array($options['query']) && ! is_object($options['query'])) {
throw new InvalidArgumentTypeException('"query" option', $options['query'], 'array or object');
throw InvalidArgumentException::invalidType('"query" option', $options['query'], 'array or object');
}
if ( ! is_bool($options['remove'])) {
throw new InvalidArgumentTypeException('"remove" option', $options['remove'], 'boolean');
throw InvalidArgumentException::invalidType('"remove" option', $options['remove'], 'boolean');
}
if (isset($options['sort']) && ! is_array($options['sort']) && ! is_object($options['sort'])) {
throw new InvalidArgumentTypeException('"sort" option', $options['sort'], 'array or object');
throw InvalidArgumentException::invalidType('"sort" option', $options['sort'], 'array or object');
}
if (isset($options['update']) && ! is_array($options['update']) && ! is_object($options['update'])) {
throw new InvalidArgumentTypeException('"update" option', $options['update'], 'array or object');
throw InvalidArgumentException::invalidType('"update" option', $options['update'], 'array or object');
}
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
throw new InvalidArgumentTypeException('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
}
if ( ! is_bool($options['upsert'])) {
throw new InvalidArgumentTypeException('"upsert" option', $options['upsert'], 'boolean');
throw InvalidArgumentException::invalidType('"upsert" option', $options['upsert'], 'boolean');
}
if ( ! (isset($options['update']) xor $options['remove'])) {
......
......@@ -3,7 +3,7 @@
namespace MongoDB\Operation;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Exception\InvalidArgumentException;
/**
* Operation for finding a single document with the find command.
......
......@@ -5,7 +5,6 @@ namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Operation for deleting a document with the findAndModify command.
......@@ -44,11 +43,11 @@ class FindOneAndDelete implements Executable
public function __construct($databaseName, $collectionName, $filter, array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
}
if (isset($options['projection']) && ! is_array($options['projection']) && ! is_object($options['projection'])) {
throw new InvalidArgumentTypeException('"projection" option', $options['projection'], 'array or object');
throw InvalidArgumentException::invalidType('"projection" option', $options['projection'], 'array or object');
}
if (isset($options['projection'])) {
......
......@@ -5,7 +5,6 @@ namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Operation for replacing a document with the findAndModify command.
......@@ -58,11 +57,11 @@ class FindOneAndReplace implements Executable
public function __construct($databaseName, $collectionName, $filter, $replacement, array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
}
if ( ! is_array($replacement) && ! is_object($replacement)) {
throw new InvalidArgumentTypeException('$replacement', $replacement, 'array or object');
throw InvalidArgumentException::invalidType('$replacement', $replacement, 'array or object');
}
if (\MongoDB\is_first_key_operator($replacement)) {
......@@ -75,11 +74,11 @@ class FindOneAndReplace implements Executable
];
if (isset($options['projection']) && ! is_array($options['projection']) && ! is_object($options['projection'])) {
throw new InvalidArgumentTypeException('"projection" option', $options['projection'], 'array or object');
throw InvalidArgumentException::invalidType('"projection" option', $options['projection'], 'array or object');
}
if ( ! is_integer($options['returnDocument'])) {
throw new InvalidArgumentTypeException('"returnDocument" option', $options['returnDocument'], 'integer');
throw InvalidArgumentException::invalidType('"returnDocument" option', $options['returnDocument'], 'integer');
}
if ($options['returnDocument'] !== self::RETURN_DOCUMENT_AFTER &&
......
......@@ -5,7 +5,6 @@ namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Operation for updating a document with the findAndModify command.
......@@ -58,11 +57,11 @@ class FindOneAndUpdate implements Executable
public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
}
if ( ! is_array($update) && ! is_object($update)) {
throw new InvalidArgumentTypeException('$update', $update, 'array or object');
throw InvalidArgumentException::invalidType('$update', $update, 'array or object');
}
if ( ! \MongoDB\is_first_key_operator($update)) {
......@@ -75,11 +74,11 @@ class FindOneAndUpdate implements Executable
];
if (isset($options['projection']) && ! is_array($options['projection']) && ! is_object($options['projection'])) {
throw new InvalidArgumentTypeException('"projection" option', $options['projection'], 'array or object');
throw InvalidArgumentException::invalidType('"projection" option', $options['projection'], 'array or object');
}
if ( ! is_integer($options['returnDocument'])) {
throw new InvalidArgumentTypeException('"returnDocument" option', $options['returnDocument'], 'integer');
throw InvalidArgumentException::invalidType('"returnDocument" option', $options['returnDocument'], 'integer');
}
if ($options['returnDocument'] !== self::RETURN_DOCUMENT_AFTER &&
......
......@@ -7,7 +7,6 @@ use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Operation for inserting multiple documents with the insert command.
......@@ -59,7 +58,7 @@ class InsertMany implements Executable
}
if ( ! is_array($document) && ! is_object($document)) {
throw new InvalidArgumentTypeException(sprintf('$documents[%d]', $i), $document, 'array or object');
throw InvalidArgumentException::invalidType(sprintf('$documents[%d]', $i), $document, 'array or object');
}
$expectedIndex += 1;
......@@ -68,15 +67,15 @@ class InsertMany implements Executable
$options += ['ordered' => true];
if (isset($options['bypassDocumentValidation']) && ! is_bool($options['bypassDocumentValidation'])) {
throw new InvalidArgumentTypeException('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
}
if ( ! is_bool($options['ordered'])) {
throw new InvalidArgumentTypeException('"ordered" option', $options['ordered'], 'boolean');
throw InvalidArgumentException::invalidType('"ordered" option', $options['ordered'], 'boolean');
}
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
throw new InvalidArgumentTypeException('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
}
$this->databaseName = (string) $databaseName;
......
......@@ -6,7 +6,7 @@ use MongoDB\InsertOneResult;
use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Exception\InvalidArgumentException;
/**
* Operation for inserting a single document with the insert command.
......@@ -43,15 +43,15 @@ class InsertOne implements Executable
public function __construct($databaseName, $collectionName, $document, array $options = [])
{
if ( ! is_array($document) && ! is_object($document)) {
throw new InvalidArgumentTypeException('$document', $document, 'array or object');
throw InvalidArgumentException::invalidType('$document', $document, 'array or object');
}
if (isset($options['bypassDocumentValidation']) && ! is_bool($options['bypassDocumentValidation'])) {
throw new InvalidArgumentTypeException('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
}
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
throw new InvalidArgumentTypeException('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
}
$this->databaseName = (string) $databaseName;
......
......@@ -6,6 +6,7 @@ use MongoDB\Driver\Command;
use MongoDB\Driver\Query;
use MongoDB\Driver\Server;
use MongoDB\Exception\RuntimeException;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\CollectionInfoCommandIterator;
use MongoDB\Model\CollectionInfoIterator;
use MongoDB\Model\CollectionInfoLegacyIterator;
......@@ -36,15 +37,16 @@ class ListCollections implements Executable
*
* @param string $databaseName Database name
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, array $options = [])
{
if (isset($options['filter']) && ! is_array($options['filter']) && ! is_object($options['filter'])) {
throw new InvalidArgumentTypeException('"filter" option', $options['filter'], 'array or object');
throw InvalidArgumentException::invalidType('"filter" option', $options['filter'], 'array or object');
}
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw new InvalidArgumentTypeException('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
}
$this->databaseName = (string) $databaseName;
......@@ -104,7 +106,7 @@ class ListCollections implements Executable
if (array_key_exists('name', $filter)) {
if ( ! is_string($filter['name'])) {
throw new InvalidArgumentTypeException('filter name for MongoDB <3.0', $filter['name'], 'string');
throw InvalidArgumentException::invalidType('filter name for MongoDB <3.0', $filter['name'], 'string');
}
$filter['name'] = $this->databaseName . '.' . $filter['name'];
......
......@@ -4,6 +4,7 @@ namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Model\DatabaseInfoIterator;
use MongoDB\Model\DatabaseInfoLegacyIterator;
......@@ -28,11 +29,12 @@ class ListDatabases implements Executable
* run.
*
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct(array $options = [])
{
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw new InvalidArgumentTypeException('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
}
$this->options = $options;
......
......@@ -6,6 +6,7 @@ use MongoDB\Driver\Command;
use MongoDB\Driver\Query;
use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\RuntimeException;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\IndexInfoIterator;
use MongoDB\Model\IndexInfoIteratorIterator;
use EmptyIterator;
......@@ -38,11 +39,12 @@ class ListIndexes implements Executable
* @param string $databaseName Database name
* @param string $collectionName Collection name
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, array $options = [])
{
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw new InvalidArgumentTypeException('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
}
$this->databaseName = (string) $databaseName;
......
......@@ -5,7 +5,6 @@ namespace MongoDB\Operation;
use MongoDB\UpdateResult;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Operation for replacing a single document with the update command.
......@@ -41,7 +40,7 @@ class ReplaceOne implements Executable
public function __construct($databaseName, $collectionName, $filter, $replacement, array $options = [])
{
if ( ! is_array($replacement) && ! is_object($replacement)) {
throw new InvalidArgumentTypeException('$replacement', $replacement, 'array or object');
throw InvalidArgumentException::invalidType('$replacement', $replacement, 'array or object');
}
if (\MongoDB\is_first_key_operator($replacement)) {
......
......@@ -7,7 +7,6 @@ use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Operation for the update command.
......@@ -56,11 +55,11 @@ class Update implements Executable
public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
}
if ( ! is_array($update) && ! is_object($update)) {
throw new InvalidArgumentTypeException('$update', $filter, 'array or object');
throw InvalidArgumentException::invalidType('$update', $filter, 'array or object');
}
$options += [
......@@ -69,11 +68,11 @@ class Update implements Executable
];
if (isset($options['bypassDocumentValidation']) && ! is_bool($options['bypassDocumentValidation'])) {
throw new InvalidArgumentTypeException('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
}
if ( ! is_bool($options['multi'])) {
throw new InvalidArgumentTypeException('"multi" option', $options['multi'], 'boolean');
throw InvalidArgumentException::invalidType('"multi" option', $options['multi'], 'boolean');
}
if ($options['multi'] && ! \MongoDB\is_first_key_operator($update)) {
......@@ -81,11 +80,11 @@ class Update implements Executable
}
if ( ! is_bool($options['upsert'])) {
throw new InvalidArgumentTypeException('"upsert" option', $options['upsert'], 'boolean');
throw InvalidArgumentException::invalidType('"upsert" option', $options['upsert'], 'boolean');
}
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
throw new InvalidArgumentTypeException('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
}
$this->databaseName = (string) $databaseName;
......
......@@ -5,7 +5,6 @@ namespace MongoDB\Operation;
use MongoDB\UpdateResult;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Operation for updating multiple documents with the update command.
......@@ -41,7 +40,7 @@ class UpdateMany implements Executable
public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
{
if ( ! is_array($update) && ! is_object($update)) {
throw new InvalidArgumentTypeException('$update', $update, 'array or object');
throw InvalidArgumentException::invalidType('$update', $update, 'array or object');
}
if ( ! \MongoDB\is_first_key_operator($update)) {
......
......@@ -5,7 +5,6 @@ namespace MongoDB\Operation;
use MongoDB\UpdateResult;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Operation for updating a single document with the update command.
......@@ -41,7 +40,7 @@ class UpdateOne implements Executable
public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
{
if ( ! is_array($update) && ! is_object($update)) {
throw new InvalidArgumentTypeException('$update', $update, 'array or object');
throw InvalidArgumentException::invalidType('$update', $update, 'array or object');
}
if ( ! \MongoDB\is_first_key_operator($update)) {
......
......@@ -5,7 +5,7 @@ namespace MongoDB;
use MongoDB\BSON\Serializable;
use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Exception\InvalidArgumentException;
use stdClass;
/**
......@@ -36,7 +36,7 @@ function extract_id_from_inserted_document($document)
* @param array|object $document Document containing fields mapped to values,
* which denote order or an index type
* @return string
* @throws InvalidArgumentTypeException
* @throws InvalidArgumentException
*/
function generate_index_name($document)
{
......@@ -45,7 +45,7 @@ function generate_index_name($document)
}
if ( ! is_array($document)) {
throw new InvalidArgumentTypeException('$document', $document, 'array or object');
throw InvalidArgumentException::invalidType('$document', $document, 'array or object');
}
$name = '';
......@@ -65,7 +65,7 @@ function generate_index_name($document)
* @internal
* @param array|object $document Update or replacement document
* @return boolean
* @throws InvalidArgumentTypeException
* @throws InvalidArgumentException
*/
function is_first_key_operator($document)
{
......@@ -74,7 +74,7 @@ function is_first_key_operator($document)
}
if ( ! is_array($document)) {
throw new InvalidArgumentTypeException('$document', $document, 'array or object');
throw InvalidArgumentException::invalidType('$document', $document, 'array or object');
}
$firstKey = (string) key($document);
......
......@@ -35,7 +35,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -32,7 +32,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......@@ -102,7 +102,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testCommandCommandArgumentTypeCheck($command)
......
......@@ -17,7 +17,7 @@ class IndexInputTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public function testConstructorShouldRequireKeyToBeArrayOrObject()
{
......@@ -25,7 +25,7 @@ class IndexInputTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidFieldOrderValues
*/
public function testConstructorShouldRequireKeyFieldOrderToBeNumericOrString($order)
......@@ -47,7 +47,7 @@ class IndexInputTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public function testConstructorShouldRequireNamespaceToBeString()
{
......@@ -55,7 +55,7 @@ class IndexInputTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public function testConstructorShouldRequireNameToBeString()
{
......
......@@ -25,7 +25,7 @@ class AggregateTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -63,7 +63,7 @@ class BulkWriteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["insertOne"\]\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
......@@ -86,7 +86,7 @@ class BulkWriteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["deleteMany"\]\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
......@@ -109,7 +109,7 @@ class BulkWriteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["deleteOne"\]\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
......@@ -132,7 +132,7 @@ class BulkWriteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
......@@ -155,7 +155,7 @@ class BulkWriteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[1\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
......@@ -178,7 +178,7 @@ class BulkWriteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[2\]\["upsert"\] to have type "boolean" but found "[\w ]+"/
* @dataProvider provideInvalidBooleanValues
*/
......@@ -201,7 +201,7 @@ class BulkWriteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
......@@ -224,7 +224,7 @@ class BulkWriteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[1\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
......@@ -247,7 +247,7 @@ class BulkWriteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[2\]\["upsert"\] to have type "boolean" but found "[\w ]+"/
* @dataProvider provideInvalidBooleanValues
*/
......@@ -270,7 +270,7 @@ class BulkWriteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
......@@ -293,7 +293,7 @@ class BulkWriteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[1\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
......@@ -316,7 +316,7 @@ class BulkWriteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[2\]\["upsert"\] to have type "boolean" but found "[\w ]+"/
* @dataProvider provideInvalidBooleanValues
*/
......@@ -328,7 +328,7 @@ class BulkWriteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\Count;
class CountTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorFilterArgumentTypeCheck($filter)
......@@ -16,7 +16,7 @@ class CountTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -25,7 +25,7 @@ class CreateIndexesTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidIndexSpecificationTypes
*/
public function testCreateIndexesRequiresIndexSpecificationsToBeAnArray($index)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\DatabaseCommand;
class DatabaseCommandTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorCommandArgumentTypeCheck($command)
......@@ -16,7 +16,7 @@ class DatabaseCommandTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\Delete;
class DeleteTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorFilterArgumentTypeCheck($filter)
......@@ -31,7 +31,7 @@ class DeleteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\Distinct;
class DistinctTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorFilterArgumentTypeCheck($filter)
......@@ -16,7 +16,7 @@ class DistinctTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\FindAndModify;
class FindAndModifyTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\FindOneAndDelete;
class FindOneAndDeleteTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorFilterArgumentTypeCheck($filter)
......@@ -16,7 +16,7 @@ class FindOneAndDeleteTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\FindOneAndReplace;
class FindOneAndReplaceTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorFilterArgumentTypeCheck($filter)
......@@ -16,7 +16,7 @@ class FindOneAndReplaceTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorReplacementArgumentTypeCheck($replacement)
......@@ -34,7 +34,7 @@ class FindOneAndReplaceTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\FindOneAndUpdate;
class FindOneAndUpdateTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorFilterArgumentTypeCheck($filter)
......@@ -16,7 +16,7 @@ class FindOneAndUpdateTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorUpdateArgumentTypeCheck($update)
......@@ -34,7 +34,7 @@ class FindOneAndUpdateTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\Find;
class FindTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorFilterArgumentTypeCheck($filter)
......@@ -16,7 +16,7 @@ class FindTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -25,7 +25,7 @@ class InsertManyTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$documents\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
......@@ -35,7 +35,7 @@ class InsertManyTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\InsertOne;
class InsertOneTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorDocumentArgumentTypeCheck($document)
......@@ -16,7 +16,7 @@ class InsertOneTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\ReplaceOne;
class ReplaceOneTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorFilterArgumentTypeCheck($filter)
......@@ -16,7 +16,7 @@ class ReplaceOneTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorReplacementArgumentTypeCheck($replacement)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\UpdateMany;
class UpdateManyTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorFilterArgumentTypeCheck($filter)
......@@ -16,7 +16,7 @@ class UpdateManyTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorUpdateArgumentTypeCheck($update)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\UpdateOne;
class UpdateOneTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorFilterArgumentTypeCheck($filter)
......@@ -16,7 +16,7 @@ class UpdateOneTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues
*/
public function testConstructorUpdateArgumentTypeCheck($update)
......
......@@ -7,7 +7,7 @@ use MongoDB\Operation\Update;
class UpdateTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$filter to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
......@@ -17,7 +17,7 @@ class UpdateTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$update to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/
......@@ -27,7 +27,7 @@ class UpdateTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment