Completed
Push — master ( a2f6eb...9792a6 )
by recca
14s queued 11s
created

Handler::shouldRenderException()   A

Complexity

Conditions 6
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
nc 2
nop 1
dl 0
loc 13
ccs 6
cts 6
cp 1
crap 6
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
namespace Recca0120\LaravelTracy\Exceptions;
4
5
use Exception;
6
use Illuminate\Contracts\Debug\ExceptionHandler;
7
use Illuminate\Contracts\View\View;
8
use Illuminate\Http\Response;
9
use Recca0120\LaravelTracy\DebuggerManager;
10
use Symfony\Component\HttpFoundation\JsonResponse;
11
use Symfony\Component\HttpFoundation\RedirectResponse;
12
use Throwable;
13
14
class Handler implements ExceptionHandler
15
{
16
    /**
17
     * app exception handler.
18
     *
19
     * @var \Illuminate\Contracts\Debug\ExceptionHandler
20
     */
21
    protected $exceptionHandler;
22
23
    /**
24
     * $debuggerManager.
25
     *
26
     * @var \Recca0120\LaravelTracy\DebuggerManager
27
     */
28
    protected $debuggerManager;
29
30
    /**
31
     * __construct.
32
     *
33
     * @param \Illuminate\Contracts\Debug\ExceptionHandler $exceptionHandler
34
     * @param \Recca0120\LaravelTracy\DebuggerManager $debuggerManager
35 12
     */
36
    public function __construct(ExceptionHandler $exceptionHandler, DebuggerManager $debuggerManager)
37 12
    {
38 12
        $this->exceptionHandler = $exceptionHandler;
39 12
        $this->debuggerManager = $debuggerManager;
40
    }
41
42
    /**
43
     * Report or log an exception.
44
     *
45
     * @param  \Throwable  $e
46 1
     * @return void
47
     *
48 1
     * @throws \Exception
49 1
     */
50
    public function report(Throwable $e)
51
    {
52
        $this->exceptionHandler->report($e);
53
    }
54
55
    /**
56
     * Determine if the exception should be reported.
57 1
     *
58
     * @param  \Throwable  $e
59 1
     * @return bool
60
     */
61
    public function shouldReport(Throwable $e)
62
    {
63
        return $this->exceptionHandler->shouldReport($e);
64
    }
65
66
    /**
67
     * Render an exception into an HTTP response.
68
     *
69 8
     * @param  \Illuminate\Http\Request  $request
70
     * @param  \Throwable  $e
71 8
     * @return \Symfony\Component\HttpFoundation\Response
72
     *
73 8
     * @throws \Throwable
74 1
     */
75 1
    public function render($request, Throwable $e)
76 1
    {
77
        $response = $this->exceptionHandler->render($request, $e);
78
79
        if ($this->shouldRenderException($response) === true) {
80 8
            $_SERVER = $request->server();
81
            $response->setContent(
82
                $this->debuggerManager->exceptionHandler($e)
83
            );
84
        }
85
86
        return $response;
87
    }
88
89 1
    /**
90
     * Render an exception to the console.
91 1
     *
92 1
     * @param  \Symfony\Component\Console\Output\OutputInterface  $output
93
     * @param  \Throwable  $e
94
     * @return void
95
     */
96
    public function renderForConsole($output, Throwable $e)
97
    {
98
        $this->exceptionHandler->renderForConsole($output, $e);
99
    }
100 8
101
    /**
102 8
     * shouldRenderException.
103 2
     *
104
     * @param \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response $response
105
     * @return bool
106 6
     */
107 2
    protected function shouldRenderException($response)
108
    {
109
        if (
110 4
            $response instanceof RedirectResponse ||
0 ignored issues
show
Bug introduced by
The class Symfony\Component\HttpFoundation\RedirectResponse does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
111 2
            $response instanceof JsonResponse ||
0 ignored issues
show
Bug introduced by
The class Symfony\Component\HttpFoundation\JsonResponse does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
112
            $response->getContent() instanceof View ||
0 ignored issues
show
Bug introduced by
The class Illuminate\Contracts\View\View does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
113
            ($response instanceof Response && $response->getOriginalContent() instanceof View)
0 ignored issues
show
Bug introduced by
The class Illuminate\Http\Response does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
Bug introduced by
The class Illuminate\Contracts\View\View does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
114 2
        ) {
115 1
            return false;
116
        }
117
118 1
        return true;
119
    }
120
}
121