Completed
Push — master ( 7c4e6d...6c75d9 )
by
unknown
26s
created

Handler   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 78
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A initializeHandlers() 0 6 1
A handleException() 0 11 2
A handleError() 0 13 2
A report() 0 10 2
A shouldReport() 0 4 1
A render() 0 4 1
A renderForConsole() 0 4 1
1
<?php
2
3
namespace PragmaRX\Tracker\Support\Exceptions;
4
5
use Exception;
6
use Illuminate\Contracts\Debug\ExceptionHandler;
7
use PragmaRX\Tracker\Tracker;
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, 'handleException']);
31
32
        $this->originalErrorHandler = set_error_handler([$this, 'handleError']);
33
    }
34
35
    public function handleException(Exception $exception)
36
    {
37
        try {
38
            $this->tracker->handleException($exception, $exception->getCode());
0 ignored issues
show
Unused Code introduced by
The call to Tracker::handleException() has too many arguments starting with $exception->getCode().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
39
        } catch (\Exception $e) {
40
            // Ignore Tracker exceptions
41
        }
42
43
        // Call Laravel Exception Handler
44
        return call_user_func($this->originalExceptionHandler, $exception);
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->handleException($error, $error->getCode());
0 ignored issues
show
Unused Code introduced by
The call to Tracker::handleException() has too many arguments starting with $error->getCode().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
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(Exception $e)
62
    {
63
        try {
64
            $this->tracker->handleException($e);
65
        } catch (Exception $exception) {
66
            // ignore
67
        }
68
69
        $this->illuminateHandler->report($e);
70
    }
71
72
    public function shouldReport(Exception $e)
73
    {
74
        return $this->illuminateHandler->shouldReport($e);
75
    }
76
77
    public function render($request, Exception $e)
78
    {
79
        return $this->illuminateHandler->render($request, $e);
80
    }
81
82
    public function renderForConsole($output, Exception $e)
83
    {
84
        return $this->illuminateHandler->renderForConsole($output, $e);
85
    }
86
}
87