| Conditions | 10 |
| Paths | 12 |
| Total Lines | 76 |
| Code Lines | 49 |
| 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 |
||
| 92 | protected function haltHttp($errorInfo = []) |
||
| 93 | { |
||
| 94 | switch ($errorInfo['code']) { |
||
| 95 | case 404: |
||
| 96 | $statusCode = 404; //not found |
||
| 97 | $title = 'Resource not found'; |
||
| 98 | break; |
||
| 99 | case 500: //application |
||
| 100 | case 0: //default |
||
| 101 | default: |
||
| 102 | $statusCode = 500; |
||
| 103 | $title = 'The App made a boo boo'; |
||
| 104 | break; |
||
| 105 | } |
||
| 106 | |||
| 107 | $output = '<!doctype html> |
||
| 108 | <html> |
||
| 109 | <head> |
||
| 110 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||
| 111 | <title>Oups</title> |
||
| 112 | <style> |
||
| 113 | * {background: #f2dede; color: #a94442; overflow-wrap: break-word;} |
||
| 114 | .i {margin-left: auto; margin-right: auto; text-align: center; width: auto;} |
||
| 115 | small {font-size: 0.8em;} |
||
| 116 | </style> |
||
| 117 | </head> |
||
| 118 | <body><div class="i"><br>' . |
||
| 119 | "<h1>{$title}</h1>"; |
||
| 120 | if (Environment::ENV_PROD !== $this->config()->getEnv()) { |
||
| 121 | $output .= sprintf( |
||
| 122 | '<p><i>%s</i></p><p>%s:%s</p>', |
||
| 123 | $errorInfo['message'], |
||
| 124 | basename($errorInfo['file']), |
||
| 125 | $errorInfo['line'] |
||
| 126 | ); |
||
| 127 | if (!empty($errorInfo['trace'])) { |
||
| 128 | $output .= "<p>"; |
||
| 129 | $output .= "<small>"; |
||
| 130 | foreach ($errorInfo['trace'] as $item) { |
||
| 131 | if (!empty($item['class'])) { |
||
| 132 | $output .= sprintf( |
||
| 133 | '%s%s', |
||
| 134 | $item['class'], |
||
| 135 | $item['type'] |
||
| 136 | ); |
||
| 137 | $output .= ""; |
||
| 138 | } |
||
| 139 | if (!empty($item['function'])) { |
||
| 140 | $output .= sprintf( |
||
| 141 | '%s', |
||
| 142 | $item['function'] |
||
| 143 | ); |
||
| 144 | $output .= ""; |
||
| 145 | } |
||
| 146 | if (!empty($item['file'])) { |
||
| 147 | $output .= sprintf( |
||
| 148 | ' [%s:%s]', |
||
| 149 | basename($item['file']), |
||
| 150 | $item['line'] |
||
| 151 | ); |
||
| 152 | $output .= " "; |
||
| 153 | } |
||
| 154 | $output .= "<br>"; |
||
| 155 | } |
||
| 156 | $output .= "</small></p>"; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | $output .= '</div></body></html>'; |
||
| 160 | |||
| 161 | $response = new \WebServCo\Framework\HttpResponse( |
||
| 162 | $output, |
||
| 163 | $statusCode, |
||
| 164 | ['Content-Type' => 'text/html'] |
||
| 165 | ); |
||
| 166 | $response->send(); |
||
| 167 | return true; |
||
| 168 | } |
||
| 185 |