updateProgrammingLanguage()   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 2
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/ProgrammingLanguage.php" ;
6
7
/**
8
 * DAO for programming languages
9
 */
10
class ProgrammingLanguageDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
    /**
18
     * Get all programming languages
19
     *
20
     * @return \AL\Common\Model\Game\ProgrammingLanguage[] An array of languages
21
     */
22
    public function getAllProgrammingLanguages() {
23
        $stmt = \AL\Db\execute_query(
24
            "ProgrammingLanguageDAO: getAllProgrammingLanguages",
25
            $this->mysqli,
26
            "SELECT id, name FROM programming_language ORDER BY id",
27
            null, null
28
        );
29
30
        \AL\Db\bind_result(
31
            "ProgrammingLanguageDAO: getAllProgrammingLanguages",
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
        $programming_languages = [];
37
        while ($stmt->fetch()) {
38
            $programming_languages[] = new \AL\Common\Model\Game\ProgrammingLanguage(
39
                $id, $name
40
            );
41
        }
42
43
        $stmt->close();
44
45
        return $programming_languages;
46
    }
47
48
    /**
49
     * Get list of programming_language IDs for a game
50
     *
51
     * @param integer Game ID
52
     */
53
    public function getProgrammingLanguagesForGame($game_id) {
54
        $stmt = \AL\Db\execute_query(
55
            "ProgrammingLanguageDAO: getProgrammingLanguagesForGame",
56
            $this->mysqli,
57
            "SELECT programming_language_id FROM game_programming_language WHERE game_id = ?",
58
            "i", $game_id
59
        );
60
61
        \AL\Db\bind_result(
62
            "ProgrammingLanguageDAO: getProgrammingLanguagesForGame",
63
            $stmt,
64
            $programming_language_id
65
        );
66
67
        $programming_languages = [];
68
        while ($stmt->fetch()) {
69
            $programming_languages[] = new \AL\Common\Model\Game\ProgrammingLanguage(
70
                $programming_language_id, null
71
            );
72
        }
73
74
        $stmt->close();
75
76
        return $programming_languages;
77
    }
78
    
79
    /**
80
     * Set the list of programming languages for this game
81
     *
82
     * @param integer Game ID
83
     * @param integer[] List of programming language 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...
84
     */
85
    public function setProgrammingLanguageForGame($game_id, $programming_languages) {
86
        $stmt = \AL\Db\execute_query(
87
            "ProgrammingLanguageDAO: setProgrammingLanguageForGame",
88
            $this->mysqli,
89
            "DELETE FROM game_programming_language WHERE game_id = ?",
90
            "i", $game_id
91
        );
92
93
        foreach ($programming_languages as $id) {
94
            $stmt = \AL\Db\execute_query(
95
                "ProgrammingLanguageDAO: setProgrammingLanguageForGame",
96
                $this->mysqli,
97
                "INSERT INTO game_programming_language (game_id, programming_language_id) VALUES (?, ?)",
98
                "ii", $game_id, $id
99
            );
100
        }
101
102
        $stmt->close();
103
    }
104
    
105
    /**
106
     * add a programming language to the database
107
     *
108
     * @param varchar name
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\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...
109
     */
110
    public function addProgrammingLanguage($name) {
111
        $stmt = \AL\Db\execute_query(
112
            "ProgrammingLanguageDAO: addProgrammingLanguage",
113
            $this->mysqli,
114
            "INSERT INTO programming_language (`name`) VALUES (?)",
115
            "s", $name
116
        );
117
118
        $stmt->close();
119
    }
120
    
121
    /**
122
     * delete a programming language
123
     *
124
     * @param int id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\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...
125
     */
126
    public function deleteProgrammingLanguage($id) {
127
        $stmt = \AL\Db\execute_query(
128
            "ProgrammingLanguageDAO: deleteProgrammingLanguage",
129
            $this->mysqli,
130
            "DELETE FROM programming_language WHERE id = ?",
131
            "i", $id
132
        );
133
134
        $stmt->close();
135
    }
136
    
137
    /**
138
     * update a programming language
139
     *
140
     * @param int id
141
     * @param varchar name
142
     */
143
    public function updateProgrammingLanguage($id, $name) {
144
        $stmt = \AL\Db\execute_query(
145
            "ProgrammingLanguageDAO: updateProgrammingLanguage",
146
            $this->mysqli,
147
            "UPDATE programming_language SET name = ? WHERE id = ?",
148
            "si", $name, $id
149
        );
150
        
151
        $stmt->close();
152
    }
153
}
154