EngineDAO::addGameEngine()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
namespace AL\Common\DAO;
3
4
require_once __DIR__."/../../lib/Db.php" ;
5
require_once __DIR__."/../Model/Game/Engine.php" ;
6
7
/**
8
 * DAO for game engines
9
 */
10
class EngineDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
    /**
18
     * Get all egines
19
     *
20
     * @return \AL\Common\Model\Game\GameGenres[] An array of genres
21
     */
22
    public function getAllEngines() {
23
        $stmt = \AL\Db\execute_query(
24
            "EngineDAO: getAllEngines",
25
            $this->mysqli,
26
            "SELECT id, name, description FROM engine ORDER BY name",
27
            null, null
28
        );
29
30
        \AL\Db\bind_result(
31
            "EngineDAO: getAllEngines",
32
            $stmt,
33
            $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...
34
        );
35
36
        $game_engines = [];
37
        while ($stmt->fetch()) {
38
            $game_engines[] = new \AL\Common\Model\Game\Engine(
39
                $id, $name, $description
40
            );
41
        }
42
43
        $stmt->close();
44
45
        return $game_engines;
46
    }
47
48
    /**
49
     * Get list of game_engines for a game
50
     *
51
     * @param integer Game ID
52
     */
53
    public function getGameEnginesForGame($game_id) {
54
        $stmt = \AL\Db\execute_query(
55
            "EngineDAO: getGameEnginesForGame",
56
            $this->mysqli,
57
            "SELECT engine_id, name, description
58
            FROM game_engine LEFT JOIN engine ON (game_engine.engine_id = engine.id)
59
            WHERE game_id = ?",
60
            "i", $game_id
61
        );
62
63
        \AL\Db\bind_result(
64
            "EngineDAO: getGameEnginesForGame",
65
            $stmt,
66
            $engine_id, $name, $description
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $name seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $description seems to be never defined.
Loading history...
67
        );
68
69
        $game_engines = [];
70
        while ($stmt->fetch()) {
71
            $game_engines[] = new \AL\Common\Model\Game\Engine(
72
                $engine_id, $name, $description
73
            );
74
        }
75
76
        $stmt->close();
77
78
        return $game_engines;
79
    }
80
    
81
     /**
82
     * Set the list of game engines for this game
83
     *
84
     * @param integer Game ID
85
     * @param integer[] List of game genre 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...
86
     */
87
    public function setGameEngineForGame($game_id, $game_engine_id) {
88
        $stmt = \AL\Db\execute_query(
89
            "EngineDAO: setGameEngineForGame",
90
            $this->mysqli,
91
            "DELETE FROM game_engine WHERE game_id = ?",
92
            "i", $game_id
93
        );
94
95
        foreach ($game_engine_id as $id) {
96
            $stmt = \AL\Db\execute_query(
97
                "EngineDAO: setGameEngineForGame",
98
                $this->mysqli,
99
                "INSERT INTO game_engine (game_id, engine_id) VALUES (?, ?)",
100
                "ii", $game_id, $id
101
            );
102
        }
103
104
        $stmt->close();
105
    }
106
    
107
    /**
108
     * add a game engine type to the database
109
     *
110
     * @param varchar Engine
111
     */
112
    public function addGameEngine($engine) {
113
        $stmt = \AL\Db\execute_query(
114
            "EngineDAO: addGameEngine",
115
            $this->mysqli,
116
            "INSERT INTO engine (`name`) VALUES (?)",
117
            "s", $engine
118
        );
119
120
        $stmt->close();
121
    }
122
    
123
    /**
124
     * delete a game engine type
125
     *
126
     * @param int Engine_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\Engine_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...
127
     */
128
    public function deleteGameEngine($engine_id) {
129
        $stmt = \AL\Db\execute_query(
130
            "EngineDAO: deleteGameEngine",
131
            $this->mysqli,
132
            "DELETE FROM engine WHERE id = ?",
133
            "i", $engine_id
134
        );
135
136
        $stmt->close();
137
    }
138
    
139
        /**
140
     * update a game engine type
141
     *
142
     * @param int Engine_id
143
     * @param varchar Engine_name
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\Engine_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...
144
     */
145
    public function updateGameEngine($engine_id, $engine_name) {
146
        $stmt = \AL\Db\execute_query(
147
            "EngineDAO: updateGameEngine",
148
            $this->mysqli,
149
            "UPDATE engine SET name = ? WHERE id = ?",
150
            "si", $engine_name, $engine_id
151
        );
152
        
153
        $stmt->close();
154
    }
155
}
156