A free open source IT asset/license management system
Apply pint to Exceptions directory
snipe2e7046a810ce
diff --git a/app/Exceptions/AssetNotRequestable.php b/app/Exceptions/AssetNotRequestable.phpindex 4067dda385..34e8d91811 100644--- a/app/Exceptions/AssetNotRequestable.php+++ b/app/Exceptions/AssetNotRequestable.php@@ -4,6 +4,4 @@ namespace App\Exceptions;use Exception;-class AssetNotRequestable extends Exception-{-}+class AssetNotRequestable extends Exception {}diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.phpindex a377835a34..7ca5f57d11 100644--- a/app/Exceptions/Handler.php+++ b/app/Exceptions/Handler.php@@ -2,16 +2,25 @@namespace App\Exceptions;-use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;use App\Helpers\Helper;-use Illuminate\Validation\ValidationException;-use Illuminate\Auth\AuthenticationException;use ArieTimmerman\Laravel\SCIMServer\Exceptions\SCIMException;+use Carbon\Exceptions\InvalidFormatException;+use Illuminate\Auth\Access\AuthorizationException;+use Illuminate\Auth\AuthenticationException;+use Illuminate\Database\Eloquent\ModelNotFoundException;+use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;+use Illuminate\Http\JsonResponse;+use Illuminate\Http\RedirectResponse;+use Illuminate\Http\Request;+use Illuminate\Http\Response;+use Illuminate\Session\TokenMismatchException;use Illuminate\Support\Facades\Log;-use Throwable;+use Illuminate\Validation\ValidationException;+use Intervention\Image\Exception\NotSupportedException;use JsonException;-use Carbon\Exceptions\InvalidFormatException;-use Illuminate\Http\Exceptions\ThrottleRequestsException;+use League\OAuth2\Server\Exception\OAuthServerException;+use Symfony\Component\HttpKernel\Exception\HttpException;+use Throwable;class Handler extends ExceptionHandler{@@ -21,16 +30,16 @@ class Handler extends ExceptionHandler* @var array*/protected $dontReport = [- \Illuminate\Auth\AuthenticationException::class,- \Illuminate\Auth\Access\AuthorizationException::class,- \Symfony\Component\HttpKernel\Exception\HttpException::class,- \Illuminate\Database\Eloquent\ModelNotFoundException::class,- \Illuminate\Session\TokenMismatchException::class,- \Illuminate\Validation\ValidationException::class,- \Intervention\Image\Exception\NotSupportedException::class,- \League\OAuth2\Server\Exception\OAuthServerException::class,+ AuthenticationException::class,+ AuthorizationException::class,+ HttpException::class,+ ModelNotFoundException::class,+ TokenMismatchException::class,+ ValidationException::class,+ NotSupportedException::class,+ OAuthServerException::class,JsonException::class,- SCIMException::class, //these generally don't need to be reported+ SCIMException::class, // these generally don't need to be reportedInvalidFormatException::class,];@@ -39,7 +48,6 @@ class Handler extends ExceptionHandler** This is a great spot to send exceptions to Sentry, Bugsnag, etc.*- * @param \Throwable $exception* @return void*/public function report(Throwable $exception)@@ -48,23 +56,23 @@ class Handler extends ExceptionHandlerif (class_exists(Log::class)) {Log::error($exception);}+return parent::report($exception);}}/*** Render an exception into an HTTP response.- *- * @param \Illuminate\Http\Request $request+ *+ * @param Request $request* @param \Exception $e- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Http\Response+ * @return JsonResponse|RedirectResponse|Response*/public function render($request, Throwable $e){-// CSRF token mismatch error- if ($e instanceof \Illuminate\Session\TokenMismatchException) {+ if ($e instanceof TokenMismatchException) {return redirect()->back()->with('error', trans('general.token_expired'));}@@ -78,9 +86,10 @@ class Handler extends ExceptionHandlerif ($e instanceof SCIMException) {try {$e->report(); // logs as 'debug', so shouldn't get too noisy- } catch(\Exception $reportException) {- //do nothing+ } catch (\Exception $reportException) {+ // do nothing}+return $e->render($request); // ALL SCIMExceptions have the 'render()' method}@@ -98,9 +107,10 @@ class Handler extends ExceptionHandler}// Handle API requests that fail because the model doesn't exist- if ($e instanceof \Illuminate\Database\Eloquent\ModelNotFoundException) {+ if ($e instanceof ModelNotFoundException) {$className = last(explode('\\', $e->getModel()));- return response()->json(Helper::formatStandardApiResponse('error', null, $className . ' not found'), 200);++ return response()->json(Helper::formatStandardApiResponse('error', null, $className.' not found'), 200);}// Handle API requests that fail because of an HTTP status code and return a useful error message@@ -111,8 +121,8 @@ class Handler extends ExceptionHandler// API throttle requests are handled in the RouteServiceProvider configureRateLimiting() method, so we don't need to handle them hereswitch ($e->getStatusCode()) {case '404':- return response()->json(Helper::formatStandardApiResponse('error', null, $statusCode . ' endpoint not found'), 404);- case '405':+ return response()->json(Helper::formatStandardApiResponse('error', null, $statusCode.' endpoint not found'), 404);+ case '405':return response()->json(Helper::formatStandardApiResponse('error', null, 'Method not allowed'), 405);default:return response()->json(Helper::formatStandardApiResponse('error', null, $statusCode), $statusCode);@@ -124,19 +134,20 @@ class Handler extends ExceptionHandler// never even get to the controller where we normally nicely format JSON responsesif ($e instanceof ValidationException) {$response = $this->invalidJson($request, $e);- return response()->json(Helper::formatStandardApiResponse('error', null, $e->errors()), 200);++ return response()->json(Helper::formatStandardApiResponse('error', null, $e->errors()), 200);}}-// This is traaaaash but it handles models that are not found while using route model binding :(// The only alternative is to set that at *each* route, which is crazypants- if ($e instanceof \Illuminate\Database\Eloquent\ModelNotFoundException) {+ if ($e instanceof ModelNotFoundException) {$ids = method_exists($e, 'getIds') ? $e->getIds() : [];if (in_array('bulkedit', $ids, true)) {- $error_array = session()->get('bulk_asset_errors');+ $error_array = session()->get('bulk_asset_errors');+return redirect()->route('hardware.index')->withErrors($error_array, 'bulk_asset_errors')@@ -144,7 +155,7 @@ class Handler extends ExceptionHandler}// This gets the MVC model name from the exception and formats in a way that's less fugly- $model_name = trim(strtolower(implode(" ", preg_split('/(?=[A-Z])/', last(explode('\\', $e->getModel()))))));+ $model_name = trim(strtolower(implode(' ', preg_split('/(?=[A-Z])/', last(explode('\\', $e->getModel()))))));$route = str_plural(strtolower(last(explode('\\', $e->getModel())))).'.index';// Sigh.@@ -171,24 +182,22 @@ class Handler extends ExceptionHandler->withError(trans('general.generic_model_not_found', ['model' => $model_name]));}-- if ($this->isHttpException($e) && (isset($statusCode)) && ($statusCode == '404' )) {+ if ($this->isHttpException($e) && (isset($statusCode)) && ($statusCode == '404')) {return response()->view('layouts/basic', [- 'content' => view('errors/404')- ],$statusCode);+ 'content' => view('errors/404'),+ ], $statusCode);}return parent::render($request, $e);}- /**+ /*** Convert an authentication exception into an unauthenticated response.*- * @param \Illuminate\Http\Request $request- * @param \Illuminate\Auth\AuthenticationException $exception- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse- */+ * @param Request $request+ * @return JsonResponse|RedirectResponse+ */protected function unauthenticated($request, AuthenticationException $exception){if ($request->expectsJson()) {@@ -203,8 +212,7 @@ class Handler extends ExceptionHandlerreturn response()->json(Helper::formatStandardApiResponse('error', null, $exception->errors()), 200);}-- /**+ /*** A list of the inputs that are never flashed for validation exceptions.** @var arraydiff --git a/app/Exceptions/ItemStillHasAccessories.php b/app/Exceptions/ItemStillHasAccessories.phpindex b40551b08b..030a55b64a 100644--- a/app/Exceptions/ItemStillHasAccessories.php+++ b/app/Exceptions/ItemStillHasAccessories.php@@ -2,8 +2,6 @@namespace App\Exceptions;-use Exception;-class ItemStillHasAccessories extends ItemStillHasChildren{//diff --git a/app/Exceptions/ItemStillHasAssetModels.php b/app/Exceptions/ItemStillHasAssetModels.phpindex ba71399d51..aa868f2df0 100644--- a/app/Exceptions/ItemStillHasAssetModels.php+++ b/app/Exceptions/ItemStillHasAssetModels.php@@ -2,8 +2,6 @@namespace App\Exceptions;-use Exception;-class ItemStillHasAssetModels extends ItemStillHasChildren{//diff --git a/app/Exceptions/ItemStillHasAssets.php b/app/Exceptions/ItemStillHasAssets.phpindex 9cb0782445..1081c718aa 100644--- a/app/Exceptions/ItemStillHasAssets.php+++ b/app/Exceptions/ItemStillHasAssets.php@@ -2,8 +2,4 @@namespace App\Exceptions;-use Exception;--class ItemStillHasAssets extends ItemStillHasChildren-{-}+class ItemStillHasAssets extends ItemStillHasChildren {}diff --git a/app/Exceptions/ItemStillHasChildren.php b/app/Exceptions/ItemStillHasChildren.phpindex e58f3e98fa..e800720477 100644--- a/app/Exceptions/ItemStillHasChildren.php+++ b/app/Exceptions/ItemStillHasChildren.php@@ -6,9 +6,9 @@ use Exception;class ItemStillHasChildren extends Exception{- //public function __construct($message, $code = 0, Exception $previous = null, $parent, $children)- //{+ // public function __construct($message, $code = 0, Exception $previous = null, $parent, $children)+ // {// trans()//- //}+ // }}diff --git a/app/Exceptions/ItemStillHasComponents.php b/app/Exceptions/ItemStillHasComponents.phpindex 77cfa5a6a0..4f5e838021 100644--- a/app/Exceptions/ItemStillHasComponents.php+++ b/app/Exceptions/ItemStillHasComponents.php@@ -2,8 +2,6 @@namespace App\Exceptions;-use Exception;-class ItemStillHasComponents extends ItemStillHasChildren{//diff --git a/app/Exceptions/ItemStillHasConsumables.php b/app/Exceptions/ItemStillHasConsumables.phpindex 917d1f62c5..c3b8b4e522 100644--- a/app/Exceptions/ItemStillHasConsumables.php+++ b/app/Exceptions/ItemStillHasConsumables.php@@ -2,8 +2,6 @@namespace App\Exceptions;-use Exception;-class ItemStillHasConsumables extends ItemStillHasChildren{//diff --git a/app/Exceptions/ItemStillHasLicenses.php b/app/Exceptions/ItemStillHasLicenses.phpindex 454460fe76..2a9566cd70 100644--- a/app/Exceptions/ItemStillHasLicenses.php+++ b/app/Exceptions/ItemStillHasLicenses.php@@ -2,8 +2,6 @@namespace App\Exceptions;-use Exception;-class ItemStillHasLicenses extends ItemStillHasChildren{//diff --git a/app/Exceptions/ItemStillHasMaintenances.php b/app/Exceptions/ItemStillHasMaintenances.phpindex 2cebf71357..efe3667dad 100644--- a/app/Exceptions/ItemStillHasMaintenances.php+++ b/app/Exceptions/ItemStillHasMaintenances.php@@ -2,8 +2,6 @@namespace App\Exceptions;-use Exception;-class ItemStillHasMaintenances extends ItemStillHasChildren{//diff --git a/app/Exceptions/UserDoestExistException.php b/app/Exceptions/UserDoestExistException.phpindex e14069dca4..81aa820460 100644--- a/app/Exceptions/UserDoestExistException.php+++ b/app/Exceptions/UserDoestExistException.php@@ -4,7 +4,4 @@ namespace App\Exceptions;use Exception;-class UserDoestExistException extends Exception-{--}+class UserDoestExistException extends Exception {}