| Conditions | 10 |
| Paths | 128 |
| Total Lines | 27 |
| Code Lines | 15 |
| 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 |
||
| 18 | public static function createFromServer($serv) |
||
| 19 | { |
||
| 20 | $scheme = isset($serv['HTTPS']) ? 'https://' : 'http://'; |
||
| 21 | $host = !empty($serv['HTTP_HOST']) ? $serv['HTTP_HOST'] : $serv['SERVER_NAME']; |
||
| 22 | $port = empty($serv['SERVER_PORT']) ? $serv['SERVER_PORT'] : null; |
||
| 23 | |||
| 24 | //Path |
||
| 25 | $scriptName = parse_url($serv['SCRIPT_NAME'], PHP_URL_PATH); |
||
| 26 | $scriptPath = dirname($scriptName); |
||
|
|
|||
| 27 | |||
| 28 | $path = (string) parse_url('http://www.example.com/' . $serv['REQUEST_URI'], PHP_URL_PATH); |
||
| 29 | |||
| 30 | $query = empty($serv['QUERY_STRING']) ? parse_url('http://example.com' . $serv['REQUEST_URI'], PHP_URL_QUERY) : $serv['QUERY_STRING']; |
||
| 31 | |||
| 32 | $fragment = ''; |
||
| 33 | |||
| 34 | $user = !empty($serv['PHP_AUTH_USER']) ? $serv['PHP_AUTH_USER'] : ''; |
||
| 35 | $password = !empty($serv['PHP_AUTH_PW']) ? $serv['PHP_AUTH_PW'] : ''; |
||
| 36 | |||
| 37 | if (empty($user) && empty($password) && !empty($serv['HTTP_AUTHORIZATION'])) { |
||
| 38 | list($user, $password) = explode(':', base64_decode(substr($serv['HTTP_AUTHORIZATION'], 6))); |
||
| 39 | } |
||
| 40 | |||
| 41 | $uri = new UriItem($scheme, $host, $port, $path, $query, $fragment, $user, $password); |
||
| 42 | |||
| 43 | return $uri; |
||
| 44 | } |
||
| 45 | |||
| 70 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.