GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ExceptionHandlerServiceProvider::boot()   B
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 31
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 17
nc 1
nop 0
dl 0
loc 31
rs 8.8571
c 1
b 0
f 0
1
<?php
2
/**
3
 * ApiServiceProvider.php.
4
 *
5
 * Description
6
 *
7
 * @author Milkmeowo <[email protected]>
8
 */
9
10
namespace Milkmeowo\Framework\Dingo\Providers;
11
12
use Illuminate\Support\ServiceProvider;
13
use Dingo\Api\Exception\ResourceException;
14
use Illuminate\Auth\AuthenticationException;
15
use Illuminate\Auth\Access\AuthorizationException;
16
use Prettus\Validator\Exceptions\ValidatorException;
17
use Illuminate\Http\Exceptions\HttpResponseException;
18
use Illuminate\Database\Eloquent\ModelNotFoundException;
19
use League\OAuth2\Server\Exception\OAuthServerException;
20
use Symfony\Component\HttpKernel\Exception\HttpException;
21
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
22
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
23
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
24
25
class ExceptionHandlerServiceProvider extends ServiceProvider
26
{
27
    public function boot()
28
    {
29
        $handler = app('Dingo\Api\Exception\Handler');
30
31
        $handler->register(function (AuthorizationException $exception) {
32
            throw new AccessDeniedHttpException($exception->getMessage());
33
        });
34
35
        $handler->register(function (OAuthServerException $e) {
36
            $message = env('API_DEBUG') ? $e->getMessage() : null;
37
            throw new HttpException($e->getHttpStatusCode(), $message, $e, $e->getHttpHeaders());
38
        });
39
40
        $handler->register(function (HttpResponseException $e) {
41
            $message = env('API_DEBUG') ? $e->getMessage() : null;
42
            throw new HttpException($e->getResponse()->getStatusCode(), $message, $e);
43
        });
44
45
        $handler->register(function (AuthenticationException $e) {
46
            throw new UnauthorizedHttpException(null, $e->getMessage(), $e);
47
        });
48
49
        $handler->register(function (ValidatorException $e) {
50
            $messageBag = $e->getMessageBag();
51
            throw new ResourceException($messageBag->first(), $messageBag->all());
52
        });
53
54
        $handler->register(function (ModelNotFoundException $e) {
0 ignored issues
show
Unused Code introduced by
The parameter $e is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
            throw new NotFoundHttpException('No resources found.');
56
        });
57
    }
58
}
59