Passed
Pull Request — master (#31)
by Sébastien
12:54 queued 06:01
created

ConfigurationResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 41
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addConfiguration() 0 3 1
A getConfiguration() 0 3 1
1
<?php
2
3
namespace Bdf\Prime\Connection\Configuration;
4
5
use Bdf\Prime\Configuration;
6
7
/**
8
 * Allows declaration of configuration custom by connection. Use a default connection if the configuration is not set.
9
 */
10
class ConfigurationResolver implements ConfigurationResolverInterface
11
{
12
    /**
13
     * @var Configuration[]
14
     */
15
    private $configurations;
16
17
    /**
18
     * @var Configuration|null
19
     */
20
    private $default;
21
22
    /**
23
     * ConfigurationResolver constructor.
24
     *
25
     * @param Configuration[] $configurations
26
     * @param Configuration|null $default
27
     */
28 207
    public function __construct(array $configurations = [], ?Configuration $default = null)
29
    {
30 207
        $this->configurations = $configurations;
31 207
        $this->default = $default;
32 207
    }
33
34
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $connectionName should have a doc-comment as per coding-style.
Loading history...
35
     * {@inheritDoc}
36
     */
37 171
    public function getConfiguration(string $connectionName): ?Configuration
38
    {
39 171
        return $this->configurations[$connectionName] ?? $this->default;
0 ignored issues
show
Coding Style introduced by
Operation must be bracketed
Loading history...
40
    }
41
42
    /**
43
     * Declare a configuration of a connection
44
     *
45
     * @param string $connectionName
46
     * @param Configuration $configuration
47
     */
48 2
    public function addConfiguration(string $connectionName, Configuration $configuration): void
49
    {
50 2
        $this->configurations[$connectionName] = $configuration;
51
    }
52
}