| Conditions | 5 |
| Paths | 9 |
| Total Lines | 31 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 34 | public static function toRoute(array $route): string |
||
| 35 | { |
||
| 36 | if (empty($route)) { |
||
| 37 | throw new InvalidArgumentException('The given route is empty'); |
||
| 38 | } |
||
| 39 | |||
| 40 | $urlParts = [$_SERVER['SCRIPT_NAME']]; |
||
| 41 | |||
| 42 | $r = trim(array_shift($route), '/'); |
||
| 43 | if (!empty($r)) { |
||
| 44 | $urlParts[] = '/'; |
||
| 45 | $urlParts[] = $r; |
||
| 46 | } |
||
| 47 | |||
| 48 | $anchor = []; |
||
| 49 | if (isset($route['#'])) { |
||
| 50 | $anchor[] = '#'; |
||
| 51 | $anchor[] = $route['#']; |
||
| 52 | unset($route['#']); |
||
| 53 | } |
||
| 54 | |||
| 55 | if (!empty($route)) { |
||
| 56 | $query = http_build_query($route); |
||
| 57 | $urlParts[] = '?'; |
||
| 58 | $urlParts[] = $query; |
||
| 59 | } |
||
| 60 | |||
| 61 | $urlParts = array_merge($urlParts, $anchor); |
||
| 62 | |||
| 63 | $url = implode('', $urlParts); |
||
| 64 | return $url; |
||
| 65 | } |
||
| 67 |