Completed
Push — master ( 0fb3d7...53ff75 )
by Markus
03:02
created

DbalStorageProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

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
namespace Mathielen\ImportEngine\Storage\Provider;
3
4
use Mathielen\ImportEngine\Storage\DbalStorage;
5
use Mathielen\ImportEngine\Storage\Provider\Connection\ConnectionFactoryInterface;
6
use Mathielen\ImportEngine\ValueObject\StorageSelection;
7
8
class DbalStorageProvider implements StorageProviderInterface
9
{
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
}
50