Completed
Push — master ( 76e8e7...f18538 )
by Antonio Carlos
14s queued 11s
created

Handler::handleThrowable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace PragmaRX\Tracker\Support\Exceptions;
4
5
use Illuminate\Contracts\Debug\ExceptionHandler;
6
use PragmaRX\Tracker\Tracker;
7
use Throwable;
8
9
class Handler implements ExceptionHandler
10
{
11
    private $tracker;
12
13
    private $illuminateHandler;
14
15
    private $originalExceptionHandler;
16
17
    private $originalErrorHandler;
18
19
    public function __construct(Tracker $tracker, $illuminateHandler = null)
20
    {
21
        $this->tracker = $tracker;
22
23
        $this->illuminateHandler = $illuminateHandler;
24
25
        $this->initializeHandlers();
26
    }
27
28
    private function initializeHandlers()
29
    {
30
        $this->originalExceptionHandler = set_exception_handler([$this, 'handleThrowable']);
31
32
        $this->originalErrorHandler = set_error_handler([$this, 'handleError']);
33
    }
34
35
    public function handleThrowable(Throwable $throwable)
36
    {
37
        try {
38
            $this->tracker->handleThrowable($throwable);
39
        } catch (\Exception $e) {
40
            // Ignore Tracker exceptions
41
        }
42
43
        // Call Laravel Exception Handler
44
        return call_user_func($this->originalExceptionHandler, $throwable);
45
    }
46
47
    public function handleError($err_severity, $err_msg, $err_file, $err_line, array $err_context)
0 ignored issues
show
Unused Code introduced by
The parameter $err_context 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...
48
    {
49
        try {
50
            $error = ExceptionFactory::make($err_severity, $err_msg);
51
52
            $this->tracker->handleThrowable($error);
53
        } catch (\Exception $e) {
54
            // Ignore Tracker exceptions
55
        }
56
57
        // Call Laravel Exception Handler
58
        return call_user_func($this->originalErrorHandler, $err_severity, $err_msg, $err_file, $err_line);
59
    }
60
61
    public function report(Throwable $e)
62
    {
63
        try {
64
            $this->tracker->handleThrowable($e);
65
        } catch (Exception $exception) {
0 ignored issues
show
Bug introduced by
The class PragmaRX\Tracker\Support\Exceptions\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
66
            // ignore
67
        }
68
69
        $this->illuminateHandler->report($e);
70
    }
71
72
    public function shouldReport(Throwable $e)
73
    {
74
        return $this->illuminateHandler->shouldReport($e);
75
    }
76
77
    public function render($request, Throwable $e)
78
    {
79
        return $this->illuminateHandler->render($request, $e);
80
    }
81
82
    public function renderForConsole($output, Throwable $e)
83
    {
84
        return $this->illuminateHandler->renderForConsole($output, $e);
85
    }
86
}
87