Passed
Pull Request — master (#5)
by Pavel
05:52
created

StorageRegistry::register()   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 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Lamoda\Metric\Storage;
4
5
/**
6
 * @internal
7
 */
8
final class StorageRegistry
9
{
10
    /** @var array MetricStorageInterface[] */
11
    private $storages = [];
12
13 1
    public function register(string $name, MetricStorageInterface $storage): void
14
    {
15 1
        $this->storages[$name] = $storage;
16 1
    }
17
18
    /**
19
     * @param string $name
20
     *
21
     * @return MetricStorageInterface
22
     *
23
     * @throws \OutOfBoundsException
24
     */
25 2
    public function getStorage(string $name): MetricStorageInterface
26
    {
27 2
        if (!array_key_exists($name, $this->storages)) {
28 1
            throw new \OutOfBoundsException('Unknown storage in registry: ' . $name);
29
        }
30
31 1
        return $this->storages[$name];
32
    }
33
}
34