Statement   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 74
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fetchField() 0 6 1
A fetchAssoc() 0 3 1
A fetchRow() 0 3 1
A rowCount() 0 10 2
A __destruct() 0 3 1
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver\Sqlite\Db\Sqlite;
4
5
use Lagdo\DbAdmin\Driver\Db\StatementInterface;
6
use Lagdo\DbAdmin\Driver\Entity\StatementFieldEntity;
7
8
use SQLite3Result;
9
10
class Statement implements StatementInterface
11
{
12
    /**
13
     * The query result
14
     *
15
     * @var SQLite3Result
16
     */
17
    protected $result = null;
18
19
    /**
20
     * Undocumented variable
21
     *
22
     * @var int
23
     */
24
    protected $offset = 0;
25
26
    /**
27
     * The constructor
28
     *
29
     * @param SQLite3Result $result
30
     */
31
    public function __construct(SQLite3Result $result)
32
    {
33
        $this->result = $result;
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function rowCount()
40
    {
41
        // Todo: find a simpler way to count the rows.
42
        $rowCount = 0;
43
        $this->result->reset();
44
        while ($this->result->fetchArray()) {
45
            $rowCount++;
46
        }
47
        $this->result->reset();
48
        return $rowCount;
49
    }
50
51
    /**
52
     * @inheritDoc
53
     */
54
    public function fetchAssoc()
55
    {
56
        return $this->result->fetchArray(SQLITE3_ASSOC);
57
    }
58
59
    /**
60
     * @inheritDoc
61
     */
62
    public function fetchRow()
63
    {
64
        return $this->result->fetchArray(SQLITE3_NUM);
65
    }
66
67
    /**
68
     * @inheritDoc
69
     */
70
    public function fetchField()
71
    {
72
        $column = $this->offset++;
73
        $type = $this->result->columnType($column);
74
        $name = $this->result->columnName($column);
75
        return new StatementFieldEntity($type, $type === SQLITE3_BLOB, $name, $name);
76
    }
77
78
    /**
79
     * The destructor
80
     */
81
    public function __destruct()
82
    {
83
        $this->result->finalize();
84
    }
85
}
86