| Total Complexity | 7 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | final class RouteArgsResolver |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var callable[] |
||
| 13 | */ |
||
| 14 | private $resolvers = []; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param RouteArgsResolverInterface $routeArgsResolver |
||
| 18 | * |
||
| 19 | * @return RouteArgsResolver |
||
| 20 | * |
||
| 21 | * @throws RouteArgsResolverException |
||
| 22 | */ |
||
| 23 | 7 | public function add(RouteArgsResolverInterface $routeArgsResolver): self |
|
| 24 | { |
||
| 25 | 7 | $keys = $routeArgsResolver->getArgsResolver(); |
|
| 26 | 7 | foreach ($keys as $key => $callable) { |
|
| 27 | 7 | $this->isValid($key, $callable); |
|
| 28 | 6 | $this->resolvers[$key] = $callable; |
|
| 29 | } |
||
| 30 | 6 | return $this; |
|
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param string $key |
||
| 35 | * @param string $value |
||
| 36 | * |
||
| 37 | * @return mixed |
||
| 38 | */ |
||
| 39 | 3 | public function resolve(string $key, string $value) |
|
| 40 | { |
||
| 41 | 3 | return $this->resolvers[$key]($value); |
|
| 42 | } |
||
| 43 | |||
| 44 | 3 | public function has(string $key): bool |
|
| 45 | { |
||
| 46 | 3 | return isset($this->resolvers[$key]); |
|
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param string $key |
||
| 51 | * @param mixed $callable |
||
| 52 | * |
||
| 53 | * @throws RouteArgsResolverException |
||
| 54 | */ |
||
| 55 | 7 | private function isValid(string $key, $callable): void |
|
| 63 | } |
||
| 64 | 6 | } |
|
| 65 | } |
||
| 66 |