ConfigurationResolver::getConfiguration()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
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
eloc 4
nc 2
nop 1
dl 0
loc 8
c 1
b 0
f 0
cc 2
rs 10
ccs 2
cts 4
cp 0.5
crap 2.5
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 12
    public function __construct(ContainerInterface $container, string $id = 'prime.%s_connection.configuration')
29
    {
30 12
        $this->container = $container;
31 12
        $this->id = $id;
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37 10
    public function getConfiguration(string $connectionName): ?Configuration
38
    {
39
        try {
40 10
            return $this->container->get(sprintf($this->id, $connectionName));
41
        } catch (ContainerExceptionInterface $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
42
        }
43
44
        return null;
45
    }
46
}
47