GameProgressSystemDAO   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 140
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 62
dl 0
loc 140
rs 10
c 0
b 0
f 0
wmc 9

7 Methods

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