| Total Complexity | 5 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class ActionContainer implements ContainerInterface |
||
| 14 | { |
||
| 15 | /** @var array<callable> */ |
||
| 16 | private array $actions; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param array<callable> $actions |
||
| 20 | */ |
||
| 21 | 4 | public function __construct(array $actions) |
|
| 24 | 4 | } |
|
| 25 | |||
| 26 | 3 | public function get($id): callable |
|
| 27 | { |
||
| 28 | 3 | if (false === $this->has($id)) { |
|
| 29 | 1 | throw ActionNotFoundException::withId($id); |
|
| 30 | } |
||
| 31 | |||
| 32 | try { |
||
| 33 | 2 | $action = $this->actions[$id](); |
|
| 34 | 1 | } catch (Throwable $exception) { |
|
| 35 | 1 | throw ActionContainerException::withIdAndPreviousException($id, $exception); |
|
| 36 | } |
||
| 37 | |||
| 38 | 1 | return $action; |
|
| 39 | } |
||
| 40 | |||
| 41 | 3 | public function has($id): bool |
|
| 44 | } |
||
| 45 | } |
||
| 46 |