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

ConfigurationResolver::getConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 2
cts 4
cp 0.5
crap 2.5
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
}