Skip to content
Permalink
Browse files

Code Cleanup - RuntimeException

Ensure files that use RuntimeException have the appropriate use
statement
  • Loading branch information...
pirouet
pirouet committed Apr 2, 2015
1 parent 639fcc4 commit 3301d5b8fa9699d492d5eebfea398009e9e735ac
@@ -15,6 +15,7 @@
namespace Cake\Auth;
use Cake\Core\App;
use RuntimeException;
/**
* Builds password hashing objects
@@ -29,7 +30,7 @@ class PasswordHasherFactory
* @param string|array $passwordHasher Name of the password hasher or an array with
* at least the key `className` set to the name of the class to use
* @return \Cake\Auth\AbstractPasswordHasher Password hasher instance
* @throws \RuntimeException If password hasher class not found or
* @throws RuntimeException If password hasher class not found or
* it does not extend Cake\Auth\AbstractPasswordHasher
*/
public static function build($passwordHasher)
@@ -45,14 +46,14 @@ public static function build($passwordHasher)
$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;
}
}
@@ -20,6 +20,7 @@
use Cake\Network\Response;
use Cake\Utility\Hash;
use Cake\Utility\Security;
use RuntimeException;
/**
* Cookie Component.
@@ -390,7 +391,7 @@ protected function _encrypt($value, $encrypt)
*
* @param string $encrypt The cipher name.
* @return void
* @throws \RuntimeException When an invalid cipher is provided.
* @throws RuntimeException When an invalid cipher is provided.
*/
protected function _checkCipher($encrypt)
{
@@ -399,7 +400,7 @@ protected function _checkCipher($encrypt)
'Invalid encryption cipher. Must be one of %s.',
implode(', ', $this->_validCiphers)
);
throw new \RuntimeException($msg);
throw new RuntimeException($msg);
}
}
@@ -29,6 +29,7 @@
use LogicException;
use ReflectionException;
use ReflectionMethod;
use RuntimeException;
/**
* Application controller class for organization of business logic.
@@ -607,7 +608,7 @@ public function referer($default = null, $local = false)
* (e.g: Table instance, 'TableName' or a Query object)
* @return \Cake\ORM\ResultSet Query results
* @link http://book.cakephp.org/3.0/en/controllers.html#Controller::paginate
* @throws \RuntimeException When no compatible table object can be found.
* @throws RuntimeException When no compatible table object can be found.
*/
public function paginate($object = null)
{
@@ -628,7 +629,7 @@ public function paginate($object = null)
$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);
}
@@ -21,6 +21,7 @@
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
@@ -1203,12 +1204,12 @@ public function unionAll($query, $overwrite = false)
* @param array $columns The columns to insert into.
* @param array $types A map between columns & their datatypes.
* @return $this
* @throws \RuntimeException When there are 0 columns.
* @throws RuntimeException When there are 0 columns.
*/
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';
@@ -15,6 +15,7 @@
namespace Cake\I18n;
use Aura\Intl\Package;
use RuntimeException;
/**
* Wraps multiple message loaders calling them one after another until
@@ -47,13 +48,13 @@ public function __construct(array $loaders)
* the chain.
*
* @return \Aura\Intl\Package
* @throws \RuntimeException if any of the loaders in the chain is not a valid callable
* @throws RuntimeException if any of the loaders in the chain is not a valid callable
*/
public function __invoke()
{
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 @@ public function __invoke()
}
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
));
@@ -19,6 +19,7 @@
use Cake\Core\Plugin;
use Cake\Utility\Inflector;
use Locale;
use RuntimeException;
/**
* A generic translations package factory that will load translations files
@@ -101,7 +102,7 @@ public function __construct($name, $locale, $extension = 'po')
* package containing the messages loaded from the file.
*
* @return \Aura\Intl\Package
* @throws \RuntimeException if no file parser class could be found for the specified
* @throws RuntimeException if no file parser class could be found for the specified
* file extension.
*/
public function __invoke()
@@ -132,7 +133,7 @@ public function __invoke()
$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);
@@ -14,6 +14,8 @@
*/
namespace Cake\I18n\Parser;
use RuntimeException;
/**
* Parses file in PO format
*
@@ -53,7 +55,7 @@ class MoFileParser
* @param resource $resource The file to be parsed.
*
* @return array List of messages extracted from the file
* @throws \RuntimeException If stream content has an invalid format.
* @throws RuntimeException If stream content has an invalid format.
*/
public function parse($resource)
{
@@ -62,7 +64,7 @@ public function parse($resource)
$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 @@ public function parse($resource)
} 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
@@ -14,6 +14,7 @@
namespace Cake\Network\Http;
use Cake\Network\Http\Message;
use RuntimeException;
/**
* Implements methods for HTTP responses.
@@ -141,12 +142,12 @@ public function __construct($headers = [], $body = '')
*
* @param string $body Gzip encoded body.
* @return string
* @throws \RuntimeException When attempting to decode gzip content without gzinflate.
* @throws RuntimeException When attempting to decode gzip content without gzinflate.
*/
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'
@@ -16,6 +16,7 @@
use Cake\Core\App;
use Cake\Utility\Hash;
use RuntimeException;
use SessionHandlerInterface;
/**
@@ -275,7 +276,7 @@ public function engine($class = null, array $options = [])
*
* @param array $options Ini options to set.
* @return void
* @throws \RuntimeException if any directive could not be set
* @throws RuntimeException if any directive could not be set
*/
public function options(array $options)
{
@@ -285,7 +286,7 @@ public function options(array $options)
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)
);
}
@@ -296,7 +297,7 @@ public function options(array $options)
* Starts the Session.
*
* @return bool True if session was started
* @throws \RuntimeException if the session was already started
* @throws RuntimeException if the session was already started
*/
public function start()
{
@@ -310,15 +311,15 @@ public function start()
}
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)) {
return;
}
if (!session_start()) {
throw new \RuntimeException('Could not start the session');
throw new RuntimeException('Could not start the session');
}
$this->_started = true;
@@ -22,6 +22,7 @@
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
@@ -470,7 +471,7 @@ protected function _options(array $options)
* @param Query $query the query to be altered to include the target table data
* @param array $options Any extra options or overrides to be taken in account
* @return void
* @throws \RuntimeException if the query builder passed does not return a query
* @throws RuntimeException if the query builder passed does not return a query
* object
*/
public function attachTo(Query $query, array $options = [])
@@ -501,7 +502,7 @@ public function attachTo(Query $query, array $options = [])
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()
));
@@ -740,7 +741,7 @@ protected function _bindNewAssociations($query, $surrogate, $options)
*
* @param array $options list of options passed to attachTo method
* @return array
* @throws \RuntimeException if the number of columns in the foreignKey do not
* @throws RuntimeException if the number of columns in the foreignKey do not
* match the number of columns in the source table primaryKey
*/
protected function _joinCondition($options)
@@ -753,7 +754,7 @@ protected function _joinCondition($options)
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),
@@ -803,7 +804,7 @@ protected function _extractFinder($finderData)
*
* @param string $property the property name
* @return \Cake\ORM\Association
* @throws \RuntimeException if no association with such name exists
* @throws RuntimeException if no association with such name exists
*/
public function __get($property)
{
@@ -20,6 +20,7 @@
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
@@ -154,7 +155,7 @@ public function saveAssociated(EntityInterface $entity, array $options = [])
*
* @param array $options list of options passed to attachTo method
* @return array
* @throws \RuntimeException if the number of columns in the foreignKey do not
* @throws RuntimeException if the number of columns in the foreignKey do not
* match the number of columns in the target table primaryKey
*/
protected function _joinCondition($options)
@@ -167,7 +168,7 @@ protected function _joinCondition($options)
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),
@@ -20,6 +20,7 @@
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
@@ -301,7 +302,7 @@ protected function _joinCondition($options)
* @param \Cake\ORM\Query $fetchQuery The query to get results from
* @param array $options The options passed to the eager loader
* @return array
* @throws \RuntimeException when the association property is not part of the results set.
* @throws RuntimeException when the association property is not part of the results set.
*/
protected function _buildResultMap($fetchQuery, $options)
{
@@ -312,7 +313,7 @@ protected function _buildResultMap($fetchQuery, $options)
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
));
Oops, something went wrong.

0 comments on commit 3301d5b

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