Completed
Push — master ( 53ff75...252438 )
by Markus
04:10
created

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