SystemDAO   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 315
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 139
dl 0
loc 315
rs 10
c 0
b 0
f 0
wmc 22

14 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteSystem() 0 9 1
A setIncompatibleSystemsForRelease() 0 18 2
A getIncompatibleSystemIdsForRelease() 0 22 2
A addSystem() 0 9 1
A getAllSystemsAsMap() 0 8 2
A getEnhancedSystemsForRelease() 0 31 3
A getAllSystems() 0 24 2
A getIncompatibleSystemsForRelease() 0 26 2
A addEnhancedSystemForRelease() 0 10 1
A setEnhancedSystemsForRelease() 0 18 2
A updateSystem() 0 9 1
A deleteEnhancedSystemForRelease() 0 8 1
A updateEnhancedSystemForRelease() 0 13 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/Game/System.php" ;
6
require_once __DIR__."/../Model/Game/Enhancement.php" ;
7
8
/**
9
 * DAO for systems
10
 */
11
class SystemDAO {
12
    private $mysqli;
13
14
    public function __construct($mysqli) {
15
        $this->mysqli = $mysqli;
16
    }
17
18
    /**
19
     * Get all systems
20
     *
21
     * @return \AL\Common\Model\Game\System[] An array of systems
22
     */
23
    public function getAllSystems() {
24
        $stmt = \AL\Db\execute_query(
25
            "SystemDAO: getAllSystems",
26
            $this->mysqli,
27
            "SELECT id, name FROM system ORDER by name",
28
            null, null
29
        );
30
31
        \AL\Db\bind_result(
32
            "SystemDAO: getAllSystems",
33
            $stmt,
34
            $id, $name
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $name seems to be never defined.
Loading history...
35
        );
36
37
        $systems = [];
38
        while ($stmt->fetch()) {
39
            $systems[] = new \AL\Common\Model\Game\System(
40
                $id, $name, null
41
            );
42
        }
43
44
        $stmt->close();
45
46
        return $systems;
47
    }
48
49
    /**
50
     * Get a map containing all systems, indexed by ID
51
     *
52
     * @return \AL\Common\Model\Game\System[] A map of systems
53
     */
54
    public function getAllSystemsAsMap() {
55
        $systems = $this->getAllSystems();
56
        $systemsMap = array();
57
        foreach ($systems as $system) {
58
            $systemsMap[$system->getId()] = $system;
59
        }
60
61
        return $systemsMap;
62
    }
63
64
    /**
65
     * Get all system IDs incompatible with a release
66
     *
67
     * @param integer Release ID
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\Release 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...
68
     * @return integer[] List of incompatible system IDs
69
     */
70
    public function getIncompatibleSystemIdsForRelease($release_id) {
71
        $stmt = \AL\Db\execute_query(
72
            "SystemDAO: getIncompatibleSystemIdsForRelease",
73
            $this->mysqli,
74
            "SELECT system_id FROM game_release_system_incompatible WHERE game_release_id = ?",
75
            "i", $release_id
76
        );
77
78
        \AL\Db\bind_result(
79
            "SystemDAO: getIncompatibleSystemIdsForRelease",
80
            $stmt,
81
            $system_id
82
        );
83
84
        $systems = [];
85
        while ($stmt->fetch()) {
86
            $systems[] = $system_id;
87
        }
88
89
        $stmt->close();
90
91
        return $systems;
92
    }
93
94
    /**
95
     * Get all system incompatible with a release
96
     *
97
     * @param integer Release ID
98
     * @return integer[] List of incompatible system IDs
99
     */
100
    public function getIncompatibleSystemsForRelease($release_id) {
101
        $stmt = \AL\Db\execute_query(
102
            "SystemDAO: getIncompatibleSystemsForRelease",
103
            $this->mysqli,
104
            "SELECT system_id, name FROM game_release_system_incompatible
105
            JOIN system on game_release_system_incompatible.system_id = system.id
106
            WHERE game_release_id = ?",
107
            "i", $release_id
108
        );
109
110
        \AL\Db\bind_result(
111
            "SystemDAO: getIncompatibleSystemsForRelease",
112
            $stmt,
113
            $id, $name
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $name seems to be never defined.
Loading history...
114
        );
115
116
        $systems = [];
117
        while ($stmt->fetch()) {
118
            $systems[] = new \AL\Common\Model\Game\System(
119
                $id, $name, null
120
            );
121
        }
122
123
        $stmt->close();
124
125
        return $systems;
126
    }
127
128
129
    /**
130
     * Set the list of systems a release is incompatible with
131
     *
132
     * @param integer Release ID
133
     * @param integer[] List of system IDs
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\List 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...
134
     */
135
    public function setIncompatibleSystemsForRelease($release_id, $systems) {
136
        $stmt = \AL\Db\execute_query(
137
            "SystemDAO: setIncompatibleSystemsForRelease",
138
            $this->mysqli,
139
            "DELETE FROM game_release_system_incompatible WHERE game_release_id = ?",
140
            "i", $release_id
141
        );
142
143
        foreach ($systems as $id) {
144
            $stmt = \AL\Db\execute_query(
145
                "SystemDAO: setIncompatibleSystemsForRelease",
146
                $this->mysqli,
147
                "INSERT INTO game_release_system_incompatible (game_release_id, system_id) VALUES (?, ?)",
148
                "ii", $release_id, $id
149
            );
150
        }
151
152
        $stmt->close();
153
    }
154
155
    /**
156
     * Get all system enhanced for a release
157
     *
158
     * @param integer Release ID
159
     * @return integer[] List of enhanced system IDs
160
     */
161
    public function getEnhancedSystemsForRelease($release_id) {
162
        $stmt = \AL\Db\execute_query(
163
            "SystemDAO: getEnhancedSystemsForRelease",
164
            $this->mysqli,
165
            "SELECT system_id, system.name, enhancement_id, enhancement.name
166
            FROM game_release_system_enhanced
167
            LEFT JOIN system ON (game_release_system_enhanced.system_id = system.id)
168
            LEFT JOIN enhancement ON (game_release_system_enhanced.enhancement_id = enhancement.id)
169
            WHERE game_release_id = ?",
170
            "i", $release_id
171
        );
172
173
        \AL\Db\bind_result(
174
            "SystemDAO: getEnhancedSystemsForRelease",
175
            $stmt,
176
            $system_id, $system, $enhancement_id, $enhancement
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $system does not exist. Did you maybe mean $systems?
Loading history...
Comprehensibility Best Practice introduced by
The variable $enhancement_id seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $enhancement seems to be never defined.
Loading history...
177
        );
178
179
        $systems = [];
180
        while ($stmt->fetch()) {
181
            $systems[] = new \AL\Common\Model\Game\System(
182
                $system_id, $system,
183
                ($enhancement_id != null)
184
                    ? new \AL\Common\Model\Game\Enhancement($enhancement_id, $enhancement)
185
                    : null
186
            );
187
        }
188
189
        $stmt->close();
190
191
        return $systems;
192
    }
193
194
    /**
195
     * Set the list of systems a release is enhanced for
196
     *
197
     * @param integer Release ID
198
     * @param integer[] List of system IDs
199
     */
200
    public function setEnhancedSystemsForRelease($release_id, $systems) {
201
        $stmt = \AL\Db\execute_query(
202
            "SystemDAO: setEnhancedSystemsForRelease",
203
            $this->mysqli,
204
            "DELETE FROM game_release_system_enhanced WHERE game_release_id = ?",
205
            "i", $release_id
206
        );
207
208
        foreach ($systems as $id) {
209
            $stmt = \AL\Db\execute_query(
210
                "SystemDAO: setEnhancedSystemsForRelease",
211
                $this->mysqli,
212
                "INSERT INTO game_release_system_enhanced (game_release_id, system_id) VALUES (?, ?)",
213
                "ii", $release_id, $id
214
            );
215
        }
216
217
        $stmt->close();
218
    }
219
220
        /**
221
     * Set the list of system enhancements for a release
222
     *
223
     * @param integer Release ID
224
     * @param integer[] system ID
225
     * @param integer[] enhancement IDs
226
     */
227
    public function addEnhancedSystemForRelease($release_id, $system_id, $enhancement_id) {
228
229
        $stmt = \AL\Db\execute_query(
230
            "SystemDAO: addEnhancedSystemForRelease",
231
            $this->mysqli,
232
            "INSERT INTO game_release_system_enhanced (game_release_id, system_id, enhancement_id) VALUES (?, ?, ?)",
233
            "iii", $release_id, $system_id, $enhancement_id
234
        );
235
236
        $stmt->close();
237
    }
238
239
240
        /**
241
     * update system enhancements for a release
242
     *
243
     * @param integer Release ID
244
     * @param integer[] system ID
245
     * @param integer[] enhancement IDs
246
     */
247
    public function updateEnhancedSystemForRelease($release_id, $system_id, $enhancement_id) {
248
249
        $stmt = \AL\Db\execute_query(
250
            "SystemDAO: updateEnhancedSystemForRelease",
251
            $this->mysqli,
252
            "UPDATE game_release_system_enhanced
253
            SET
254
                `enhancement_id` = ?
255
            WHERE game_release_id = ? AND system_id = ?",
256
            "iii", $enhancement_id, $release_id, $system_id
257
        );
258
259
        $stmt->close();
260
    }
261
262
        /**
263
     * delete system enhancements for a release
264
     *
265
     * @param integer Release ID
266
     * @param integer[] system ID
267
     */
268
    public function deleteEnhancedSystemForRelease($release_id, $system_id) {
269
270
        $stmt = \AL\Db\execute_query(
0 ignored issues
show
Unused Code introduced by
The assignment to $stmt is dead and can be removed.
Loading history...
271
            "SystemDAO: deleteEnhancedSystemForRelease",
272
            $this->mysqli,
273
            "DELETE FROM game_release_system_enhanced
274
            WHERE game_release_id = ? AND system_id = ?",
275
            "ii", $release_id, $system_id
276
        );
277
    }
278
279
        /**
280
     * add a system to the database
281
     *
282
     * @param varchar system
283
     */
284
    public function addSystem($system) {
285
        $stmt = \AL\Db\execute_query(
286
            "SystemDAO: addSystem",
287
            $this->mysqli,
288
            "INSERT INTO system (`name`) VALUES (?)",
289
            "s", $system
290
        );
291
292
        $stmt->close();
293
    }
294
295
    /**
296
     * delete a system
297
     *
298
     * @param int system_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\system_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...
299
     */
300
    public function deleteSystem($system_id) {
301
        $stmt = \AL\Db\execute_query(
302
            "SystemDAO: deleteSystem",
303
            $this->mysqli,
304
            "DELETE FROM system WHERE id = ?",
305
            "i", $system_id
306
        );
307
308
        $stmt->close();
309
    }
310
311
        /**
312
     * update a system
313
     *
314
     * @param int system_id
315
     * @param varchar system_name
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\system_name 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...
316
     */
317
    public function updateSystem($system_id, $system_name) {
318
        $stmt = \AL\Db\execute_query(
319
            "SystemDAO: updateSystem",
320
            $this->mysqli,
321
            "UPDATE system SET name = ? WHERE id = ?",
322
            "si", $system_name, $system_id
323
        );
324
325
        $stmt->close();
326
    }
327
}
328