ChangeDAO   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 59
dl 0
loc 92
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getChangeByUpdateId() 0 44 2
A insertChange() 0 26 1
A __construct() 0 2 1
1
<?php
2
namespace AL\Common\DAO;
3
4
require_once __DIR__."/../../lib/Db.php" ;
5
require_once __DIR__."/../Model/Database/Change.php" ;
6
7
/**
8
 * DAO for DB Change
9
 */
10
class ChangeDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
18
    /**
19
     * Get a single change from it's update ID (NOT the automatically incremented
20
     *  id from the database)
21
     * @param number $id Update ID of the change to retrieve
22
     * @return \AL\Common\Model\Database\Change The change
23
     */
24
    public function getChangeByUpdateId($update_id) {
25
        $stmt = \AL\Db\execute_query(
26
            "ChangeDAO: getChange: $update_id",
27
            $this->mysqli,
28
            "SELECT
29
                database_change_id,
30
                database_update_id,
31
                update_description,
32
                execute_timestamp,
33
                implementation_state,
34
                update_filename,
35
                database_change_script
36
            FROM database_change WHERE database_update_id = ?",
37
            "i", $update_id
38
        );
39
40
        \AL\Db\bind_result(
41
            "ChangeDAO: getChange: $update_id",
42
            $stmt,
43
            $database_change_id,
44
            $database_update_id,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $database_update_id does not exist. Did you maybe mean $update_id?
Loading history...
45
            $update_description,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $update_description seems to be never defined.
Loading history...
46
            $execute_timestamp,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $execute_timestamp seems to be never defined.
Loading history...
47
            $implementation_state,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $implementation_state seems to be never defined.
Loading history...
48
            $update_filename,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $update_filename seems to be never defined.
Loading history...
49
            $database_change_script
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $database_change_script does not exist. Did you maybe mean $change?
Loading history...
50
        );
51
52
        $change = null;
53
        if ($stmt->fetch()) {
54
            $change = new \AL\Common\Model\Database\Change(
55
                $database_change_id,
56
                $database_update_id,
57
                $update_description,
58
                $execute_timestamp,
59
                $implementation_state,
60
                $update_filename,
61
                $database_change_script
62
            );
63
        }
64
65
        $stmt->close();
66
67
        return $change;
68
    }
69
70
    /**
71
     * Insert a new change
72
     *
73
     * @param  \AL\Common\Model\Database\Change Change to insert
74
     * @return integer ID of the inserted change
75
     */
76
    public function insertChange($change) {
77
        $stmt = \AL\Db\execute_query(
78
            "ChangeDAO: insertChange",
79
            $this->mysqli,
80
            "INSERT INTO database_change (
81
                database_update_id,
82
                update_description,
83
                execute_timestamp,
84
                implementation_state,
85
                update_filename,
86
                database_change_script
87
            ) VALUES (?, ?, ?, ?, ?, ?)",
88
            "isisss",
89
            $change->getUpdateId(),
90
            $change->getDescription(),
91
            $change->getTimestamp(),
92
            $change->getState(),
93
            $change->getFilename(),
94
            $change->getScript()
95
        );
96
97
        $id = $stmt->insert_id;
98
99
        $stmt->close();
100
101
        return $id;
102
    }
103
}
104