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

DefaultServiceContainerRegistry::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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