| Conditions | 9 |
| Paths | 97 |
| Total Lines | 55 |
| Code Lines | 26 |
| 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 |
||
| 72 | public static function urlParser($url) |
||
| 73 | { |
||
| 74 | |||
| 75 | $parseUrl = self::autoCorrectParseUrl($url); |
||
| 76 | |||
| 77 | // malformed URL, parse_url() returns false. Returns urls "as is". |
||
| 78 | if ($parseUrl === false) { |
||
| 79 | return array("url" => $url, "url_display" => $url); |
||
| 80 | } |
||
| 81 | |||
| 82 | $urlArray = array("url" => "", "url_display" => ""); |
||
| 83 | |||
| 84 | // Check if scheme is correct |
||
| 85 | if (!in_array($parseUrl["scheme"], array("http", "https", "gopher"))) { |
||
| 86 | $urlArray["url"] .= 'http'.'://'; |
||
| 87 | } else { |
||
| 88 | $urlArray["url"] .= $parseUrl["scheme"].'://'; |
||
| 89 | } |
||
| 90 | |||
| 91 | // Check if the right amount of "www" is set. |
||
| 92 | $explodeHost = explode(".", $parseUrl["host"]); |
||
| 93 | |||
| 94 | // Remove empty entries |
||
| 95 | $explodeHost = array_filter($explodeHost); |
||
| 96 | // And reassign indexes |
||
| 97 | $explodeHost = array_values($explodeHost); |
||
| 98 | |||
| 99 | // Contains subdomain |
||
| 100 | if (count($explodeHost) > 2) { |
||
| 101 | // Check if subdomain only contains the letter w(then not any other subdomain). |
||
| 102 | if (substr_count($explodeHost[0], 'w') == strlen($explodeHost[0])) { |
||
| 103 | // Replace with "www" to avoid "ww" or "wwww", etc. |
||
| 104 | $explodeHost[0] = "www"; |
||
| 105 | |||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | $urlArray["url"] .= implode(".", $explodeHost); |
||
| 110 | $urlArray["url_display"] = trim(implode(".", $explodeHost), '\/'); // Removes trailing slash |
||
| 111 | |||
| 112 | if (!empty($parseUrl["port"])) { |
||
| 113 | $urlArray["url"] .= ":".$parseUrl["port"]; |
||
| 114 | } |
||
| 115 | if (!empty($parseUrl["path"])) { |
||
| 116 | $urlArray["url"] .= $parseUrl["path"]; |
||
| 117 | } |
||
| 118 | if (!empty($parseUrl["query"])) { |
||
| 119 | $urlArray["url"] .= '?'.$parseUrl["query"]; |
||
| 120 | } |
||
| 121 | if (!empty($parseUrl["fragment"])) { |
||
| 122 | $urlArray["url"] .= '#'.$parseUrl["fragment"]; |
||
| 123 | } |
||
| 124 | |||
| 125 | return $urlArray; |
||
| 126 | } |
||
| 127 | |||
| 173 |
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.