Statement::__destruct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver\MySql\Db\MySqli;
4
5
use Lagdo\DbAdmin\Driver\Db\StatementInterface;
6
use Lagdo\DbAdmin\Driver\Entity\StatementFieldEntity;
7
8
use mysqli_result;
9
10
use function is_a;
11
12
class Statement implements StatementInterface
13
{
14
    /**
15
     * The query result
16
     *
17
     * @var mysqli_result
18
     */
19
    protected $result = null;
20
21
    /**
22
     * The constructor
23
     *
24
     * @param mysqli_result|bool $result
25
     */
26
    public function __construct($result)
27
    {
28
        if (is_a($result, mysqli_result::class)) {
29
            $this->result = $result;
30
        }
31
    }
32
33
    /**
34
     * @inheritDoc
35
     */
36
    public function rowCount()
37
    {
38
        return $this->result ? $this->result->num_rows : 0;
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44
    public function fetchAssoc()
45
    {
46
        return ($this->result) ? $this->result->fetch_assoc() : null;
47
    }
48
49
    /**
50
     * @inheritDoc
51
     */
52
    public function fetchRow()
53
    {
54
        return ($this->result) ? $this->result->fetch_row() : null;
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    public function fetchField()
61
    {
62
        if (!$this->result || !($field = $this->result->fetch_field())) {
63
            return null;
64
        }
65
        return new StatementFieldEntity($field->type, $field->type === 63, // 63 - binary
66
            $field->name, $field->orgname, $field->table, $field->orgtable);
67
    }
68
69
    /**
70
     * The destructor
71
     */
72
    public function __destruct()
73
    {
74
        if (($this->result)) {
75
            $this->result->free();
76
        }
77
    }
78
}
79