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.
Completed
Pull Request — develop (#371)
by Dane
02:54
created

Handler::render()   C

Complexity

Conditions 10
Paths 8

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 6.1368
c 0
b 0
f 0
cc 10
eloc 13
nc 8
nop 2

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Pterodactyl\Exceptions;
4
5
use Log;
6
use Exception;
7
use DisplayException;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Pterodactyl\Exceptions\DisplayException.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use Illuminate\Auth\AuthenticationException;
9
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
10
11
class Handler extends ExceptionHandler
12
{
13
    /**
14
     * A list of the exception types that should not be reported.
15
     *
16
     * @var array
17
     */
18
    protected $dontReport = [
19
        \Illuminate\Auth\AuthenticationException::class,
20
        \Illuminate\Auth\Access\AuthorizationException::class,
21
        \Symfony\Component\HttpKernel\Exception\HttpException::class,
22
        \Illuminate\Database\Eloquent\ModelNotFoundException::class,
23
        \Illuminate\Session\TokenMismatchException::class,
24
        \Illuminate\Validation\ValidationException::class,
25
    ];
26
27
    /**
28
     * Report or log an exception.
29
     *
30
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
31
     *
32
     * @param  \Exception  $exception
33
     * @return void
34
     */
35
    public function report(Exception $exception)
36
    {
37
        return parent::report($exception);
38
    }
39
40
    /**
41
     * Render an exception into an HTTP response.
42
     *
43
     * @param  \Illuminate\Http\Request  $request
44
     * @param  \Exception                $exception
45
     * @return \Illuminate\Http\Response
46
     */
47
    public function render($request, Exception $exception)
48
    {
49
        if ($request->expectsJson() || $request->isJson() || $request->is(...config('pterodactyl.json_routes'))) {
50
            $exception = $this->prepareException($exception);
51
52
            if (config('app.debug')) {
53
                $report = [
54
                    'code' => (! $this->isHttpException($exception)) ?: $exception->getStatusCode(),
55
                    'message' => class_basename($exception) . ' in ' . $exception->getFile() . ' on line ' . $exception->getLine(),
56
                ];
57
            }
58
59
            $response = response()->json([
60
                'error' => (config('app.debug')) ? $exception->getMessage() : 'An unhandled exception was encountered with this request.',
61
                'exception' => ! isset($report) ?: $report,
62
            ], ($this->isHttpException($exception)) ? $exception->getStatusCode() : 500, [], JSON_UNESCAPED_SLASHES);
63
64
            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...
65
        }
66
67
        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 67 which is incompatible with the return type documented by Pterodactyl\Exceptions\Handler::render of type Illuminate\Http\Response.
Loading history...
68
    }
69
70
    /**
71
     * Convert an authentication exception into an unauthenticated response.
72
     *
73
     * @param  \Illuminate\Http\Request                  $request
74
     * @param  \Illuminate\Auth\AuthenticationException  $exception
75
     * @return \Illuminate\Http\Response
76
     */
77
    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...
78
    {
79
        if ($request->expectsJson()) {
80
            return response()->json(['error' => 'Unauthenticated.'], 401);
81
        }
82
83
        return redirect()->guest(route('auth.login'));
84
    }
85
}
86