| Conditions | 12 |
| Paths | 66 |
| Total Lines | 31 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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 |
||
| 21 | public static function normalizeUrl(string $url) |
||
| 22 | { |
||
| 23 | $encodedUrl = preg_replace_callback( |
||
| 24 | '%[^:/@?&=#]+%usD', |
||
| 25 | function ($matches) { |
||
| 26 | return urlencode($matches[0]); |
||
| 27 | }, |
||
| 28 | $url |
||
| 29 | ); |
||
| 30 | |||
| 31 | $url = parse_url($encodedUrl); |
||
| 32 | |||
| 33 | if (empty($url) || !isset($url['host'])) { |
||
| 34 | return false; |
||
| 35 | } |
||
| 36 | |||
| 37 | $url = array_map('urldecode', $url); |
||
| 38 | $url['host'] = idn_to_ascii($url['host'], IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); |
||
| 39 | |||
| 40 | if (empty($url['scheme']) || !is_string($url['host']) || !self::checkDomain($url['host'])) { |
||
| 41 | return false; |
||
| 42 | } |
||
| 43 | |||
| 44 | return |
||
| 45 | $url['scheme'] . '://' |
||
| 46 | . (isset($url['user']) ? $url['user'] . ((isset($url['pass'])) ? ':' . $url['pass'] : '') . '@' : '') |
||
| 47 | . $url['host'] |
||
| 48 | . ((isset($url['port'])) ? ':' . $url['port'] : '') |
||
| 49 | . ((isset($url['path'])) ? $url['path'] : '') |
||
| 50 | . ((isset($url['query'])) ? '?' . $url['query'] : '') |
||
| 51 | . ((isset($url['fragment'])) ? '#' . $url['fragment'] : ''); |
||
| 52 | } |
||
| 66 |