Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Handler::unauthenticated()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 4
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace DoeSangue\Exceptions;
4
5
use Exception;
6
use Illuminate\Auth\AuthenticationException;
7
use Illuminate\Validation\ValidationException;
8
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
10
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
11
12
class Handler extends ExceptionHandler
13
{
14
    /**
15
     * A list of the exception types that are not reported.
16
     *
17
     * @var array
18
     */
19
    protected $dontReport = [
20
        /*\Illuminate\Auth\AuthenticationException::class,
21
        \Illuminate\Auth\Access\AuthorizationException::class,
22
        \Symfony\Component\HttpKernel\Exception\HttpException::class,
23
        \Illuminate\Database\Eloquent\ModelNotFoundException::class,
24
        \Illuminate\Session\TokenMismatchException::class,
25
        \Illuminate\Validation\ValidationException::class,
26
        */
27
    ];
28
29
    /**
30
     * A list of the inputs that are never flashed for validation exceptions.
31
     * @var array
32
     */
33
    protected $dontFlash = [
34
      'password',
35
      'password_confirmation',
36
    ];
37
38
    /**
39
     * Report or log an exception.
40
     *
41
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
42
     *
43
     * @param \Exception $exception
44
     */
45 1
    public function report(Exception $exception)
46
    {
47 1
        parent::report($exception);
48 1
    }
49
50
    /**
51
     * Render an exception into an HTTP response.
52
     *
53
     * @param \Illuminate\Http\Request $request
54
     * @param \Exception               $exception
55
     *
56
     * @return \Illuminate\Http\Response
57
     */
58 1
    public function render($request, Exception $exception)
59
    {
60
        // Validate 404 exceptions.
61 1
        if ($exception instanceof NotFoundHttpException) {
62
            return response()->json(
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
63
                [
64
                'error' => [
65
                    'description' => 'Invalid URI',
66
                    'messages' => [ ]
67
                ]
68
                ], 404
69
            );
70
        }
71
72
        // Method not allowed exception handler
73 1
        if ($exception instanceof MethodNotAllowedHttpException) {
74
            return response()->json(
75
                [
76
                'error' => [
77
                    'description' => 'Method Not Allowed',
78
                    'messages' => [ ]
79
                ]
80
                ], 405
81
            );
82
        }
83
84 1
        return parent::render($request, $exception);
85
    }
86
87
    /**
88
     * Convert a validation exception into a JSON response.
89
     *
90
     * @param \Illuminate\Http\Request $request
91
     * @param \Illuminate\Validation\ValidationException $exception
92
     * @return \Illuminate\Http\JsonResponse
93
     */
94
    protected function invalidJson($request, ValidationException $exception)
95
    {
96
      return response()->json($exception->errors(), $exception->status);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
97
    }
98
99
    /**
100
     * Convert an authentication exception into an unauthenticated response.
101
     *
102
     * @param \Illuminate\Http\Request                 $request
103
     * @param \Illuminate\Auth\AuthenticationException $exception
104
     * @return \Illuminate\Http\Response
105
     */
106
    protected function unauthenticated($request, AuthenticationException $exception)
107
    {
108
        if ($request->expectsJson()) {
109
110
            return response()->json([ 'error' => 'Unauthenticated.' ], 401);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
111
112
        }
113
114
        // return redirect()->guest('login');
115
    }
116
117
118
}
119