Skip to content

Commit

Permalink
Code Cleanup - InvalidArgumentException
Browse files Browse the repository at this point in the history
Ensure files that use InvalidArgumentException have the appropriate use
statement
  • Loading branch information
pirouet committed Apr 3, 2015
1 parent 6859505 commit 2c53841
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/Cache/CacheEngine.php
Expand Up @@ -15,6 +15,7 @@
namespace Cake\Cache;

use Cake\Core\InstanceConfigTrait;
use InvalidArgumentException;

/**
* Storage engine for CakePHP caching
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/Database/Type.php
Expand Up @@ -15,6 +15,7 @@
namespace Cake\Database;

use Cake\Database\Driver;
use InvalidArgumentException;
use PDO;

/**
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions src/Datasource/EntityTrait.php
Expand Up @@ -16,6 +16,7 @@

use Cake\Collection\Collection;
use Cake\Utility\Inflector;
use InvalidArgumentException;
use Traversable;

/**
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand Down
5 changes: 3 additions & 2 deletions src/Network/Session.php
Expand Up @@ -16,6 +16,7 @@

use Cake\Core\App;
use Cake\Utility\Hash;
use InvalidArgumentException;
use RuntimeException;
use SessionHandlerInterface;

Expand Down Expand Up @@ -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.'
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Network/Session/CacheSession.php
Expand Up @@ -17,6 +17,7 @@
namespace Cake\Network\Session;

use Cake\Cache\Cache;
use InvalidArgumentException;
use SessionHandlerInterface;

/**
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Network/Socket.php
Expand Up @@ -17,6 +17,7 @@
use Cake\Core\InstanceConfigTrait;
use Cake\Network\Exception\SocketException;
use Cake\Validation\Validation;
use InvalidArgumentException;

/**
* CakePHP network socket connection class.
Expand Down Expand Up @@ -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]);
Expand Down
3 changes: 2 additions & 1 deletion src/ORM/Association.php
Expand Up @@ -22,6 +22,7 @@
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\Utility\Inflector;
use InvalidArgumentException;
use RuntimeException;

/**
Expand Down Expand Up @@ -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)
);
}
Expand Down
11 changes: 6 additions & 5 deletions src/ORM/Association/BelongsToMany.php
Expand Up @@ -20,6 +20,7 @@
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\Utility\Inflector;
use InvalidArgumentException;
use RuntimeException;

/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/ORM/Association/HasMany.php
Expand Up @@ -20,6 +20,7 @@
use Cake\ORM\Association\DependentDeleteTrait;
use Cake\ORM\Association\ExternalAssociationTrait;
use Cake\ORM\Table;
use InvalidArgumentException;
use RuntimeException;

/**
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/ORM/Association/SelectableAssociationTrait.php
Expand Up @@ -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
Expand Down Expand Up @@ -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)
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/ORM/AssociationCollection.php
Expand Up @@ -18,6 +18,7 @@
use Cake\ORM\AssociationsNormalizerTrait;
use Cake\ORM\Entity;
use Cake\ORM\Table;
use InvalidArgumentException;

/**
* A container/collection for association classes.
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/ORM/Behavior/TreeBehavior.php
Expand Up @@ -20,6 +20,7 @@
use Cake\ORM\Behavior;
use Cake\ORM\Entity;
use Cake\ORM\Query;
use InvalidArgumentException;
use RuntimeException;

/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/ORM/EagerLoader.php
Expand Up @@ -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
Expand Down Expand Up @@ -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)
);
}
Expand Down
5 changes: 3 additions & 2 deletions src/ORM/Table.php
Expand Up @@ -38,6 +38,7 @@
use Cake\ORM\Rule\IsUnique;
use Cake\Utility\Inflector;
use Cake\Validation\Validator;
use InvalidArgumentException;
use RuntimeException;

/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Routing/RouteBuilder.php
Expand Up @@ -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 !== '/') {
Expand Down
5 changes: 3 additions & 2 deletions src/Utility/Hash.php
Expand Up @@ -13,6 +13,7 @@
*/
namespace Cake\Utility;

use InvalidArgumentException;
use RuntimeException;

/**
Expand Down Expand Up @@ -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
));
Expand Down Expand Up @@ -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']) {
Expand Down
4 changes: 3 additions & 1 deletion src/Validation/ValidationRule.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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'])
);
}
Expand Down

0 comments on commit 2c53841

Please sign in to comment.