These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php /** MicroFatalError */ |
||
2 | |||
3 | namespace Micro\Base; |
||
4 | |||
5 | /** |
||
6 | * Class FatalError |
||
7 | * @package Micro\Base |
||
8 | */ |
||
9 | class FatalError |
||
10 | { |
||
11 | protected static $number = 0; |
||
12 | protected static $message = ''; |
||
13 | protected static $file = ''; |
||
14 | protected static $line = 0; |
||
15 | protected static $context = []; |
||
16 | protected static $trace = []; |
||
17 | |||
18 | /** |
||
19 | * Register FatalError handler |
||
20 | */ |
||
21 | public static function register() |
||
22 | { |
||
23 | set_error_handler(['\Micro\Base\FatalError', 'handle']); |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Fatal error handle |
||
28 | * |
||
29 | * @param int $number |
||
30 | * @param string $message |
||
31 | * @param string $file |
||
32 | * @param int $line |
||
33 | * @param array $context |
||
34 | */ |
||
35 | public static function handle($number = 0, $message = '', $file = '', $line = 0, $context = []) |
||
36 | { |
||
37 | self::$context = $context; |
||
38 | self::$message = $message; |
||
39 | self::$number = $number; |
||
40 | self::$trace = debug_backtrace(); |
||
41 | self::$file = $file; |
||
42 | self::$line = $line; |
||
43 | |||
44 | $level = ob_get_level(); |
||
45 | if ($level > 0) { |
||
46 | for ($i = ob_get_level(); $i >= 0; $i--) { |
||
47 | ob_clean(); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | // ob_clean(); |
||
0 ignored issues
–
show
|
|||
52 | // ob_end_clean(); |
||
53 | |||
54 | print('cli' === php_sapi_name() ? static::doCli() : static::doRun()); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | protected static function doCli() |
||
61 | { |
||
62 | return static::$number . ' - ' . static::$message . ' on ' . static::$file . ':' . static::$line; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | protected static function doRun() |
||
69 | { |
||
70 | $str = '<div class="error" style="width: 100%;">'; |
||
71 | $str .= '<h2>FatalError ' . static::$number . ' - ' . static::$message . ' on ' . static::$file . ':' . static::$line . '</h2>'; |
||
72 | |||
73 | $str .= '<table width="100%" style="width: 100%">'; |
||
74 | $str .= '<tr>'; |
||
75 | $str .= '<th width="100px">Context</th>'; |
||
76 | $str .= '<td style="vertical-align: top; height: 300px">'; |
||
77 | $str .= '<textarea disabled style="width:100%; height: 100%">' . print_r(static::$context, true) . '</textarea>'; |
||
78 | $str .= '</td>'; |
||
79 | $str .= '</tr>'; |
||
80 | $str .= '<tr>'; |
||
81 | $str .= '<th width="100px">Debug trace</th>'; |
||
82 | $str .= '<td style="vertical-align: top; height: 300px">'; |
||
83 | $str .= '<textarea disabled style="width: 100%; height: 100%">' . print_r(static::$trace, true) . '</textarea>'; |
||
84 | $str .= '</td>'; |
||
85 | $str .= '</tr>'; |
||
86 | $str .= '</table>'; |
||
87 | $str .= '</div>'; |
||
88 | |||
89 | return $str; |
||
90 | } |
||
91 | } |
||
92 |
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.