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

ChainFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 10
cc 3
nc 3
nop 3
crap 3.072
1
<?php
2
3
namespace Bdf\Prime\Connection\Factory;
4
5
use Bdf\Prime\Connection\ConnectionInterface;
6
use Doctrine\DBAL\Configuration;
7
8
/**
9
 * ChainFactory
10
 */
11
class ChainFactory implements ConnectionFactoryInterface
12
{
13
    /**
14
     * The connection factories
15
     *
16
     * @var ConnectionFactoryInterface[]
17
     */
18
    private $factories;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
19
20 72
    public function __construct(array $connectionFactories)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
introduced by
Missing function doc comment
Loading history...
21
    {
22 72
        $this->factories = $connectionFactories;
23 72
    }
24
25
    /**
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...
26
     * {@inheritDoc}
27
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @throws tag in function comment
Loading history...
28 76
    public function create(string $connectionName, array $parameters, Configuration $config): ConnectionInterface
29
    {
30 76
        foreach ($this->factories as $connectionFactory) {
31 76
            if ($connectionFactory->support($connectionName, $parameters)) {
32 76
                return $connectionFactory->create($connectionName, $parameters, $config);
33
            }
34
        }
35
36
        throw new \LogicException('No handlers found to create the connection '.$connectionName);
37
    }
38
39
    /**
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...
40
     * {@inheritDoc}
41
     */
42
    public function support(string $connectionName, array $parameters): bool
43
    {
44
        return true;
45
    }
46
}
47