Passed
Pull Request — master (#3)
by Vincent
08:42
created

ConfigurationResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Bdf\PrimeBundle\Connection;
4
5
use Bdf\Prime\Configuration;
6
use Bdf\Prime\Connection\Configuration\ConfigurationResolverInterface;
7
use Psr\Container\ContainerExceptionInterface;
8
use Psr\Container\ContainerInterface;
9
10
/**
11
 * Allows declaration of configuration custom by connection. Use a default connection if the configuration is not set.
12
 */
13
class ConfigurationResolver implements ConfigurationResolverInterface
14
{
15
    /**
16
     * @var ContainerInterface
17
     */
18
    private $container;
19
20
    /**
21
     * @var string
22
     */
23
    private $id;
24
25
    /**
26
     * ConfigurationResolver constructor.
27
     *
28
     * @param ContainerInterface $container
29
     * @param string $id
30
     */
31 10
    public function __construct(ContainerInterface $container, string $id = 'prime.%s_connection.configuration')
32
    {
33 10
        $this->container = $container;
34 10
        $this->id = $id;
35 10
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40 8
    public function getConfiguration(string $connectionName): ?Configuration
41
    {
42
        try {
43 8
            return $this->container->get(sprintf($this->id, $connectionName));
44
        } catch (ContainerExceptionInterface $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
45
46
        }
47
48
        return null;
49
    }
50
}