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.

Handler::unauthenticated()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace Pterodactyl\Exceptions;
4
5
use Log;
6
use Exception;
7
use Illuminate\Auth\AuthenticationException;
8
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
9
10
class Handler extends ExceptionHandler
11
{
12
    /**
13
     * A list of the exception types that should not be reported.
14
     *
15
     * @var array
16
     */
17
    protected $dontReport = [
18
        \Illuminate\Auth\AuthenticationException::class,
19
        \Illuminate\Auth\Access\AuthorizationException::class,
20
        \Symfony\Component\HttpKernel\Exception\HttpException::class,
21
        \Illuminate\Database\Eloquent\ModelNotFoundException::class,
22
        \Illuminate\Session\TokenMismatchException::class,
23
        \Illuminate\Validation\ValidationException::class,
24
    ];
25
26
    /**
27
     * Report or log an exception.
28
     *
29
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
30
     *
31
     * @param  \Exception  $exception
32
     * @return void
33
     */
34
    public function report(Exception $exception)
35
    {
36
        return parent::report($exception);
37
    }
38
39
    /**
40
     * Render an exception into an HTTP response.
41
     *
42
     * @param  \Illuminate\Http\Request  $request
43
     * @param  \Exception                $exception
44
     * @return \Illuminate\Http\Response
45
     */
46
    public function render($request, Exception $exception)
47
    {
48
        if ($request->expectsJson() || $request->isJson() || $request->is(...config('pterodactyl.json_routes'))) {
49
            $exception = $this->prepareException($exception);
50
51
            if (config('app.debug') || $this->isHttpException($exception)) {
52
                $displayError = $exception->getMessage();
53
            } else {
54
                $displayError = 'An unhandled exception was encountered with this request.';
55
            }
56
57
            $response = response()->json([
58
                'error' => $displayError,
59
                'http_code' => (! $this->isHttpException($exception)) ?: $exception->getStatusCode(),
60
                'trace' => (! config('app.debug')) ? null : class_basename($exception) . ' in ' . $exception->getFile() . ' on line ' . $exception->getLine(),
61
            ], ($this->isHttpException($exception)) ? $exception->getStatusCode() : 500, [], JSON_UNESCAPED_SLASHES);
62
63
            parent::report($exception);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (report() instead of render()). Are you sure this is correct? If so, you might want to change this to $this->report().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
64
        }
65
66
        return (isset($response)) ? $response : parent::render($request, $exception);
0 ignored issues
show
Bug Compatibility introduced by
The expression isset($response) ? $resp...($request, $exception); of type Illuminate\Http\JsonResp...HttpFoundation\Response adds the type Illuminate\Http\JsonResponse to the return on line 66 which is incompatible with the return type documented by Pterodactyl\Exceptions\Handler::render of type Illuminate\Http\Response.
Loading history...
67
    }
68
69
    /**
70
     * Convert an authentication exception into an unauthenticated response.
71
     *
72
     * @param  \Illuminate\Http\Request                  $request
73
     * @param  \Illuminate\Auth\AuthenticationException  $exception
74
     * @return \Illuminate\Http\Response
75
     */
76
    protected function unauthenticated($request, AuthenticationException $exception)
0 ignored issues
show
Unused Code introduced by
The parameter $exception 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...
77
    {
78
        if ($request->expectsJson()) {
79
            return response()->json(['error' => 'Unauthenticated.'], 401);
80
        }
81
82
        return redirect()->guest(route('auth.login'));
83
    }
84
}
85