StorageRegistry::getStorage()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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