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

DbalStorageProvider::select()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
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