| Conditions | 10 |
| Paths | 128 |
| Total Lines | 25 |
| 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 |
||
| 40 | function createuriFromServer() |
||
| 41 | { |
||
| 42 | $scheme = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
||
| 43 | $host = !empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']; |
||
| 44 | $port = empty($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : null; |
||
| 45 | $path = (string) parse_url('http://www.example.com/' . $_SERVER['REQUEST_URI'], PHP_URL_PATH); |
||
| 46 | $query = empty($_SERVER['QUERY_STRING']) ? parse_url('http://example.com' . $_SERVER['REQUEST_URI'], PHP_URL_QUERY) : $_SERVER['QUERY_STRING']; |
||
| 47 | $fragment = ''; |
||
| 48 | $user = !empty($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : ''; |
||
| 49 | $password = !empty($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : ''; |
||
| 50 | if (empty($user) && empty($password) && !empty($_SERVER['HTTP_AUTHORIZATION'])) { |
||
| 51 | list($user, $password) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6))); |
||
| 52 | } |
||
| 53 | |||
| 54 | return new Uri( |
||
| 55 | $scheme, |
||
| 56 | $host, |
||
| 57 | $port, |
||
| 58 | $path, |
||
| 59 | $query, |
||
| 60 | $fragment, |
||
| 61 | $user, |
||
| 62 | $password |
||
| 63 | ); |
||
| 64 | } |
||
| 65 |