| Conditions | 10 |
| Paths | 128 |
| Total Lines | 23 |
| Code Lines | 13 |
| 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 |
||
| 17 | public static function createFromServer ($serv) |
||
| 18 | { |
||
| 19 | $scheme = isset($serv['HTTPS']) ? 'https://' : 'http://'; |
||
| 20 | $host = !empty($serv['HTTP_HOST']) ? $serv['HTTP_HOST'] : $serv['SERVER_NAME']; |
||
| 21 | $port = empty($serv['SERVER_PORT']) ? $serv['SERVER_PORT'] : null; |
||
| 22 | |||
| 23 | $path = (string) parse_url('http://www.example.com/' . $serv['REQUEST_URI'], PHP_URL_PATH); |
||
| 24 | |||
| 25 | $query = empty($serv['QUERY_STRING']) ? parse_url('http://example.com' . $serv['REQUEST_URI'], PHP_URL_QUERY) : $serv['QUERY_STRING']; |
||
| 26 | |||
| 27 | $fragment = ''; |
||
| 28 | |||
| 29 | $user = !empty($serv['PHP_AUTH_USER']) ? $serv['PHP_AUTH_USER'] : ''; |
||
| 30 | $password = !empty($serv['PHP_AUTH_PW']) ? $serv['PHP_AUTH_PW'] : ''; |
||
| 31 | |||
| 32 | if (empty($user) && empty($password) && !empty($serv['HTTP_AUTHORIZATION'])) { |
||
| 33 | list($user, $password) = explode(':', base64_decode(substr($serv['HTTP_AUTHORIZATION'], 6))); |
||
| 34 | } |
||
| 35 | |||
| 36 | $uri = new \Resilient\Http\Uri($scheme, $host, $port, $path, $query, $fragment, $user, $password); |
||
| 37 | |||
| 38 | return $uri; |
||
| 39 | } |
||
| 40 | |||
| 65 |