| Conditions | 3 |
| Paths | 3 |
| Total Lines | 28 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | public function parse(string $url): ParsedURL { |
||
| 16 | $splitURL = explode('/', trim($url, '/')); |
||
| 17 | if(count($splitURL) < 3){ |
||
| 18 | throw new InvalidRequestURLException(); |
||
| 19 | } |
||
| 20 | //Find endpoint |
||
| 21 | $version = $splitURL[0]; |
||
| 22 | $apiKey = $splitURL[1]; |
||
| 23 | $endpoint = $splitURL[2]; |
||
| 24 | |||
| 25 | $splitExtension = explode('.', $splitURL[count($splitURL) - 1]); |
||
| 26 | $extension = array_pop($splitExtension); |
||
| 27 | |||
| 28 | $instance = null; |
||
| 29 | |||
| 30 | if(count($splitURL) == 4){ |
||
| 31 | $instance = implode('.', $splitExtension); |
||
| 32 | } else { |
||
| 33 | $endpoint = implode('.', $splitExtension); |
||
| 34 | } |
||
| 35 | |||
| 36 | $splitOnQuery = explode('?', $url); |
||
| 37 | $queryString = $splitOnQuery[1] ?? ''; |
||
| 38 | |||
| 39 | $requestData = new URLEncodedQueryStringRequestData($queryString); |
||
| 40 | |||
| 41 | return new ParsedURL($requestData, $version, $apiKey, $endpoint, $extension, $instance); |
||
| 42 | } |
||
| 43 | } |
||
| 44 |