SoundHardwareDAO   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 156
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 67
dl 0
loc 156
rs 10
c 0
b 0
f 0
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A updateSoundHardware() 0 9 1
A addSoundHardware() 0 9 1
A __construct() 0 2 1
A deleteSoundHardware() 0 9 1
A addSoundHardwareToGame() 0 10 1
A getSoundHardwareForGame() 0 27 2
A deleteSoundHardwareFromGame() 0 10 1
A getAllSoundHardware() 0 24 2
1
<?php
2
namespace AL\Common\DAO;
3
4
require_once __DIR__."/../../lib/Db.php" ;
5
require_once __DIR__."/../Model/Game/SoundHardware.php" ;
6
7
/**
8
 * DAO for Sound Hardware
9
 */
10
class SoundHardwareDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
    /**
18
     * Get all Sound Hardware Types
19
20
     * @return \AL\Common\Model\Game\SoundHardware[] An array of SoundHardware types
21
     */
22
    public function getAllSoundHardware() {
23
        $stmt = \AL\Db\execute_query(
24
            "SoundHardwareDAO: getAllSoundHardware",
25
            $this->mysqli,
26
            "SELECT id, name FROM sound_hardware ORDER BY name",
27
            null, null
28
        );
29
30
        \AL\Db\bind_result(
31
            "SoundHardwareDAO: getAllSoundHardware",
32
            $stmt,
33
            $id, $name
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $name seems to be never defined.
Loading history...
34
        );
35
36
        $sound_hardware_types = [];
37
        while ($stmt->fetch()) {
38
            $sound_hardware_types[] = new \AL\Common\Model\Game\SoundHardware(
39
                $id, $name, null
40
            );
41
        }
42
43
        $stmt->close();
44
45
        return $sound_hardware_types;
46
    }
47
48
    /**
49
     * Get list of sound_hardware IDs for a game
50
     *
51
     * @param integer game ID
52
     */
53
    public function getSoundHardwareForGame($game_id) {
54
        $stmt = \AL\Db\execute_query(
55
            "SoundHardwareDAO: getSoundHardwareForGame",
56
            $this->mysqli,
57
            "SELECT sound_hardware_id, name, description
58
            FROM game_sound_hardware LEFT JOIN 
59
            sound_hardware ON (game_sound_hardware.sound_hardware_id = sound_hardware.id)
60
            WHERE game_id = ?",
61
            "i", $game_id
62
        );
63
64
        \AL\Db\bind_result(
65
            "SoundHardwareDAO: getSoundHardwareForGame",
66
            $stmt,
67
            $sound_hardware_id, $name, $description
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $description seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $name seems to be never defined.
Loading history...
68
        );
69
70
        $sound_hardware_types = [];
71
        while ($stmt->fetch()) {
72
            $sound_hardware_types[] = new \AL\Common\Model\Game\SoundHardware(
73
                $sound_hardware_id, $name, $description
74
            );
75
        }
76
77
        $stmt->close();
78
79
        return $sound_hardware_types;
80
    }
81
    
82
     /**
83
     * Add sound hardware to game
84
     *
85
     * @param integer Game ID
86
     * @param integer hardware ID
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\hardware was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
87
     * $param text description
88
     */
89
    public function addSoundHardwareToGame($game_id, $hardware_id) {
90
       
91
        $stmt = \AL\Db\execute_query(
92
            "SoundHardwareDAO: addSoundHardwareToGame",
93
            $this->mysqli,
94
            "INSERT INTO game_sound_hardware (game_id, sound_hardware_id) VALUES (?, ?)",
95
            "ii", $game_id, $hardware_id
96
        );
97
98
        $stmt->close();
99
    }
100
    
101
     /**
102
     * Delete sound hardware from game
103
     *
104
     * @param integer Game ID
105
     * @param integer hardware ID
106
     */
107
    public function deleteSoundHardwareFromGame($game_id, $hardware_id) {
108
        $stmt = \AL\Db\execute_query(
109
            "SoundHardwareDAO: deleteSoundHardwareFromGame",
110
            $this->mysqli,
111
            "DELETE FROM game_sound_hardware
112
            WHERE game_id = ? AND sound_hardware_id = ?",
113
            "ii", $game_id, $hardware_id
114
        );
115
116
        $stmt->close();
117
    }
118
     
119
     /**
120
     * add a sound hardware type to the database
121
     *
122
     * @param varchar sound hardware type
123
     */
124
    public function addSoundHardware($sound_hardware) {
125
        $stmt = \AL\Db\execute_query(
126
            "SoundHardwareDAO: addSoundHardware",
127
            $this->mysqli,
128
            "INSERT INTO sound_hardware (`name`) VALUES (?)",
129
            "s", $sound_hardware
130
        );
131
132
        $stmt->close();
133
    }
134
    
135
    /**
136
     * delete a sound hardware
137
     *
138
     * @param int $hardware_id
139
     */
140
    public function deleteSoundHardware($hardware_id) {
141
        $stmt = \AL\Db\execute_query(
142
            "SoundHardwareDAO: deleteSoundHardware",
143
            $this->mysqli,
144
            "DELETE FROM sound_hardware WHERE id = ?",
145
            "i", $hardware_id
146
        );
147
148
        $stmt->close();
149
    }
150
    
151
        /**
152
     * update a sound hardware
153
     *
154
     * @param int sound_hardware_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\sound_hardware_id was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
155
     * @param varchar sound_hardware
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\sound_hardware was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
156
     */
157
    public function updateSoundHardware($sound_hardware_id, $sound_hardware) {
158
        $stmt = \AL\Db\execute_query(
159
            "SoundHardwareDAO: updateSoundHardware",
160
            $this->mysqli,
161
            "UPDATE sound_hardware SET name = ? WHERE id = ?",
162
            "si", $sound_hardware, $sound_hardware_id
163
        );
164
        
165
        $stmt->close();
166
    }
167
}
168