TosDAO   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 184
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 81
dl 0
loc 184
rs 10
c 0
b 0
f 0
wmc 12

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A deleteTos() 0 9 1
A updateTos() 0 9 1
A setIncompatibleTosForRelease() 0 10 1
A deleteTosForRelease() 0 10 1
A getAllTos() 0 24 2
A getIncompatibleTosForRelease() 0 32 3
A updateTosLanguageForRelease() 0 12 1
A addTos() 0 9 1
1
<?php
2
namespace AL\Common\DAO;
3
4
require_once __DIR__."/../../lib/Db.php" ;
5
require_once __DIR__."/../Model/Game/Tos.php" ;
6
7
/**
8
 * DAO for Tos versions
9
 */
10
class TosDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
    /**
18
     * Get all Tos versions
19
     *
20
     * @return \AL\Common\Model\Game\Emulator[] An array of Tos versions
21
     */
22
    public function getAllTos() {
23
        $stmt = \AL\Db\execute_query(
24
            "TosDAO: getAllTos",
25
            $this->mysqli,
26
            "SELECT id, name FROM tos ORDER by name",
27
            null, null
28
        );
29
30
        \AL\Db\bind_result(
31
            "TosDAO: getAllTos",
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
        $tos_versions = [];
37
        while ($stmt->fetch()) {
38
            $tos_versions[] = new \AL\Common\Model\Game\Tos(
39
                $id, $name, null
40
            );
41
        }
42
43
        $stmt->close();
44
45
        return $tos_versions;
46
    }
47
48
     /**
49
     * Get all tos IDs incompatible with a release
50
     *
51
     * @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...
52
     * @return integer[] List of incompatible TOS IDs
53
     */
54
    public function getIncompatibleTosForRelease($release_id) {
55
        $stmt = \AL\Db\execute_query(
56
            "TosDAO: getIncompatibleTosForRelease",
57
            $this->mysqli,
58
            "SELECT game_release_tos_version_incompatibility.tos_id,
59
                    tos.name, game_release_tos_version_incompatibility.language_id, language.name
60
                    FROM game_release_tos_version_incompatibility
61
                    LEFT JOIN tos ON (game_release_tos_version_incompatibility.tos_id = tos.id)
62
                    LEFT JOIN language ON (language.id = game_release_tos_version_incompatibility.language_id)
63
                    WHERE release_id = ?",
64
            "i", $release_id
65
        );
66
67
        \AL\Db\bind_result(
68
            "TosDAO: getIncompatibleTosForRelease",
69
            $stmt,
70
            $tos_id, $tos_name, $language_id, $language_name
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $tos_name seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $language_name seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $language_id seems to be never defined.
Loading history...
71
        );
72
73
        $tos_versions = [];
74
        while ($stmt->fetch()) {
75
            $tos_versions[] = new \AL\Common\Model\Game\Tos(
76
                $tos_id, $tos_name,
77
                $language_id
78
                    ? new \AL\Common\Model\Language\Language($language_id, $language_name)
79
                    : null
80
            );
81
        }
82
83
        $stmt->close();
84
85
        return $tos_versions;
86
    }
87
88
    /**
89
     * Set the list of tos versions a release is incompatible with
90
     *
91
     * @param integer Release ID
92
     * @param integer[] List of TOS 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...
93
     */
94
    public function setIncompatibleTosForRelease($release_id, $tos, $language) {
95
96
        $stmt = \AL\Db\execute_query(
97
            "TosDAO: setIncompatibleTosForRelease",
98
            $this->mysqli,
99
            "INSERT INTO game_release_tos_version_incompatibility (release_id, tos_id, language_id) VALUES (?, ?, ?)",
100
            "iis", $release_id, $tos, $language
101
        );
102
103
        $stmt->close();
104
    }
105
106
107
    /**
108
     * Update language for incompatible TOS
109
     *
110
     * @param integer Game Release ID
111
     * @param integer TOS ID
112
     */
113
    public function updateTosLanguageForRelease($game_release_id, $tos_id, $new_language_id) {
114
        $stmt = \AL\Db\execute_query(
115
            "TosDAO: updateTosLanguageForRelease",
116
            $this->mysqli,
117
            "UPDATE game_release_tos_version_incompatibility
118
            SET
119
                `language_id` = ?
120
            WHERE release_id = ? AND tos_id = ?",
121
            "sii", $new_language_id, $game_release_id, $tos_id
122
        );
123
124
        $stmt->close();
125
    }
126
127
128
    /**
129
     * Delete incompatible TOS for release
130
     *
131
     * @param integer Game Release ID
132
     * @param integer tos ID
133
     */
134
    public function deleteTosForRelease($game_release_id, $tos_id) {
135
        $stmt = \AL\Db\execute_query(
136
            "TosDAO: deleteTosForRelease",
137
            $this->mysqli,
138
            "DELETE FROM game_release_tos_version_incompatibility
139
            WHERE release_id = ? AND tos_id = ?",
140
            "ii", $game_release_id, $tos_id
141
        );
142
143
        $stmt->close();
144
    }
145
146
147
     /**
148
     * add a tos to the database
149
     *
150
     * @param varchar tos
151
     */
152
    public function addTos($tos) {
153
        $stmt = \AL\Db\execute_query(
154
            "TosDAO: addTos",
155
            $this->mysqli,
156
            "INSERT INTO tos (`name`) VALUES (?)",
157
            "s", $tos
158
        );
159
160
        $stmt->close();
161
    }
162
163
    /**
164
     * delete a tos version
165
     *
166
     * @param int tos_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\tos_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...
167
     */
168
    public function deleteTos($tos_id) {
169
        $stmt = \AL\Db\execute_query(
170
            "TosDAO: deleteTos",
171
            $this->mysqli,
172
            "DELETE FROM tos WHERE id = ?",
173
            "i", $tos_id
174
        );
175
176
        $stmt->close();
177
    }
178
179
     /**
180
     * update a tos version
181
     *
182
     * @param int tos_id
183
     * @param varchar tos_name
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\tos_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...
184
     */
185
    public function updateTos($tos_id, $tos_name) {
186
        $stmt = \AL\Db\execute_query(
187
            "TosDAO: updateTos",
188
            $this->mysqli,
189
            "UPDATE tos SET name = ? WHERE id = ?",
190
            "si", $tos_name, $tos_id
191
        );
192
193
        $stmt->close();
194
    }
195
}
196