Passed
Push — master ( 6139d1...678a4c )
by Petr
13:22 queued 10:27
created

ConfigStorage   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 42
ccs 13
cts 15
cp 0.8667
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 6 2
A getInstance() 0 6 2
A addConfig() 0 3 1
A __construct() 0 2 1
A __clone() 0 2 1
1
<?php
2
3
namespace kalanis\kw_mapper\Storage\Database;
4
5
6
use kalanis\kw_mapper\MapperException;
7
8
9
/**
10
 * Class ConfigStorage
11
 * @package kalanis\kw_mapper\Storage\Database
12
 * Singleton to access configs across the mapper system
13
 */
14
class ConfigStorage
15
{
16
    /** @var self|null */
17
    protected static $instance = null;
18
    /** @var Config[] */
19
    private $configs = [];
20
21 63
    public static function getInstance(): self
22
    {
23 63
        if (empty(static::$instance)) {
24 1
            static::$instance = new self();
25
        }
26 63
        return static::$instance;
27
    }
28
29 1
    protected function __construct()
30
    {
31 1
    }
32
33
    /**
34
     * @codeCoverageIgnore why someone would run that?!
35
     */
36
    private function __clone()
37
    {
38
    }
39
40 61
    final public function addConfig(Config $config): void
41
    {
42 61
        $this->configs[$config->getSourceName()] = $config;
43 61
    }
44
45
    /**
46
     * @param string $sourceName
47
     * @throws MapperException
48
     * @return Config
49
     */
50 25
    final public function getConfig(string $sourceName): Config
51
    {
52 25
        if (empty($this->configs[$sourceName])) {
53 1
            throw new MapperException(sprintf('Unknown source *%s*', $sourceName));
54
        }
55 24
        return $this->configs[$sourceName];
56
    }
57
}
58