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

CollectorRegistry::getCollector()   A

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 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Lamoda\Metric\Collector;
4
5
/**
6
 * @internal
7
 */
8
final class CollectorRegistry
9
{
10
    /** @var MetricCollectorInterface[] */
11
    private $collectors = [];
12
13
    /**
14
     * Add collector to registry.
15
     *
16
     * @param string                   $name
17
     * @param MetricCollectorInterface $collector
18
     */
19 1
    public function register(string $name, MetricCollectorInterface $collector): void
20
    {
21 1
        $this->collectors[$name] = $collector;
22 1
    }
23
24
    /**
25
     * Fetch collector from registry.
26
     *
27
     * @param string $name
28
     *
29
     * @return MetricCollectorInterface
30
     *
31
     * @throws \OutOfBoundsException
32
     */
33 2
    public function getCollector(string $name): MetricCollectorInterface
34
    {
35 2
        if (!array_key_exists($name, $this->collectors)) {
36 1
            throw new \OutOfBoundsException('Unknown collector in registry: ' . $name);
37
        }
38
39 1
        return $this->collectors[$name];
40
    }
41
}
42