| Total Complexity | 10 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 94.12% |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | final class CompositeContainer implements ContainerInterface |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Containers to look into starting from the beginning of the array. |
||
| 18 | * @var ContainerInterface[] The list of containers |
||
| 19 | */ |
||
| 20 | private array $containers = []; |
||
| 21 | |||
| 22 | 25 | public function get($id) |
|
| 23 | { |
||
| 24 | 25 | foreach ($this->containers as $container) { |
|
| 25 | 25 | if ($container->has($id)) { |
|
| 26 | 22 | return $container->get($id); |
|
| 27 | } |
||
| 28 | } |
||
| 29 | 5 | throw new NotFoundException("No definition for $id"); |
|
| 30 | } |
||
| 31 | |||
| 32 | 9 | public function has($id): bool |
|
| 33 | { |
||
| 34 | 9 | foreach ($this->containers as $container) { |
|
| 35 | 9 | if ($container->has($id)) { |
|
| 36 | 9 | return true; |
|
| 37 | } |
||
| 38 | } |
||
| 39 | return false; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Attaches a container to the composite container. |
||
| 44 | * @param ContainerInterface $container |
||
| 45 | */ |
||
| 46 | 27 | public function attach(ContainerInterface $container): void |
|
| 49 | 27 | } |
|
| 50 | |||
| 51 | /** |
||
| 52 | * Removes a container from the list of containers. |
||
| 53 | * @param ContainerInterface $container |
||
| 54 | */ |
||
| 55 | 2 | public function detach(ContainerInterface $container): void |
|
| 60 | } |
||
| 61 | } |
||
| 64 |