|
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()); |
|
|
|
|
|
|
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) |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
try { |
|
50
|
|
|
$error = ExceptionFactory::make($err_severity, $err_msg); |
|
51
|
|
|
|
|
52
|
|
|
$this->tracker->handleException($error, $error->getCode()); |
|
|
|
|
|
|
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
|
|
|
|
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
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.