1 | <?php |
||
17 | class Exception extends \Exception |
||
18 | { |
||
19 | const CRITICAL_ERROR_STRING = '500 Internal Server Error'; |
||
20 | |||
21 | /** |
||
22 | * E_RECOVERABLE_ERROR handler. |
||
23 | * |
||
24 | * Use to re-throw E_RECOVERABLE_ERROR as they occur. |
||
25 | * |
||
26 | * @param int $code The error number. |
||
27 | * @param string $msg The error message. |
||
28 | * @param string $file The filename where the error occured. |
||
29 | * @param int $line The line number where it happened. |
||
30 | * @param \Exception|null $previous The previous chaining Exception. |
||
31 | * @throws \ErrorException |
||
32 | */ |
||
33 | public static function errorHandler( |
||
34 | $code, $msg = '', $file = __FILE__, $line = __LINE__, $previous = null |
||
35 | ) { |
||
36 | if (E_RECOVERABLE_ERROR == $code) { |
||
37 | $msg = preg_replace('@to\s.*::\w+\(\)@', '', $msg, 1); |
||
38 | // $code = 400; // Due to a client error, recoverable. |
||
|
|||
39 | } |
||
40 | $code = 500; // Set as a HTTP Internal Server Error. |
||
41 | |||
42 | if ( null !== $previous && !($previous instanceof \Exception) ) { |
||
43 | |||
44 | Service::get('logger')->error( |
||
45 | '{0} - {1}:{2} {3}', |
||
46 | array($msg, $file, $line, $previous) |
||
47 | ); |
||
48 | |||
49 | $previous = null; |
||
50 | } |
||
51 | |||
52 | throw new \ErrorException($msg, $code, 0, $file, $line, $previous); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Startup exception handler. |
||
57 | * |
||
58 | * @param \Exception $e |
||
59 | * @return array |
||
60 | */ |
||
61 | public static function startupException(\Exception $e) |
||
62 | { |
||
63 | return self::criticalError($e, 'Startup Exception'); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Shutdown/fatal exceptions handler. |
||
68 | * |
||
69 | * @see criticalError |
||
70 | * @return void |
||
71 | * @codeCoverageIgnore |
||
72 | */ |
||
73 | public static function shutdownHandler() |
||
79 | |||
80 | /** |
||
81 | * Handles critical errors (output and logging). |
||
82 | * |
||
83 | * @param \Exception $e |
||
84 | * @return array |
||
85 | */ |
||
86 | public static function criticalError(\Exception $e, $alt_msg) |
||
115 | |||
116 | /** |
||
117 | * Returns the provided exception as a normalize associative array. |
||
118 | * |
||
119 | * @param \Exception $e |
||
120 | * @return array |
||
121 | */ |
||
122 | public static function toArray(\Exception $e) |
||
142 | |||
143 | } |
||
144 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.