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

ConfigurationResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 36
ccs 6
cts 8
cp 0.75
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getConfiguration() 0 9 2
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
}