DbalStorageProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 3
dl 0
loc 40
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A storage() 0 6 1
A select() 0 8 2
1
<?php
2
3
namespace Mathielen\ImportEngine\Storage\Provider;
4
5
use Mathielen\ImportEngine\Storage\DbalStorage;
6
use Mathielen\ImportEngine\Storage\Provider\Connection\ConnectionFactoryInterface;
7
use Mathielen\ImportEngine\ValueObject\StorageSelection;
8
9
class DbalStorageProvider implements StorageProviderInterface
10
{
11
    /**
12
     * @var ConnectionFactoryInterface
13
     */
14
    private $connectionFactory;
15
16
    /**
17
     * @var \ArrayAccess
18
     */
19
    private $queries;
20
21
    public function __construct(ConnectionFactoryInterface $connectionFactory, \ArrayAccess $queries)
22
    {
23
        $this->connectionFactory = $connectionFactory;
24
        $this->queries = $queries;
25
    }
26
27
    /**
28
     * @return DbalStorage
29
     */
30
    public function storage(StorageSelection $selection)
31
    {
32
        $connection = $this->connectionFactory->getConnection($selection);
33
34
        return new DbalStorage($connection, $selection->getName(), $selection->getImpl());
35
    }
36
37
    /**
38
     * @return StorageSelection
39
     */
40
    public function select($id = null)
41
    {
42
        if (!$id) {
43
            throw new \InvalidArgumentException('id must not be empty');
44
        }
45
46
        return new StorageSelection($this->queries[$id], $id, $id);
47
    }
48
}
49