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

Test Setup Failed
Pull Request — development (#68)
by José
06:06
created

ExceptionHandler::render()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
namespace GiveBlood\Units;
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 Handler;
11
12
class ExceptionHandler extends Handler
13
{
14
    /**
15
     * A list of the exception types that are not reported.
16
     *
17
     * @var array
18
     */
19
    protected $dontReport = [
20
        //
21
    ];
22
23
    /**
24
     * A list of the inputs that are never flashed for validation exceptions.
25
     *
26
     * @var array
27
     */
28
    protected $dontFlash = [
29
        'password',
30
        'password_confirmation',
31
    ];
32
33
    /**
34
     * Report or log an exception.
35
     *
36
     * @param  \Exception $exception
37
     * @return void
38
     */
39
    public function report(Exception $exception)
40
    {
41
        parent::report($exception);
42
    }
43
44
    /**
45
     * Render an exception into an HTTP response.
46
     *
47
     * @param  \Illuminate\Http\Request $request
48
     * @param  \Exception               $exception
49
     * @return \Illuminate\Http\Response
50
     */
51
    public function render($request, Exception $exception)
52
    {
53
        // Validate 404 exceptions.
54
        if ($exception instanceof NotFoundHttpException) {
55
            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...
56
                [
57
                'error' => [
58
                    'description' => 'Invalid URI',
59
                    'messages' => [ ]
60
                ]
61
                ], 404
62
            );
63
        }
64
65
        // Method not allowed exception handler
66
        if ($exception instanceof MethodNotAllowedHttpException) {
67
            return response()->json(
68
                [
69
                'error' => [
70
                    'description' => 'Method Not Allowed',
71
                    'messages' => [ ]
72
                ]
73
                ], 405
74
            );
75
        }
76
        return parent::render($request, $exception);
77
    }
78
79
    /**
80
     * Convert a validation exception into a JSON response.
81
     *
82
     * @param  \Illuminate\Http\Request                   $request
83
     * @param  \Illuminate\Validation\ValidationException $exception
84
     * @return \Illuminate\Http\JsonResponse
85
     */
86
    protected function invalidJson($request, ValidationException $exception)
87
    {
88
        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...
89
    }
90
91
    /**
92
     * Convert an authentication exception into an unauthenticated response.
93
     *
94
     * @param  \Illuminate\Http\Request                 $request
95
     * @param  \Illuminate\Auth\AuthenticationException $exception
96
     * @return \Illuminate\Http\Response
97
     */
98
    protected function unauthenticated($request, AuthenticationException $exception)
99
    {
100
        if ($request->expectsJson()) {
101
102
            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...
103
104
        }
105
106
        // return redirect()->guest('login');
107
    }
108
109
}
110