| Conditions | 2 |
| Paths | 2 |
| Total Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | 2 | public function parseUrl(string $url): string |
|
| 30 | { |
||
| 31 | // Separates the url parts |
||
| 32 | 2 | $link = parse_url($url); |
|
| 33 | // Parses the parameters of the url query |
||
| 34 | 2 | parse_str($link['query'], $link); |
|
| 35 | |||
| 36 | 2 | $url = filter_var($link['q'], FILTER_VALIDATE_URL); |
|
| 37 | // If this is not a valid URL, so the result is (probably) an image, news or video suggestion |
||
| 38 | 2 | if (!$url) { |
|
| 39 | 1 | throw new InvalidResultException(); |
|
| 40 | } |
||
| 41 | |||
| 42 | 1 | return $url; |
|
| 43 | } |
||
| 44 | } |
||
| 45 |