Completed
Push — master ( d6cfd6...378c5b )
by Markus
09:37 queued 06:34
created

DbalStorage::reader()   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 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Mathielen\ImportEngine\Storage;
4
5
use Mathielen\DataImport\Reader\DbalReader;
6
use Doctrine\DBAL\Connection;
7
use Mathielen\ImportEngine\Exception\InvalidConfigurationException;
8
9
class DbalStorage implements StorageInterface
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
     */
31
    public function getQuery()
32
    {
33
        return $this->query;
34
    }
35
36
    /**
37
     * @param null $query
38
     */
39
    public function setQuery($query)
40
    {
41
        $this->query = $query;
42
    }
43
44
    /**
45
     */
46
    public function getTableName()
47
    {
48
        return $this->tableName;
49
    }
50
51
    /**
52
     * @param null $tableName
53
     */
54
    public function setTableName($tableName)
55
    {
56
        $this->tableName = $tableName;
57
    }
58
59
    /**
60
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::writer().
61
     */
62
    public function writer()
63
    {
64
        if (empty($this->tableName)) {
65
            throw new InvalidConfigurationException('Can only use pdo for writing if tableName is given.');
66
        }
67
68
        //TODO implement me
69
70
        //return $writer;
71
    }
72
73
    /**
74
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::info().
75
     */
76
    public function info()
77
    {
78
        if (!$this->info) {
79
            $this->info = new StorageInfo(array(
80
                'name' => $this->query,
81
                'type' => 'SQL Query',
82
                'count' => count($this->reader()),
83
            ));
84
        }
85
86
        return $this->info;
87
    }
88
89
    /**
90
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::reader().
91
     */
92
    public function reader()
93
    {
94
        return new DbalReader($this->connection, $this->query);
95
    }
96
97
    /**
98
     * (non-PHPdoc) @see \Mathielen\ImportEngine\Storage\StorageInterface::getFields().
99
     */
100
    public function getFields()
101
    {
102
        return $this->reader()->getFields();
103
    }
104
}
105