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

DbalStorage::getFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
namespace Mathielen\ImportEngine\Storage;
3
4
use Ddeboer\DataImport\Reader\DbalReader;
5
use Doctrine\DBAL\Connection;
6
use Mathielen\ImportEngine\Exception\InvalidConfigurationException;
7
8
class DbalStorage implements StorageInterface
9
{
10
11
    /**
12
     * @var Connection
13
     */
14
    private $connection;
15
16
    private $tableName;
17
18
    private $query;
19
20
    private $info;
21
22
    public function __construct(Connection $connection, $tableName=null, $query=null)
23
    {
24
        $this->connection = $connection;
25
        $this->tableName = $tableName;
26
        $this->query = $query;
27
    }
28
29
    /**
30
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::writer()
31
     */
32
    public function writer()
33
    {
34
        if (empty($this->tableName)) {
35
            throw new InvalidConfigurationException("Can only use pdo for writing if tableName is given.");
36
        }
37
38
        //TODO implement me
39
40
        //return $writer;
41
    }
42
43
    /**
44
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::info()
45
     */
46
    public function info()
47
    {
48
        if (!$this->info) {
49
            $this->info = new StorageInfo(array(
50
                'name' => $this->query,
51
                'type' => 'SQL Query',
52
                'count' => count($this->reader())
53
            ));
54
        }
55
56
        return $this->info;
57
    }
58
59
    /**
60
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::reader()
61
     */
62
    public function reader()
63
    {
64
        return new DbalReader($this->connection, $this->query);
65
    }
66
67
    /**
68
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::getFields()
69
     */
70
    public function getFields()
71
    {
72
        return $this->reader()->getFields();
73
    }
74
}
75