Conditions | 11 |
Paths | 10 |
Total Lines | 71 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
52 | public static function defaultErrorRender( |
||
53 | string $errType, |
||
54 | string $errMsg, |
||
55 | string $errFile, |
||
56 | int $errLine, |
||
57 | array $backtrace, |
||
58 | $exceptionCode |
||
59 | ) { |
||
60 | http_response_code(500); |
||
61 | ob_clean(); |
||
62 | |||
63 | if (!empty($exceptionCode)) { |
||
64 | $errMsg = '#'.$exceptionCode.' : '.$errMsg; |
||
65 | } |
||
66 | |||
67 | echo ' |
||
68 | <!doctype html> |
||
69 | <html lang="fr"> |
||
70 | <head> |
||
71 | <title>An error is detected !</title> |
||
72 | <style> |
||
73 | html {padding:0; margin:0; background-color:#e3e3e3; font-family:sans-serif; font-size: 1em; word-wrap:break-word;} |
||
74 | div {position:relative; margin:auto; width:950px; border: 1px solid #a6c9e2; top: 30px; margin-bottom:10px;} |
||
75 | p {padding:0; margin:0;} |
||
76 | p.title {font-size:1.2em; background-color:#D0DCE9; padding:10px;} |
||
77 | p.info {padding:5px; margin-top:10px; margin-bottom:10px;} |
||
78 | fieldset {border:none; background-color: white;} |
||
79 | pre {width:910px; line-height:1.5; white-space:pre-line;} |
||
80 | </style> |
||
81 | </head> |
||
82 | <body> |
||
83 | <div> |
||
84 | <p class="title">Niarf, an error is detected !</p> |
||
85 | <p class="info">'.$errType.' Error : <strong>'.$errMsg.'</strong> in '.$errFile.' at line '.$errLine.'</p> |
||
86 | <fieldset><pre>'; |
||
87 | foreach ($backtrace as $i => $info) { |
||
88 | echo '#'.$i.' '.$info['function']; |
||
89 | |||
90 | if (isset($info['args']) && count($info['args']) > 0) { |
||
91 | echo '('; |
||
92 | |||
93 | foreach ($info['args'] as $iArgs => $args) { |
||
94 | if ($iArgs > 0) { |
||
95 | echo ', '; |
||
96 | } |
||
97 | |||
98 | if (is_array($args) || is_object($args)) { |
||
99 | echo gettype($args); |
||
100 | } elseif (is_null($args)) { |
||
101 | echo 'null'; |
||
102 | } else { |
||
103 | echo htmlentities($args); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | echo ')'; |
||
108 | } |
||
109 | |||
110 | if (isset($info['file'], $info['line'])) { |
||
111 | echo ' called at ['.$info['file'].' line '.$info['line'].']'; |
||
112 | } |
||
113 | echo "\n\n"; |
||
114 | } |
||
115 | echo '</pre></fieldset> |
||
116 | </div> |
||
117 | <body> |
||
118 | </html> |
||
119 | '; |
||
120 | |||
121 | ob_flush(); |
||
122 | exit; |
||
123 | } |
||
125 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.