Conditions | 10 |
Paths | 12 |
Total Lines | 76 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
64 | protected function haltHttp($errorInfo = []) |
||
65 | { |
||
66 | switch ($errorInfo['code']) { |
||
67 | case 404: |
||
68 | $statusCode = 404; //not found |
||
69 | $title = 'Resource not found'; |
||
70 | break; |
||
71 | case 500: //application |
||
72 | case 0: //default |
||
73 | default: |
||
74 | $statusCode = 500; |
||
75 | $title = 'Boo boo'; |
||
76 | break; |
||
77 | } |
||
78 | |||
79 | $output = '<!doctype html> |
||
80 | <html> |
||
81 | <head> |
||
82 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||
83 | <title>Oups</title> |
||
84 | <style> |
||
85 | * {background: #f2dede; color: #a94442; overflow-wrap: break-word;} |
||
86 | .i {margin-left: auto; margin-right: auto; text-align: center; width: auto;} |
||
87 | small {font-size: 0.8em;} |
||
88 | </style> |
||
89 | </head> |
||
90 | <body><div class="i"><br>' . |
||
91 | "<h1>{$title}</h1>"; |
||
92 | if (Environment::ENV_DEV == $this->config()->getEnv()) { |
||
93 | $output .= sprintf( |
||
94 | '<p><i>%s</i></p><p>%s:%s</p>', |
||
95 | $errorInfo['message'], |
||
96 | basename($errorInfo['file']), |
||
97 | $errorInfo['line'] |
||
98 | ); |
||
99 | if (!empty($errorInfo['trace'])) { |
||
100 | $output .= "<p>"; |
||
101 | $output .= "<small>"; |
||
102 | foreach ($errorInfo['trace'] as $item) { |
||
103 | if (!empty($item['class'])) { |
||
104 | $output .= sprintf( |
||
105 | '%s%s', |
||
106 | $item['class'], |
||
107 | $item['type'] |
||
108 | ); |
||
109 | $output .= ""; |
||
110 | } |
||
111 | if (!empty($item['function'])) { |
||
112 | $output .= sprintf( |
||
113 | '%s', |
||
114 | $item['function'] |
||
115 | ); |
||
116 | $output .= ""; |
||
117 | } |
||
118 | if (!empty($item['file'])) { |
||
119 | $output .= sprintf( |
||
120 | ' [%s:%s]', |
||
121 | basename($item['file']), |
||
122 | $item['line'] |
||
123 | ); |
||
124 | $output .= " "; |
||
125 | } |
||
126 | $output .= "<br>"; |
||
127 | } |
||
128 | $output .= "</small></p>"; |
||
129 | } |
||
130 | } |
||
131 | $output .= '</div></body></html>'; |
||
132 | |||
133 | $response = new \WebServCo\Framework\Http\Response( |
||
134 | $output, |
||
135 | $statusCode, |
||
136 | ['Content-Type' => 'text/html'] |
||
137 | ); |
||
138 | $response->send(); |
||
139 | return true; |
||
140 | } |
||
155 |