| Conditions | 13 |
| Paths | 240 |
| Total Lines | 43 |
| 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 |
||
| 53 | function create_uri_from_globals():Uri{ |
||
| 54 | $parts = []; |
||
| 55 | $hasPort = false; |
||
| 56 | $hasQuery = false; |
||
| 57 | |||
| 58 | $parts['scheme'] = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http'; |
||
| 59 | |||
| 60 | if(isset($_SERVER['HTTP_HOST'])){ |
||
| 61 | $hostHeaderParts = explode(':', $_SERVER['HTTP_HOST']); |
||
| 62 | $parts['host'] = $hostHeaderParts[0]; |
||
| 63 | |||
| 64 | if(isset($hostHeaderParts[1])){ |
||
| 65 | $hasPort = true; |
||
| 66 | $parts['port'] = $hostHeaderParts[1]; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | elseif(isset($_SERVER['SERVER_NAME'])){ |
||
| 70 | $parts['host'] = $_SERVER['SERVER_NAME']; |
||
| 71 | } |
||
| 72 | elseif(isset($_SERVER['SERVER_ADDR'])){ |
||
| 73 | $parts['host'] = $_SERVER['SERVER_ADDR']; |
||
| 74 | } |
||
| 75 | |||
| 76 | if(!$hasPort && isset($_SERVER['SERVER_PORT'])){ |
||
| 77 | $parts['port'] = $_SERVER['SERVER_PORT']; |
||
| 78 | } |
||
| 79 | |||
| 80 | if(isset($_SERVER['REQUEST_URI'])){ |
||
| 81 | $requestUriParts = explode('?', $_SERVER['REQUEST_URI']); |
||
| 82 | $parts['path'] = $requestUriParts[0]; |
||
| 83 | |||
| 84 | if(isset($requestUriParts[1])){ |
||
| 85 | $hasQuery = true; |
||
| 86 | $parts['query'] = $requestUriParts[1]; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | if(!$hasQuery && isset($_SERVER['QUERY_STRING'])){ |
||
| 91 | $parts['query'] = $_SERVER['QUERY_STRING']; |
||
| 92 | } |
||
| 93 | |||
| 94 | return Uri::fromParts($parts); |
||
| 95 | } |
||
| 96 | |||
| 152 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: