Completed
Push — master ( 7a6bdd...324ce1 )
by Sébastien
09:34
created

MasterSlaveConnectionFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 41
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A support() 0 3 1
A create() 0 11 1
A __construct() 0 3 1
1
<?php
2
3
namespace Bdf\Prime\Connection\Factory;
4
5
use Bdf\Prime\Connection\ConnectionInterface;
6
use Bdf\Prime\Connection\MasterSlaveConnection;
7
use Doctrine\DBAL\Configuration;
8
9
/**
10
 * MasterSlaveConnectionLoader
11
 */
12
class MasterSlaveConnectionFactory implements ConnectionFactoryInterface
13
{
14
    /**
15
     * The delegated connectionFactory
16
     *
17
     * @var ConnectionFactoryInterface
18
     */
19
    private $connectionFactory;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
20
21
    /**
22
     * Set default configuration
23
     *
24
     * @param ConnectionFactoryInterface $connectionFactory
25
     */
26 80
    public function __construct(ConnectionFactoryInterface $connectionFactory)
27
    {
28 80
        $this->connectionFactory = $connectionFactory;
29 80
    }
30
31
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $connectionName should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $parameters should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $config should have a doc-comment as per coding-style.
Loading history...
32
     * {@inheritDoc}
33
     */
34 8
    public function create(string $connectionName, array $parameters, Configuration $config): ConnectionInterface
35
    {
36 8
        $masterParameters = $parameters;
37 8
        unset($masterParameters['read']);
38 8
        unset($masterParameters['wrapperClass']);
39 8
        $readParameters = array_merge($masterParameters, $parameters['read']);
40
41 8
        $parameters['read'] = $this->connectionFactory->create($connectionName.'.read', $readParameters, $config);
42 8
        $parameters['wrapperClass'] = $parameters['wrapperClass'] ?? MasterSlaveConnection::class;
0 ignored issues
show
Coding Style introduced by
Operation must be bracketed
Loading history...
43
44 8
        return $this->connectionFactory->create($connectionName, $parameters, $config);
45
    }
46
47
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $connectionName should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $parameters should have a doc-comment as per coding-style.
Loading history...
48
     * {@inheritDoc}
49
     */
50 77
    public function support(string $connectionName, array $parameters): bool
0 ignored issues
show
Coding Style introduced by
The method parameter $connectionName is never used
Loading history...
51
    {
52 77
        return isset($parameters['read']);
53
    }
54
}
55