| 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 |
||
| 58 | public static function defaultErrorRender( |
||
| 59 | string $errType, |
||
| 60 | string $errMsg, |
||
| 61 | string $errFile, |
||
| 62 | int $errLine, |
||
| 63 | array $backtrace, |
||
| 64 | $exceptionCode |
||
| 65 | ) { |
||
| 66 | http_response_code(500); |
||
| 67 | ob_clean(); |
||
| 68 | |||
| 69 | if (!empty($exceptionCode)) { |
||
| 70 | $errMsg = '#'.$exceptionCode.' : '.$errMsg; |
||
| 71 | } |
||
| 72 | |||
| 73 | echo ' |
||
| 74 | <!doctype html> |
||
| 75 | <html lang="fr"> |
||
| 76 | <head> |
||
| 77 | <title>An error is detected !</title> |
||
| 78 | <style> |
||
| 79 | html {padding:0; margin:0; background-color:#e3e3e3; font-family:sans-serif; font-size: 1em; word-wrap:break-word;} |
||
| 80 | div {position:relative; margin:auto; width:950px; border: 1px solid #a6c9e2; top: 30px; margin-bottom:10px;} |
||
| 81 | p {padding:0; margin:0;} |
||
| 82 | p.title {font-size:1.2em; background-color:#D0DCE9; padding:10px;} |
||
| 83 | p.info {padding:5px; margin-top:10px; margin-bottom:10px;} |
||
| 84 | fieldset {border:none; background-color: white;} |
||
| 85 | pre {width:910px; line-height:1.5;} |
||
| 86 | </style> |
||
| 87 | </head> |
||
| 88 | <body> |
||
| 89 | <div> |
||
| 90 | <p class="title">Niarf, an error is detected !</p> |
||
| 91 | <p class="info">'.$errType.' Error : <strong>'.$errMsg.'</strong> in '.$errFile.' at line '.$errLine.'</p> |
||
| 92 | <fieldset><pre>'; |
||
| 93 | foreach ($backtrace as $i => $info) { |
||
| 94 | echo '#'.$i.' '.$info['function']; |
||
| 95 | |||
| 96 | if (isset($info['args']) && count($info['args']) > 0) { |
||
| 97 | echo '('; |
||
| 98 | |||
| 99 | foreach ($info['args'] as $iArgs => $args) { |
||
| 100 | if ($iArgs > 0) { |
||
| 101 | echo ', '; |
||
| 102 | } |
||
| 103 | |||
| 104 | if (is_array($args) || is_object($args)) { |
||
| 105 | echo gettype($args); |
||
| 106 | } elseif (is_null($args)) { |
||
| 107 | echo 'null'; |
||
| 108 | } else { |
||
| 109 | echo htmlentities($args); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | echo ')'; |
||
| 114 | } |
||
| 115 | |||
| 116 | if (isset($info['file'], $info['line'])) { |
||
| 117 | echo ' called at ['.$info['file'].' line '.$info['line'].']'; |
||
| 118 | } |
||
| 119 | echo "\n\n"; |
||
| 120 | } |
||
| 121 | echo '</pre></fieldset> |
||
| 122 | </div> |
||
| 123 | <body> |
||
| 124 | </html> |
||
| 125 | '; |
||
| 126 | |||
| 127 | ob_flush(); |
||
| 128 | exit; |
||
|
1 ignored issue
–
show
|
|||
| 129 | } |
||
| 131 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.