Browse Source

Code Cleanup - InvalidArgumentException

Ensure files that use InvalidArgumentException have the appropriate use
statement
pirouet 11 years ago
parent
commit
2c5384153b

+ 2 - 1
src/Cache/CacheEngine.php

@@ -15,6 +15,7 @@
 namespace Cake\Cache;
 
 use Cake\Core\InstanceConfigTrait;
+use InvalidArgumentException;
 
 /**
  * Storage engine for CakePHP caching
@@ -245,7 +246,7 @@ abstract class CacheEngine
     {
         $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;

+ 2 - 1
src/Database/Type.php

@@ -15,6 +15,7 @@
 namespace Cake\Database;
 
 use Cake\Database\Driver;
+use InvalidArgumentException;
 use PDO;
 
 /**
@@ -99,7 +100,7 @@ class Type
             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);
     }

+ 4 - 3
src/Datasource/EntityTrait.php

@@ -16,6 +16,7 @@ namespace Cake\Datasource;
 
 use Cake\Collection\Collection;
 use Cake\Utility\Inflector;
+use InvalidArgumentException;
 use Traversable;
 
 /**
@@ -225,7 +226,7 @@ trait EntityTrait
         }
 
         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 @@ trait EntityTrait
     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 @@ trait EntityTrait
     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];

+ 3 - 2
src/Network/Session.php

@@ -16,6 +16,7 @@ namespace Cake\Network;
 
 use Cake\Core\App;
 use Cake\Utility\Hash;
+use InvalidArgumentException;
 use RuntimeException;
 use SessionHandlerInterface;
 
@@ -251,14 +252,14 @@ class Session
 
         $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.'
             );
         }

+ 2 - 1
src/Network/Session/CacheSession.php

@@ -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;
     }

+ 2 - 1
src/Network/Socket.php

@@ -17,6 +17,7 @@ namespace Cake\Network;
 use Cake\Core\InstanceConfigTrait;
 use Cake\Network\Exception\SocketException;
 use Cake\Validation\Validation;
+use InvalidArgumentException;
 
 /**
  * CakePHP network socket connection class.
@@ -375,7 +376,7 @@ class Socket
     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]);

+ 2 - 1
src/ORM/Association.php

@@ -22,6 +22,7 @@ use Cake\ORM\Query;
 use Cake\ORM\Table;
 use Cake\ORM\TableRegistry;
 use Cake\Utility\Inflector;
+use InvalidArgumentException;
 use RuntimeException;
 
 /**
@@ -410,7 +411,7 @@ abstract class Association
     {
         if ($name !== null) {
             if (!in_array($name, $this->_validStrategies)) {
-                throw new \InvalidArgumentException(
+                throw new InvalidArgumentException(
                     sprintf('Invalid strategy "%s" was provided', $name)
                 );
             }

+ 6 - 5
src/ORM/Association/BelongsToMany.php

@@ -20,6 +20,7 @@ use Cake\ORM\Query;
 use Cake\ORM\Table;
 use Cake\ORM\TableRegistry;
 use Cake\Utility\Inflector;
+use InvalidArgumentException;
 use RuntimeException;
 
 /**
@@ -394,7 +395,7 @@ class BelongsToMany extends Association
         }
         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 @@ class BelongsToMany extends Association
         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 @@ class BelongsToMany extends Association
 
         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 @@ class BelongsToMany extends Association
     {
         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);
             }
         }
 

+ 2 - 1
src/ORM/Association/HasMany.php

@@ -20,6 +20,7 @@ use Cake\ORM\Association;
 use Cake\ORM\Association\DependentDeleteTrait;
 use Cake\ORM\Association\ExternalAssociationTrait;
 use Cake\ORM\Table;
+use InvalidArgumentException;
 use RuntimeException;
 
 /**
@@ -92,7 +93,7 @@ class HasMany extends Association
         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(

+ 2 - 1
src/ORM/Association/SelectableAssociationTrait.php

@@ -16,6 +16,7 @@ namespace Cake\ORM\Association;
 
 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 @@ trait SelectableAssociationTrait
         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)
                 );
             }

+ 2 - 1
src/ORM/AssociationCollection.php

@@ -18,6 +18,7 @@ use Cake\ORM\Association;
 use Cake\ORM\AssociationsNormalizerTrait;
 use Cake\ORM\Entity;
 use Cake\ORM\Table;
+use InvalidArgumentException;
 
 /**
  * A container/collection for association classes.
@@ -216,7 +217,7 @@ class AssociationCollection
                     $alias,
                     $table->alias()
                 );
-                throw new \InvalidArgumentException($msg);
+                throw new InvalidArgumentException($msg);
             }
             if ($relation->isOwningSide($table) !== $owningSide) {
                 continue;

+ 3 - 2
src/ORM/Behavior/TreeBehavior.php

@@ -20,6 +20,7 @@ use Cake\Event\Event;
 use Cake\ORM\Behavior;
 use Cake\ORM\Entity;
 use Cake\ORM\Query;
+use InvalidArgumentException;
 use RuntimeException;
 
 /**
@@ -343,7 +344,7 @@ class TreeBehavior extends Behavior
     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 @@ class TreeBehavior extends Behavior
         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) {

+ 2 - 1
src/ORM/EagerLoader.php

@@ -21,6 +21,7 @@ use Cake\ORM\EagerLoadable;
 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 @@ class EagerLoader
         $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)
             );
         }

+ 3 - 2
src/ORM/Table.php

@@ -38,6 +38,7 @@ use Cake\ORM\RulesChecker;
 use Cake\ORM\Rule\IsUnique;
 use Cake\Utility\Inflector;
 use Cake\Validation\Validator;
+use InvalidArgumentException;
 use RuntimeException;
 
 /**
@@ -1573,7 +1574,7 @@ class Table implements RepositoryInterface, EventListenerInterface
 
         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 @@ class Table implements RepositoryInterface, EventListenerInterface
         $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)) {

+ 1 - 1
src/Routing/RouteBuilder.php

@@ -569,7 +569,7 @@ class RouteBuilder
         }
         if (!is_callable($callback)) {
             $msg = 'Need a callable function/object to connect routes.';
-            throw new \InvalidArgumentException($msg);
+            throw new InvalidArgumentException($msg);
         }
 
         if ($this->_path !== '/') {

+ 3 - 2
src/Utility/Hash.php

@@ -13,6 +13,7 @@
  */
 namespace Cake\Utility;
 
+use InvalidArgumentException;
 use RuntimeException;
 
 /**
@@ -52,7 +53,7 @@ class Hash
             $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 @@ class Hash
         }
 
         if (!$return) {
-            throw new \InvalidArgumentException('Invalid data array to nest.');
+            throw new InvalidArgumentException('Invalid data array to nest.');
         }
 
         if ($options['root']) {

+ 3 - 1
src/Validation/ValidationRule.php

@@ -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 @@ class ValidationRule
 
         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'])
             );
         }