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

CollectorRegistry   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 32
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCollector() 0 7 2
A register() 0 3 1
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