Passed
Push — master ( eda472...81f3e1 )
by Tomáš
11:58
created

DefaultServiceContainerRegistry   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 21
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 5 1
A add() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Service\Registry;
6
7
use Inspirum\Balikobot\Exception\ServiceContainerNotFoundException;
8
use function array_keys;
9
10
final class DefaultServiceContainerRegistry implements ServiceContainerRegistry
11
{
12
    /**
13
     * @param array<string, \Inspirum\Balikobot\Service\Registry\ServiceContainer> $containers
14
     */
15 5
    public function __construct(
16
        private array $containers = [],
17
        private string $defaultConnectionName = 'default',
18
    ) {
19 5
    }
20
21 1
    public function add(string $connection, ServiceContainer $container): void
22
    {
23 1
        $this->containers[$connection] = $container;
24
    }
25
26 5
    public function get(?string $connection = null): ServiceContainer
27
    {
28 5
        $connection ??= $this->defaultConnectionName;
29
30 5
        return $this->containers[$connection] ?? throw new ServiceContainerNotFoundException($connection, array_keys($this->containers));
31
    }
32
}
33