| Total Complexity | 5 |
| Total Lines | 24 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class Uri implements Stringable |
||
| 9 | { |
||
| 10 | private readonly string $uri; |
||
| 11 | |||
| 12 | 15 | public function __construct(mixed $value) |
|
| 13 | { |
||
| 14 | 15 | if (\is_array($value)) { |
|
| 15 | 4 | if (!isset($value['base'])) { |
|
| 16 | 1 | throw new InvalidArgumentException( |
|
| 17 | 1 | 'If you want to build an URI from an array, use the schema: [ base => string, ?parameters => [string => mixed]' |
|
| 18 | 1 | ); |
|
| 19 | } |
||
| 20 | |||
| 21 | 3 | $parameters = $value['parameters'] ?? []; |
|
| 22 | 3 | $value = str_replace(array_keys($parameters), $parameters, (string) $value['base']); |
|
| 23 | 11 | } elseif (!\is_string($value)) { |
|
| 24 | 4 | throw new InvalidArgumentException('$value must be a string or an array.'); |
|
| 25 | } |
||
| 26 | 10 | $this->uri = $value; |
|
|
|
|||
| 27 | } |
||
| 28 | |||
| 29 | 10 | public function __toString(): string |
|
| 32 | } |
||
| 33 | } |
||
| 34 |