| Conditions | 9 |
| Paths | 97 |
| Total Lines | 55 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 81 | public static function urlParser($url) { |
||
| 82 | |||
| 83 | $parseUrl = self::autoCorrectParseUrl($url); |
||
| 84 | |||
| 85 | // malformed URL, parse_url() returns false. Returns urls "as is". |
||
| 86 | if($parseUrl === false) { |
||
| 87 | return array("url" => $url, "url_display" => $url); |
||
| 88 | } |
||
| 89 | |||
| 90 | $urlArray = array("url" => "", "url_display" => ""); |
||
| 91 | |||
| 92 | // Check if scheme is correct |
||
| 93 | if(!in_array($parseUrl["scheme"], array("http", "https", "gopher"))) { |
||
| 94 | $urlArray["url"] .= 'http'.'://'; |
||
| 95 | } else { |
||
| 96 | $urlArray["url"] .= $parseUrl["scheme"].'://'; |
||
| 97 | } |
||
| 98 | |||
| 99 | // Check if the right amount of "www" is set. |
||
| 100 | $explodeHost = explode(".", $parseUrl["host"]); |
||
| 101 | |||
| 102 | // Remove empty entries |
||
| 103 | $explodeHost = array_filter($explodeHost); |
||
| 104 | // And reassign indexes |
||
| 105 | $explodeHost = array_values($explodeHost); |
||
| 106 | |||
| 107 | // Contains subdomain |
||
| 108 | if(count($explodeHost) > 2) { |
||
| 109 | // Check if subdomain only contains the letter w(then not any other subdomain). |
||
| 110 | if(substr_count($explodeHost[0], 'w') == strlen($explodeHost[0])) { |
||
| 111 | // Replace with "www" to avoid "ww" or "wwww", etc. |
||
| 112 | $explodeHost[0] = "www"; |
||
| 113 | |||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | $urlArray["url"] .= implode(".",$explodeHost); |
||
| 118 | $urlArray["url_display"] = trim(implode(".",$explodeHost), '\/'); // Removes trailing slash |
||
| 119 | |||
| 120 | if(!empty($parseUrl["port"])) { |
||
| 121 | $urlArray["url"] .= ":".$parseUrl["port"]; |
||
| 122 | } |
||
| 123 | if(!empty($parseUrl["path"])) { |
||
| 124 | $urlArray["url"] .= $parseUrl["path"]; |
||
| 125 | } |
||
| 126 | if(!empty($parseUrl["query"])) { |
||
| 127 | $urlArray["url"] .= '?'.$parseUrl["query"]; |
||
| 128 | } |
||
| 129 | if(!empty($parseUrl["fragment"])) { |
||
| 130 | $urlArray["url"] .= '#'.$parseUrl["fragment"]; |
||
| 131 | } |
||
| 132 | |||
| 133 | |||
| 134 | return $urlArray; |
||
| 135 | } |
||
| 136 | |||
| 171 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.