Skip to content
Permalink
Browse files

Code Cleanup - InvalidArgumentException

Ensure files that use InvalidArgumentException have the appropriate use
statement
  • Loading branch information...
pirouet
pirouet committed Apr 3, 2015
1 parent 6859505 commit 2c5384153b5f1b670e0d2cd894b61672ba743cda
@@ -15,6 +15,7 @@
namespace Cake\Cache;
use Cake\Core\InstanceConfigTrait;
use InvalidArgumentException;
/**
* Storage engine for CakePHP caching
@@ -245,7 +246,7 @@ protected function _key($key)
{
$key = $this->key($key);
if (!$key) {
throw new \InvalidArgumentException('An empty value is not valid as a cache key');
throw new InvalidArgumentException('An empty value is not valid as a cache key');
}
return $this->_config['prefix'] . $key;
@@ -15,6 +15,7 @@
namespace Cake\Database;
use Cake\Database\Driver;
use InvalidArgumentException;
use PDO;
/**
@@ -99,7 +100,7 @@ public static function build($name)
return static::$_builtTypes[$name] = new static($name);
}
if (!isset(static::$_types[$name])) {
throw new \InvalidArgumentException(sprintf('Unknown type "%s"', $name));
throw new InvalidArgumentException(sprintf('Unknown type "%s"', $name));
}
return static::$_builtTypes[$name] = new static::$_types[$name]($name);
}
@@ -16,6 +16,7 @@
use Cake\Collection\Collection;
use Cake\Utility\Inflector;
use InvalidArgumentException;
use Traversable;
/**
@@ -225,7 +226,7 @@ public function set($property, $value = null, array $options = [])
}
if (!is_array($property)) {
throw new \InvalidArgumentException('Cannot set an empty property');
throw new InvalidArgumentException('Cannot set an empty property');
}
$options += ['setter' => true, 'guard' => $guard];
@@ -267,7 +268,7 @@ public function set($property, $value = null, array $options = [])
public function &get($property)
{
if (!strlen((string)$property)) {
throw new \InvalidArgumentException('Cannot get an empty property');
throw new InvalidArgumentException('Cannot get an empty property');
}
$value = null;
@@ -294,7 +295,7 @@ public function &get($property)
public function getOriginal($property)
{
if (!strlen((string)$property)) {
throw new \InvalidArgumentException('Cannot get an empty property');
throw new InvalidArgumentException('Cannot get an empty property');
}
if (isset($this->_original[$property])) {
return $this->_original[$property];
@@ -16,6 +16,7 @@
use Cake\Core\App;
use Cake\Utility\Hash;
use InvalidArgumentException;
use RuntimeException;
use SessionHandlerInterface;
@@ -251,14 +252,14 @@ public function engine($class = null, array $options = [])
$className = App::className($class, 'Network/Session');
if (!$className) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
sprintf('The class "%s" does not exist and cannot be used as a session engine', $class)
);
}
$handler = new $className($options);
if (!($handler instanceof SessionHandlerInterface)) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
'The chosen SessionHandler does not implement SessionHandlerInterface, it cannot be used as an engine.'
);
}
@@ -17,6 +17,7 @@
namespace Cake\Network\Session;
use Cake\Cache\Cache;
use InvalidArgumentException;
use SessionHandlerInterface;
/**
@@ -46,7 +47,7 @@ class CacheSession implements SessionHandlerInterface
public function __construct(array $config = [])
{
if (empty($config['config'])) {
throw new \InvalidArgumentException('The cache configuration name to use is required');
throw new InvalidArgumentException('The cache configuration name to use is required');
}
$this->_options = $config;
}
@@ -17,6 +17,7 @@
use Cake\Core\InstanceConfigTrait;
use Cake\Network\Exception\SocketException;
use Cake\Validation\Validation;
use InvalidArgumentException;
/**
* CakePHP network socket connection class.
@@ -375,7 +376,7 @@ public function reset($state = null)
public function enableCrypto($type, $clientOrServer = 'client', $enable = true)
{
if (!array_key_exists($type . '_' . $clientOrServer, $this->_encryptMethods)) {
throw new \InvalidArgumentException('Invalid encryption scheme chosen');
throw new InvalidArgumentException('Invalid encryption scheme chosen');
}
try {
$enableCryptoResult = stream_socket_enable_crypto($this->connection, $enable, $this->_encryptMethods[$type . '_' . $clientOrServer]);
@@ -22,6 +22,7 @@
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\Utility\Inflector;
use InvalidArgumentException;
use RuntimeException;
/**
@@ -410,7 +411,7 @@ public function strategy($name = null)
{
if ($name !== null) {
if (!in_array($name, $this->_validStrategies)) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
sprintf('Invalid strategy "%s" was provided', $name)
);
}
@@ -20,6 +20,7 @@
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\Utility\Inflector;
use InvalidArgumentException;
use RuntimeException;
/**
@@ -394,7 +395,7 @@ public function saveStrategy($strategy = null)
}
if (!in_array($strategy, [self::SAVE_APPEND, self::SAVE_REPLACE])) {
$msg = sprintf('Invalid save strategy "%s"', $strategy);
throw new \InvalidArgumentException($msg);
throw new InvalidArgumentException($msg);
}
return $this->_saveStrategy = $strategy;
}
@@ -473,7 +474,7 @@ protected function _saveTarget(EntityInterface $parentEntity, $entities, $option
if (!(is_array($entities) || $entities instanceof \Traversable)) {
$name = $this->property();
$message = sprintf('Could not save %s, it cannot be traversed', $name);
throw new \InvalidArgumentException($message);
throw new InvalidArgumentException($message);
}
$table = $this->target();
@@ -722,7 +723,7 @@ public function replaceLinks(EntityInterface $sourceEntity, array $targetEntitie
if (count(array_filter($primaryValue, 'strlen')) !== count($primaryKey)) {
$message = 'Could not find primary key value for source entity';
throw new \InvalidArgumentException($message);
throw new InvalidArgumentException($message);
}
return $this->junction()->connection()->transactional(
@@ -835,13 +836,13 @@ protected function _checkPersistenceStatus($sourceEntity, array $targetEntities)
{
if ($sourceEntity->isNew()) {
$error = 'Source entity needs to be persisted before proceeding';
throw new \InvalidArgumentException($error);
throw new InvalidArgumentException($error);
}
foreach ($targetEntities as $entity) {
if ($entity->isNew()) {
$error = 'Cannot link not persisted entities';
throw new \InvalidArgumentException($error);
throw new InvalidArgumentException($error);
}
}
@@ -20,6 +20,7 @@
use Cake\ORM\Association\DependentDeleteTrait;
use Cake\ORM\Association\ExternalAssociationTrait;
use Cake\ORM\Table;
use InvalidArgumentException;
use RuntimeException;
/**
@@ -92,7 +93,7 @@ public function saveAssociated(EntityInterface $entity, array $options = [])
if (!is_array($targetEntities) && !($targetEntities instanceof \Traversable)) {
$name = $this->property();
$message = sprintf('Could not save %s, it cannot be traversed', $name);
throw new \InvalidArgumentException($message);
throw new InvalidArgumentException($message);
}
$properties = array_combine(
@@ -16,6 +16,7 @@
use Cake\Database\Expression\IdentifierExpression;
use Cake\Database\Expression\TupleComparison;
use InvalidArgumentException;
/**
* Represents a type of association that that can be fetched using another query
@@ -106,7 +107,7 @@ protected function _buildQuery($options)
if (!empty($options['fields'])) {
$fields = $fetchQuery->aliasFields($options['fields'], $alias);
if (!in_array($key, $fields)) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
sprintf('You are required to select the "%s" field', $key)
);
}
@@ -18,6 +18,7 @@
use Cake\ORM\AssociationsNormalizerTrait;
use Cake\ORM\Entity;
use Cake\ORM\Table;
use InvalidArgumentException;
/**
* A container/collection for association classes.
@@ -216,7 +217,7 @@ protected function _saveAssociations($table, $entity, $associations, $options, $
$alias,
$table->alias()
);
throw new \InvalidArgumentException($msg);
throw new InvalidArgumentException($msg);
}
if ($relation->isOwningSide($table) !== $owningSide) {
continue;
@@ -20,6 +20,7 @@
use Cake\ORM\Behavior;
use Cake\ORM\Entity;
use Cake\ORM\Query;
use InvalidArgumentException;
use RuntimeException;
/**
@@ -343,7 +344,7 @@ protected function _unmarkInternalTree()
public function findPath(Query $query, array $options)
{
if (empty($options['for'])) {
throw new \InvalidArgumentException("The 'for' key is required for find('path')");
throw new InvalidArgumentException("The 'for' key is required for find('path')");
}
$config = $this->config();
@@ -416,7 +417,7 @@ function ($field) {
list($for, $direct) = [$options['for'], $options['direct']];
if (empty($for)) {
throw new \InvalidArgumentException("The 'for' key is required for find('children')");
throw new InvalidArgumentException("The 'for' key is required for find('children')");
}
if ($query->clause('order') === null) {
@@ -21,6 +21,7 @@
use Cake\ORM\Query;
use Cake\ORM\Table;
use Closure;
use InvalidArgumentException;
/**
* Exposes the methods for storing the associations that should be eager loaded
@@ -377,7 +378,7 @@ protected function _normalizeContain(Table $parent, $alias, $options, $paths)
$defaults = $this->_containOptions;
$instance = $parent->association($alias);
if (!$instance) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
sprintf('%s is not associated with %s', $parent->alias(), $alias)
);
}
@@ -38,6 +38,7 @@
use Cake\ORM\Rule\IsUnique;
use Cake\Utility\Inflector;
use Cake\Validation\Validator;
use InvalidArgumentException;
use RuntimeException;
/**
@@ -1573,7 +1574,7 @@ protected function _update($entity, $data)
if (!$entity->has($primaryColumns)) {
$message = 'All primary key value(s) are needed for updating';
throw new \InvalidArgumentException($message);
throw new InvalidArgumentException($message);
}
$query = $this->query();
@@ -1671,7 +1672,7 @@ protected function _processDelete($entity, $options)
$primaryKey = (array)$this->primaryKey();
if (!$entity->has($primaryKey)) {
$msg = 'Deleting requires all primary key values.';
throw new \InvalidArgumentException($msg);
throw new InvalidArgumentException($msg);
}
if ($options['checkRules'] && !$this->checkRules($entity, RulesChecker::DELETE, $options)) {
@@ -569,7 +569,7 @@ public function scope($path, $params, $callback = null)
}
if (!is_callable($callback)) {
$msg = 'Need a callable function/object to connect routes.';
throw new \InvalidArgumentException($msg);
throw new InvalidArgumentException($msg);
}
if ($this->_path !== '/') {
@@ -13,6 +13,7 @@
*/
namespace Cake\Utility;
use InvalidArgumentException;
use RuntimeException;
/**
@@ -52,7 +53,7 @@ public static function get(array $data, $path, $default = null)
$parts = explode('.', $path);
} else {
if (!is_array($path)) {
throw new \InvalidArgumentException(sprintf(
throw new InvalidArgumentException(sprintf(
'Invalid Parameter %s, should be dot separated path or array.',
$path
));
@@ -1125,7 +1126,7 @@ public static function nest(array $data, array $options = [])
}
if (!$return) {
throw new \InvalidArgumentException('Invalid data array to nest.');
throw new InvalidArgumentException('Invalid data array to nest.');
}
if ($options['root']) {
@@ -18,6 +18,8 @@
*/
namespace Cake\Validation;
use InvalidArgumentException;
/**
* ValidationRule object. Represents a validation method, error message and
* rules for applying such method to a field.
@@ -126,7 +128,7 @@ public function process($value, array $providers, array $context = [])
if (!$isCallable) {
$message = 'Unable to call method "%s" in "%s" provider for field "%s"';
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
sprintf($message, $this->_rule, $this->_provider, $context['field'])
);
}

0 comments on commit 2c53841

Please sign in to comment.
You can’t perform that action at this time.