GameGenreDAO   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 144
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 65
dl 0
loc 144
rs 10
c 0
b 0
f 0
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getGameGenresForGame() 0 26 2
A addGenre() 0 9 1
A setGameGenreForGame() 0 18 2
A getAllGameGenres() 0 24 2
A updateGenre() 0 9 1
A deleteGenre() 0 9 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/GameGenre.php" ;
6
7
/**
8
 * DAO for game genres
9
 */
10
class GameGenreDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
    /**
18
     * Get all Game Genres
19
     *
20
     * @return \AL\Common\Model\Game\GameGenres[] An array of genres
21
     */
22
    public function getAllGameGenres() {
23
        $stmt = \AL\Db\execute_query(
24
            "GameGenreDAO: getAllGameGenres",
25
            $this->mysqli,
26
            "SELECT id, name FROM game_genre ORDER BY name",
27
            null, null
28
        );
29
30
        \AL\Db\bind_result(
31
            "GameGenreDAO: getAllGameGenres",
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
        $game_genres = [];
37
        while ($stmt->fetch()) {
38
            $game_genres[] = new \AL\Common\Model\Game\GameGenre(
39
                $id, $name
40
            );
41
        }
42
43
        $stmt->close();
44
45
        return $game_genres;
46
    }
47
48
    /**
49
     * Get list of game_genre IDs for a game
50
     *
51
     * @param integer Game ID
52
     */
53
    public function getGameGenresForGame($game_id) {
54
        $stmt = \AL\Db\execute_query(
55
            "GameGenreDAO: getGameGenresForGame",
56
            $this->mysqli,
57
            "SELECT game_genre_id, name
58
            FROM game_genre_cross LEFT JOIN game_genre ON (game_genre_cross.game_genre_id = game_genre.id)
59
            WHERE game_id = ?",
60
            "i", $game_id
61
        );
62
63
        \AL\Db\bind_result(
64
            "GameGenreDAO: getGameGenresForGame",
65
            $stmt,
66
            $game_genre_id, $name
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $name seems to be never defined.
Loading history...
67
        );
68
69
        $game_genres = [];
70
        while ($stmt->fetch()) {
71
            $game_genres[] = new \AL\Common\Model\Game\GameGenre(
72
                $game_genre_id, $name
73
            );
74
        }
75
76
        $stmt->close();
77
78
        return $game_genres;
79
    }
80
    
81
    /**
82
     * Set the list of game genres 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 setGameGenreForGame($game_id, $game_genre_id) {
88
        $stmt = \AL\Db\execute_query(
89
            "GameGenreDAO: setGameGenreForGame",
90
            $this->mysqli,
91
            "DELETE FROM game_genre_cross WHERE game_id = ?",
92
            "i", $game_id
93
        );
94
95
        foreach ($game_genre_id as $id) {
96
            $stmt = \AL\Db\execute_query(
97
                "GameGenreDAO: setGameGenreForGame",
98
                $this->mysqli,
99
                "INSERT INTO game_genre_cross (game_id, game_genre_id) VALUES (?, ?)",
100
                "ii", $game_id, $id
101
            );
102
        }
103
104
        $stmt->close();
105
    }
106
     
107
     /**
108
     * add a genre to the database
109
     *
110
     * @param varchar Genre
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\Genre 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...
111
     */
112
    public function addGenre($genre) {
113
        $stmt = \AL\Db\execute_query(
114
            "GameGenreDAO: addGenre",
115
            $this->mysqli,
116
            "INSERT INTO game_genre (`name`) VALUES (?)",
117
            "s", $genre
118
        );
119
120
        $stmt->close();
121
    }
122
    
123
    /**
124
     * delete a genre
125
     *
126
     * @param int genre_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\genre_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 deleteGenre($genre_id) {
129
        $stmt = \AL\Db\execute_query(
130
            "GameGenreDAO: deleteGenre",
131
            $this->mysqli,
132
            "DELETE FROM game_genre WHERE id = ?",
133
            "i", $genre_id
134
        );
135
136
        $stmt->close();
137
    }
138
    
139
        /**
140
     * update a genre
141
     *
142
     * @param int genre_id
143
     * @param varchar genre_name
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\genre_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 updateGenre($genre_id, $genre_name) {
146
        $stmt = \AL\Db\execute_query(
147
            "GameGenreDAO: updateGenre",
148
            $this->mysqli,
149
            "UPDATE game_genre SET name = ? WHERE id = ?",
150
            "si", $genre_name, $genre_id
151
        );
152
        
153
        $stmt->close();
154
    }
155
}
156