1 | <?php |
||
7 | class ErrorHandler |
||
8 | { |
||
9 | |||
10 | /** @var \League\CLImate\CLImate */ |
||
11 | private $cli; |
||
12 | |||
13 | protected $verbose = false; |
||
14 | |||
15 | public function __construct(CLImate $cli) |
||
19 | |||
20 | /** |
||
21 | * Register this error handler |
||
22 | */ |
||
23 | public function register() |
||
28 | |||
29 | public function setVerbose($verbose) |
||
33 | |||
34 | /** |
||
35 | * Handle an exception |
||
36 | * @param \Exception $e |
||
37 | */ |
||
38 | public function handleException(\Exception $e) |
||
51 | |||
52 | /** |
||
53 | * Handle an error |
||
54 | * @param int $code |
||
55 | * @param string $message |
||
56 | * @param string $file |
||
57 | * @param int $line |
||
58 | * @param array $context |
||
59 | * @return bool |
||
60 | */ |
||
61 | public function handleError($code, $message, $file, $line, $context) |
||
62 | { |
||
63 | if (!(error_reporting() & $code)) { |
||
64 | return false; |
||
65 | } |
||
66 | |||
67 | $cli = $this->cli; |
||
68 | |||
69 | switch ($code) { |
||
70 | case E_ERROR: |
||
71 | case E_USER_ERROR: |
||
72 | $type = '<error>Fatal Error</error>'; |
||
73 | break; |
||
74 | case E_RECOVERABLE_ERROR: |
||
75 | case E_WARNING: |
||
76 | case E_USER_WARNING: |
||
77 | $type = '<yellow>Warning</yellow>'; |
||
78 | break; |
||
79 | case E_NOTICE: |
||
80 | case E_USER_NOTICE: |
||
81 | $type = '<green>Notice</green>'; |
||
82 | break; |
||
83 | case E_DEPRECATED: |
||
84 | case E_USER_DEPRECATED: |
||
85 | $type = '<blue>Deprecated Alert</blue>'; |
||
86 | break; |
||
87 | default: |
||
88 | $type = 'Unknown Error'; |
||
89 | break; |
||
90 | } |
||
91 | |||
92 | $cli->errorInline(sprintf('<bold>%s</bold> ', $type)) |
||
93 | ->errorInline(sprintf('on line <bold><yellow>%s</yellow></bold> ', $line)) |
||
94 | ->error(sprintf('in <bold><yellow>%s</yellow></bold>', $file)); |
||
95 | |||
96 | $cli->out("<dim><error>>></error></dim> " . $message); |
||
97 | |||
98 | $this->outputStack(); |
||
99 | exit(1); |
||
100 | } |
||
101 | |||
102 | protected function outputStack() |
||
146 | |||
147 | } |
||
148 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.