Completed
Push — master ( 08db18...a30a73 )
by recca
09:59
created

Handler::shouldReport()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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