| Conditions | 8 |
| Paths | 3 |
| Total Lines | 57 |
| Code Lines | 32 |
| 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 |
||
| 29 | protected function getHttpOutput(\Throwable $throwable): string |
||
| 30 | { |
||
| 31 | $output = '<!doctype html> |
||
| 32 | <html> |
||
| 33 | <head> |
||
| 34 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||
| 35 | <title>Oops</title> |
||
| 36 | <style> |
||
| 37 | * {background: #f2dede; color: #a94442; overflow-wrap: break-word;} |
||
| 38 | .i {margin-left: auto; margin-right: auto; text-align: center; width: auto;} |
||
| 39 | small {font-size: 0.8em;} |
||
| 40 | </style> |
||
| 41 | </head> |
||
| 42 | <body><div class="i"><br>'; |
||
| 43 | $output .= \sprintf('<h1>%s</h1>', 404 === $throwable->getCode() ? 'Resource not found' : 'Boo boo'); |
||
| 44 | |||
| 45 | if ( |
||
| 46 | \WebServCo\Framework\Environment\Value::DEVELOPMENT |
||
| 47 | === \WebServCo\Framework\Environment\Config::string('APP_ENVIRONMENT') |
||
| 48 | ) { |
||
| 49 | $output .= \sprintf( |
||
| 50 | '<p><i>%s</i></p><p>%s:%s</p>', |
||
| 51 | $throwable->getMessage(), |
||
| 52 | $throwable->getFile(), |
||
| 53 | $throwable->getLine(), |
||
| 54 | ); |
||
| 55 | $trace = $throwable->getTrace(); |
||
| 56 | if (!empty($trace)) { |
||
| 57 | $output .= "<p>"; |
||
| 58 | $output .= "<small>"; |
||
| 59 | foreach ($trace as $item) { |
||
| 60 | if (!empty($item['class'])) { |
||
| 61 | $output .= \sprintf('%s%s', $item['class'], $item['type']); |
||
| 62 | $output .= ""; |
||
| 63 | } |
||
| 64 | if (!empty($item['function'])) { |
||
| 65 | $output .= \sprintf('%s', $item['function']); |
||
| 66 | $output .= ""; |
||
| 67 | } |
||
| 68 | if (!empty($item['file'])) { |
||
| 69 | $output .= \sprintf( |
||
| 70 | ' [%s:%s]', |
||
| 71 | \basename($item['file']), |
||
| 72 | $item['line'], |
||
| 73 | ); |
||
| 74 | $output .= " "; |
||
| 75 | } |
||
| 76 | $output .= "<br>"; |
||
| 77 | } |
||
| 78 | $output .= "</small></p>"; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | $output .= '</div></body>'; |
||
| 83 | $output .= '</html>'; |
||
| 84 | |||
| 85 | return $output; |
||
| 86 | } |
||
| 96 |