Skip to content

Commit

Permalink
unify exception formatting (#23266)
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkruss authored and taylorotwell committed Feb 23, 2018
1 parent 5acb717 commit ba0fa73
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Connectors/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,6 @@ protected function createConnection($driver, $connection, $database, $prefix = '
return new SqlServerConnection($connection, $database, $prefix, $config);
}

throw new InvalidArgumentException("Unsupported driver [$driver]");
throw new InvalidArgumentException("Unsupported driver [{$driver}]");
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Database/DatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected function configuration($name)
$connections = $this->app['config']['database.connections'];

if (is_null($config = Arr::get($connections, $name))) {
throw new InvalidArgumentException("Database [$name] not configured.");
throw new InvalidArgumentException("Database [{$name}] not configured.");
}

return $config;
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1308,9 +1308,9 @@ public static function __callStatic($method, $parameters)
}

if (! isset(static::$macros[$method])) {
$class = static::class;

throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}

if (static::$macros[$method] instanceof Closure) {
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ protected function getRelationshipFromMethod($method)
$relation = $this->$method();

if (! $relation instanceof Relation) {
throw new LogicException(get_class($this).'::'.$method.' must return a relationship instance.');
throw new LogicException(sprintf(
'%s::%s must return a relationship instance.', static::class, $method
));
}

return tap($relation->getResults(), function ($results) use ($method) {
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2519,8 +2519,8 @@ public function __call($method, $parameters)
return $this->dynamicWhere($method, $parameters);
}

$class = static::class;

throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/JsonExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ protected function getJsonBindingParameter($value)
return '?';
}

throw new InvalidArgumentException('JSON value is of illegal type: '.$type);
throw new InvalidArgumentException("JSON value is of illegal type: {$type}");
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ protected function parseVisibility($visibility)
return AdapterInterface::VISIBILITY_PRIVATE;
}

throw new InvalidArgumentException('Unknown visibility: '.$visibility);
throw new InvalidArgumentException("Unknown visibility: {$visibility}");
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Http/RedirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ public function __call($method, $parameters)
return $this->with(Str::snake(substr($method, 4)), $parameters[0]);
}

$class = static::class;

throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}
}
6 changes: 3 additions & 3 deletions src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,8 @@ public function __call($method, $parameters)
return $this->with(Str::snake(substr($method, 4)), $parameters[0]);
}

$class = static::class;

throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}
}
4 changes: 1 addition & 3 deletions src/Illuminate/Notifications/Channels/BroadcastChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ protected function getData($notifiable, Notification $notification)
return $notification->toArray($notifiable);
}

throw new RuntimeException(
'Notification is missing toArray method.'
);
throw new RuntimeException('Notification is missing toArray method.');
}
}
4 changes: 1 addition & 3 deletions src/Illuminate/Notifications/Channels/DatabaseChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ protected function getData($notifiable, Notification $notification)
return $notification->toArray($notifiable);
}

throw new RuntimeException(
'Notification is missing toDatabase / toArray method.'
);
throw new RuntimeException('Notification is missing toDatabase / toArray method.');
}
}
4 changes: 1 addition & 3 deletions src/Illuminate/Redis/RedisManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ public function resolve($name = null)
return $this->resolveCluster($name);
}

throw new InvalidArgumentException(
"Redis connection [{$name}] not configured."
);
throw new InvalidArgumentException("Redis connection [{$name}] not configured.");
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Routing/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public function callAction($method, $parameters)
*/
public function __call($method, $parameters)
{
$class = static::class;

throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}
}
4 changes: 1 addition & 3 deletions src/Illuminate/Routing/Middleware/ThrottleRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ protected function resolveRequestSignature($request)
return sha1($route->getDomain().'|'.$request->ip());
}

throw new RuntimeException(
'Unable to generate the request signature. Route unavailable.'
);
throw new RuntimeException('Unable to generate the request signature. Route unavailable.');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Routing/RouteRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ public function __call($method, $parameters)
return $this->attribute($method, $parameters[0]);
}

$class = static::class;

throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}
}
4 changes: 3 additions & 1 deletion src/Illuminate/Support/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public function driver($driver = null)
$driver = $driver ?: $this->getDefaultDriver();

if (is_null($driver)) {
throw new InvalidArgumentException('Unable to resolve NULL driver for ['.get_class($this).'].');
throw new InvalidArgumentException(sprintf(
'Unable to resolve NULL driver for [%s].', static::class
));
}

// If the given driver has not been created before, we will create the instances
Expand Down
12 changes: 6 additions & 6 deletions src/Illuminate/Support/Traits/Macroable.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public static function hasMacro($name)
public static function __callStatic($method, $parameters)
{
if (! static::hasMacro($method)) {
$class = static::class;

throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}

if (static::$macros[$method] instanceof Closure) {
Expand All @@ -95,9 +95,9 @@ public static function __callStatic($method, $parameters)
public function __call($method, $parameters)
{
if (! static::hasMacro($method)) {
$class = static::class;

throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}

$macro = static::$macros[$method];
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,8 @@ public function __call($method, $parameters)
return $this->callExtension($rule, $parameters);
}

$class = static::class;

throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/View/Engines/EngineResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public function resolve($engine)
return $this->resolved[$engine] = call_user_func($this->resolvers[$engine]);
}

throw new InvalidArgumentException("Engine $engine not found.");
throw new InvalidArgumentException("Engine [{$engine}] not found.");
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/View/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function exists($view)
public function getEngineFromPath($path)
{
if (! $extension = $this->getExtension($path)) {
throw new InvalidArgumentException("Unrecognized extension in file: $path");
throw new InvalidArgumentException("Unrecognized extension in file: {$path}");
}

$engine = $this->extensions[$extension];
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/View/FileViewFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected function parseNamespaceSegments($name)
$segments = explode(static::HINT_PATH_DELIMITER, $name);

if (count($segments) != 2) {
throw new InvalidArgumentException("View [$name] has an invalid name.");
throw new InvalidArgumentException("View [{$name}] has an invalid name.");
}

if (! isset($this->hints[$segments[0]])) {
Expand Down Expand Up @@ -134,7 +134,7 @@ protected function findInPaths($name, $paths)
}
}

throw new InvalidArgumentException("View [$name] not found.");
throw new InvalidArgumentException("View [{$name}] not found.");
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ public function __unset($key)
public function __call($method, $parameters)
{
if (! Str::startsWith($method, 'with')) {
$class = static::class;

throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}

return $this->with(Str::camel(substr($method, 4)), $parameters[0]);
Expand Down

0 comments on commit ba0fa73

Please sign in to comment.