Test Failed
Pull Request — master (#31)
by Sébastien
07:15
created

ConfigurationResolver::getConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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
    public function __construct(array $configurations = [], ?Configuration $default = null)
29
    {
30
        $this->configurations = $configurations;
31
        $this->default = $default;
32
    }
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
    public function getConfiguration(string $connectionName): ?Configuration
38
    {
39
        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
    public function addConfiguration(string $connectionName, Configuration $configuration): void
49
    {
50
        $this->configurations[$connectionName] = $configuration;
51
    }
52
}