Browse Source

Merge pull request #6263 from pirouet/master

Code Cleanup - RuntimeException
Mark Story 11 years ago
parent
commit
9eeb4dccda

+ 3 - 2
src/Auth/PasswordHasherFactory.php

@@ -15,6 +15,7 @@
 namespace Cake\Auth;
 
 use Cake\Core\App;
+use RuntimeException;
 
 /**
  * Builds password hashing objects
@@ -45,12 +46,12 @@ class PasswordHasherFactory
 
         $className = App::className($class, 'Auth', 'PasswordHasher');
         if (!$className) {
-            throw new \RuntimeException(sprintf('Password hasher class "%s" was not found.', $class));
+            throw new RuntimeException(sprintf('Password hasher class "%s" was not found.', $class));
         }
 
         $hasher = new $className($config);
         if (!($hasher instanceof AbstractPasswordHasher)) {
-            throw new \RuntimeException('Password hasher must extend AbstractPasswordHasher class.');
+            throw new RuntimeException('Password hasher must extend AbstractPasswordHasher class.');
         }
 
         return $hasher;

+ 1 - 1
src/Cache/Cache.php

@@ -237,7 +237,7 @@ class Cache
      * @param array $data An array of data to be stored in the cache
      * @param string $config Optional string configuration name to write to. Defaults to 'default'
      * @return array of bools for each key provided, indicating true for success or false for fail
-     * @throws RuntimeException
+     * @throws \RuntimeException
      */
     public static function writeMany($data, $config = 'default')
     {

+ 2 - 1
src/Controller/Component/CookieComponent.php

@@ -20,6 +20,7 @@ use Cake\Network\Request;
 use Cake\Network\Response;
 use Cake\Utility\Hash;
 use Cake\Utility\Security;
+use RuntimeException;
 
 /**
  * Cookie Component.
@@ -399,7 +400,7 @@ class CookieComponent extends Component
                 'Invalid encryption cipher. Must be one of %s.',
                 implode(', ', $this->_validCiphers)
             );
-            throw new \RuntimeException($msg);
+            throw new RuntimeException($msg);
         }
     }
 

+ 2 - 1
src/Controller/Controller.php

@@ -29,6 +29,7 @@ use Cake\View\ViewVarsTrait;
 use LogicException;
 use ReflectionException;
 use ReflectionMethod;
+use RuntimeException;
 
 /**
  * Application controller class for organization of business logic.
@@ -628,7 +629,7 @@ class Controller implements EventListenerInterface
 
         $this->loadComponent('Paginator');
         if (empty($table)) {
-            throw new \RuntimeException('Unable to locate an object compatible with paginate.');
+            throw new RuntimeException('Unable to locate an object compatible with paginate.');
         }
         return $this->Paginator->paginate($table, $this->paginate);
     }

+ 2 - 1
src/Database/Query.php

@@ -21,6 +21,7 @@ use Cake\Database\Expression\ValuesExpression;
 use Cake\Database\Statement\CallbackStatement;
 use Cake\Database\ValueBinder;
 use IteratorAggregate;
+use RuntimeException;
 
 /**
  * This class represents a Relational database SQL Query. A query can be of
@@ -1208,7 +1209,7 @@ class Query implements ExpressionInterface, IteratorAggregate
     public function insert(array $columns, array $types = [])
     {
         if (empty($columns)) {
-            throw new \RuntimeException('At least 1 column is required to perform an insert.');
+            throw new RuntimeException('At least 1 column is required to perform an insert.');
         }
         $this->_dirty();
         $this->_type = 'insert';

+ 1 - 1
src/Datasource/QueryCacher.php

@@ -34,7 +34,7 @@ class QueryCacher
      *
      * @param string|\Closure $key The key or function to generate a key.
      * @param string|CacheEngine $config The cache config name or cache engine instance.
-     * @throws RuntimeException
+     * @throws \RuntimeException
      */
     public function __construct($key, $config)
     {

+ 3 - 2
src/I18n/ChainMessagesLoader.php

@@ -15,6 +15,7 @@
 namespace Cake\I18n;
 
 use Aura\Intl\Package;
+use RuntimeException;
 
 /**
  * Wraps multiple message loaders calling them one after another until
@@ -53,7 +54,7 @@ class ChainMessagesLoader
     {
         foreach ($this->_loaders as $k => $loader) {
             if (!is_callable($loader)) {
-                throw new \RuntimeException(sprintf(
+                throw new RuntimeException(sprintf(
                     'Loader "%s" in the chain is not a valid callable',
                     $k
                 ));
@@ -65,7 +66,7 @@ class ChainMessagesLoader
             }
 
             if (!($package instanceof Package)) {
-                throw new \RuntimeException(sprintf(
+                throw new RuntimeException(sprintf(
                     'Loader "%s" in the chain did not return a valid Package object',
                     $k
                 ));

+ 2 - 1
src/I18n/MessagesFileLoader.php

@@ -19,6 +19,7 @@ use Cake\Core\App;
 use Cake\Core\Plugin;
 use Cake\Utility\Inflector;
 use Locale;
+use RuntimeException;
 
 /**
  * A generic translations package factory that will load translations files
@@ -132,7 +133,7 @@ class MessagesFileLoader
         $class = App::classname($name, 'I18n\Parser', 'FileParser');
 
         if (!$class) {
-            throw new \RuntimeException(sprintf('Could not find class %s', "{$name}FileParser"));
+            throw new RuntimeException(sprintf('Could not find class %s', "{$name}FileParser"));
         }
 
         $messages = (new $class)->parse($file);

+ 4 - 2
src/I18n/Parser/MoFileParser.php

@@ -14,6 +14,8 @@
  */
 namespace Cake\I18n\Parser;
 
+use RuntimeException;
+
 /**
  * Parses file in PO format
  *
@@ -62,7 +64,7 @@ class MoFileParser
         $stat = fstat($stream);
 
         if ($stat['size'] < self::MO_HEADER_SIZE) {
-            throw new \RuntimeException("Invalid format for MO translations file");
+            throw new RuntimeException("Invalid format for MO translations file");
         }
         $magic = unpack('V1', fread($stream, 4));
         $magic = hexdec(substr(dechex(current($magic)), -8));
@@ -72,7 +74,7 @@ class MoFileParser
         } elseif ($magic == self::MO_BIG_ENDIAN_MAGIC) {
             $isBigEndian = true;
         } else {
-            throw new \RuntimeException("Invalid format for MO translations file");
+            throw new RuntimeException("Invalid format for MO translations file");
         }
 
         // offset formatRevision

+ 2 - 1
src/Network/Http/Response.php

@@ -14,6 +14,7 @@
 namespace Cake\Network\Http;
 
 use Cake\Network\Http\Message;
+use RuntimeException;
 
 /**
  * Implements methods for HTTP responses.
@@ -146,7 +147,7 @@ class Response extends Message
     protected function _decodeGzipBody($body)
     {
         if (!function_exists('gzinflate')) {
-            throw new \RuntimeException('Cannot decompress gzip response body without gzinflate()');
+            throw new RuntimeException('Cannot decompress gzip response body without gzinflate()');
         }
         $offset = 0;
         // Look for gzip 'signature'

+ 4 - 3
src/Network/Session.php

@@ -16,6 +16,7 @@ namespace Cake\Network;
 
 use Cake\Core\App;
 use Cake\Utility\Hash;
+use RuntimeException;
 use SessionHandlerInterface;
 
 /**
@@ -285,7 +286,7 @@ class Session
 
         foreach ($options as $setting => $value) {
             if (ini_set($setting, $value) === false) {
-                throw new \RuntimeException(
+                throw new RuntimeException(
                     sprintf('Unable to configure the session, setting %s failed.', $setting)
                 );
             }
@@ -310,7 +311,7 @@ class Session
         }
 
         if (session_status() === \PHP_SESSION_ACTIVE) {
-            throw new \RuntimeException('Session was already started');
+            throw new RuntimeException('Session was already started');
         }
 
         if (ini_get('session.use_cookies') && headers_sent($file, $line)) {
@@ -318,7 +319,7 @@ class Session
         }
 
         if (!session_start()) {
-            throw new \RuntimeException('Could not start the session');
+            throw new RuntimeException('Could not start the session');
         }
 
         $this->_started = true;

+ 3 - 2
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 RuntimeException;
 
 /**
  * An Association is a relationship established between two tables and is used
@@ -501,7 +502,7 @@ abstract class Association
         if (!empty($options['queryBuilder'])) {
             $dummy = $options['queryBuilder']($dummy);
             if (!($dummy instanceof Query)) {
-                throw new \RuntimeException(sprintf(
+                throw new RuntimeException(sprintf(
                     'Query builder for association "%s" did not return a query',
                     $this->name()
                 ));
@@ -753,7 +754,7 @@ abstract class Association
 
         if (count($foreignKey) !== count($primaryKey)) {
             $msg = 'Cannot match provided foreignKey for "%s", got "(%s)" but expected foreign key for "(%s)"';
-            throw new \RuntimeException(sprintf(
+            throw new RuntimeException(sprintf(
                 $msg,
                 $this->_name,
                 implode(', ', $foreignKey),

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

@@ -20,6 +20,7 @@ use Cake\ORM\Association;
 use Cake\ORM\Association\SelectableAssociationTrait;
 use Cake\ORM\Table;
 use Cake\Utility\Inflector;
+use RuntimeException;
 
 /**
  * Represents an 1 - N relationship where the source side of the relation is
@@ -167,7 +168,7 @@ class BelongsTo extends Association
 
         if (count($foreignKey) !== count($primaryKey)) {
             $msg = 'Cannot match provided foreignKey for "%s", got "(%s)" but expected foreign key for "(%s)"';
-            throw new \RuntimeException(sprintf(
+            throw new RuntimeException(sprintf(
                 $msg,
                 $this->_name,
                 implode(', ', $foreignKey),

+ 2 - 1
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 RuntimeException;
 
 /**
  * Represents an M - N relationship where there exists a junction - or join - table
@@ -312,7 +313,7 @@ class BelongsToMany extends Association
 
         foreach ($fetchQuery->all() as $result) {
             if (!isset($result[$property])) {
-                throw new \RuntimeException(sprintf(
+                throw new RuntimeException(sprintf(
                     '"%s" is missing from the belongsToMany results. Results cannot be created.',
                     $property
                 ));

+ 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 RuntimeException;
 
 /**
  * Represents an N - 1 relationship where the target side of the relationship
@@ -138,7 +139,7 @@ class HasMany extends Association
         if ($options['foreignKey'] === false) {
             $msg = 'Cannot have foreignKey = false for hasMany associations. ' .
                    'You must provide a foreignKey column.';
-            throw new \RuntimeException($msg);
+            throw new RuntimeException($msg);
         }
 
         foreach ((array)$options['foreignKey'] as $key) {

+ 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 RuntimeException;
 
 /**
  * Makes the table to which this is attached to behave like a nested set and
@@ -92,7 +93,7 @@ class TreeBehavior extends Behavior
 
         if ($isNew && $parent) {
             if ($entity->get($primaryKey[0]) == $parent) {
-                throw new \RuntimeException("Cannot set a node's parent as itself");
+                throw new RuntimeException("Cannot set a node's parent as itself");
             }
 
             $parentNode = $this->_getNode($parent);
@@ -237,7 +238,7 @@ class TreeBehavior extends Behavior
         $left = $entity->get($config['left']);
 
         if ($parentLeft > $left && $parentLeft < $right) {
-            throw new \RuntimeException(sprintf(
+            throw new RuntimeException(sprintf(
                 'Cannot use node "%s" as parent for entity "%s"',
                 $parent,
                 $entity->get($this->_getPrimaryKey())

+ 3 - 2
src/ORM/Query.php

@@ -22,6 +22,7 @@ use Cake\ORM\EagerLoader;
 use Cake\ORM\ResultSet;
 use Cake\ORM\Table;
 use JsonSerializable;
+use RuntimeException;
 
 /**
  * Extends the base Query class to provide new methods related to association
@@ -575,7 +576,7 @@ class Query extends DatabaseQuery implements JsonSerializable
     public function cache($key, $config = 'default')
     {
         if ($this->_type !== 'select' && $this->_type !== null) {
-            throw new \RuntimeException('You cannot cache the results of non-select queries.');
+            throw new RuntimeException('You cannot cache the results of non-select queries.');
         }
         return $this->_cache($key, $config);
     }
@@ -588,7 +589,7 @@ class Query extends DatabaseQuery implements JsonSerializable
     public function all()
     {
         if ($this->_type !== 'select' && $this->_type !== null) {
-            throw new \RuntimeException(
+            throw new RuntimeException(
                 'You cannot call all() on a non-select query. Use execute() instead.'
             );
         }

+ 4 - 3
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 RuntimeException;
 
 /**
  * Represents a single database table.
@@ -1482,7 +1483,7 @@ class Table implements RepositoryInterface, EventListenerInterface
                 'Cannot insert row in "%s" table, it has no primary key.',
                 $this->table()
             );
-            throw new \RuntimeException($msg);
+            throw new RuntimeException($msg);
         }
         $keys = array_fill(0, count($primary), null);
         $id = (array)$this->_newId($primary) + $keys;
@@ -1500,7 +1501,7 @@ class Table implements RepositoryInterface, EventListenerInterface
                         implode(', ', $filteredKeys + $entity->extract(array_keys($primary))),
                         implode(', ', array_keys($primary))
                     );
-                    throw new \RuntimeException($msg);
+                    throw new RuntimeException($msg);
                 }
             }
         }
@@ -1851,7 +1852,7 @@ class Table implements RepositoryInterface, EventListenerInterface
     {
         $association = $this->_associations->get($property);
         if (!$association) {
-            throw new \RuntimeException(sprintf(
+            throw new RuntimeException(sprintf(
                 'Table "%s" is not associated with "%s"',
                 get_class($this),
                 $property

+ 1 - 1
src/ORM/TableRegistry.php

@@ -97,7 +97,7 @@ class TableRegistry
      * @param string|null $alias Name of the alias
      * @param array|null $options list of options for the alias
      * @return array The config data.
-     * @throws RuntimeException When you attempt to configure an existing table instance.
+     * @throws \RuntimeException When you attempt to configure an existing table instance.
      */
     public static function config($alias = null, $options = null)
     {

+ 3 - 1
src/Utility/Hash.php

@@ -13,6 +13,8 @@
  */
 namespace Cake\Utility;
 
+use RuntimeException;
+
 /**
  * Library of array functions for manipulating and extracting data
  * from arrays or 'sets' of data.
@@ -444,7 +446,7 @@ class Hash
         }
 
         if (count($keys) !== count($vals)) {
-            throw new \RuntimeException(
+            throw new RuntimeException(
                 'Hash::combine() needs an equal number of keys + values.'
             );
         }

+ 3 - 2
src/View/Form/EntityContext.php

@@ -20,6 +20,7 @@ use Cake\ORM\Entity;
 use Cake\ORM\TableRegistry;
 use Cake\Utility\Inflector;
 use Cake\View\Form\ContextInterface;
+use RuntimeException;
 use Traversable;
 
 /**
@@ -137,7 +138,7 @@ class EntityContext implements ContextInterface
         }
 
         if (!is_object($table)) {
-            throw new \RuntimeException(
+            throw new RuntimeException(
                 'Unable to find table class for current entity'
             );
         }
@@ -296,7 +297,7 @@ class EntityContext implements ContextInterface
             }
             $entity = $next;
         }
-        throw new \RuntimeException(sprintf(
+        throw new RuntimeException(sprintf(
             'Unable to fetch property "%s"',
             implode(".", $path)
         ));

+ 2 - 1
src/View/Helper/FormHelper.php

@@ -34,6 +34,7 @@ use Cake\View\StringTemplateTrait;
 use Cake\View\View;
 use Cake\View\Widget\WidgetRegistry;
 use DateTime;
+use RuntimeException;
 use Traversable;
 
 /**
@@ -2480,7 +2481,7 @@ class FormHelper extends Helper
             $context = new NullContext($this->request, $data);
         }
         if (!($context instanceof ContextInterface)) {
-            throw new \RuntimeException(
+            throw new RuntimeException(
                 'Context objects must implement Cake\View\Form\ContextInterface'
             );
         }

+ 2 - 1
src/View/Widget/DateTimeWidget.php

@@ -18,6 +18,7 @@ use Cake\View\Form\ContextInterface;
 use Cake\View\StringTemplate;
 use Cake\View\Widget\SelectBoxWidget;
 use Cake\View\Widget\WidgetInterface;
+use RuntimeException;
 
 /**
  * Input widget class for generating a date time input widget.
@@ -154,7 +155,7 @@ class DateTimeWidget implements WidgetInterface
                 continue;
             }
             if (!is_array($data[$select])) {
-                throw new \RuntimeException(sprintf(
+                throw new RuntimeException(sprintf(
                     'Options for "%s" must be an array|false|null',
                     $select
                 ));

+ 5 - 4
src/View/Widget/WidgetRegistry.php

@@ -20,6 +20,7 @@ use Cake\View\StringTemplate;
 use Cake\View\View;
 use Cake\View\Widget\WidgetInterface;
 use ReflectionClass;
+use RuntimeException;
 
 /**
  * A registry/factory for input widgets.
@@ -118,7 +119,7 @@ class WidgetRegistry
             if (gettype($object) === 'object' &&
                 !($object instanceof WidgetInterface)
             ) {
-                throw new \RuntimeException(
+                throw new RuntimeException(
                     'Widget objects must implement Cake\View\Widget\WidgetInterface.'
                 );
             }
@@ -141,7 +142,7 @@ class WidgetRegistry
     public function get($name)
     {
         if (!isset($this->_widgets[$name]) && empty($this->_widgets['_default'])) {
-            throw new \RuntimeException(sprintf('Unknown widget "%s"', $name));
+            throw new RuntimeException(sprintf('Unknown widget "%s"', $name));
         }
         if (!isset($this->_widgets[$name])) {
             $name = '_default';
@@ -182,7 +183,7 @@ class WidgetRegistry
         $class = array_shift($widget);
         $className = App::className($class, 'View/Widget', 'Widget');
         if ($className === false || !class_exists($className)) {
-            throw new \RuntimeException(sprintf('Unable to locate widget class "%s"', $class));
+            throw new RuntimeException(sprintf('Unable to locate widget class "%s"', $class));
         }
         if ($type === 'array' && count($widget)) {
             $reflection = new ReflectionClass($className);
@@ -195,7 +196,7 @@ class WidgetRegistry
             $instance = new $className($this->_templates);
         }
         if (!($instance instanceof WidgetInterface)) {
-            throw new \RuntimeException(sprintf('"%s" does not implement the WidgetInterface', $className));
+            throw new RuntimeException(sprintf('"%s" does not implement the WidgetInterface', $className));
         }
         return $instance;
     }