CopyProtectionDAO   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 156
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 67
dl 0
loc 156
rs 10
c 0
b 0
f 0
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteCopyProtectionForRelease() 0 10 1
A __construct() 0 2 1
A addCopyProtectionForRelease() 0 10 1
A getAllCopyProtections() 0 24 2
A getCopyProtectionsForRelease() 0 27 2
A addCopyProtection() 0 9 1
A updateCopyProtection() 0 9 1
A deleteCopyProtection() 0 9 1
1
<?php
2
namespace AL\Common\DAO;
3
4
require_once __DIR__."/../../lib/Db.php" ;
5
require_once __DIR__."/../Model/Game/CopyProtection.php" ;
6
7
/**
8
 * DAO for Copy Protection
9
 */
10
class CopyProtectionDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
    /**
18
     * Get all Copy Protection Types
19
     *
20
     * @return \AL\Common\Model\Game\CopyProtection[] An array of copy protection types
21
     */
22
    public function getAllCopyProtections() {
23
        $stmt = \AL\Db\execute_query(
24
            "CopyProtectionDAO: getAllCopyProtections",
25
            $this->mysqli,
26
            "SELECT id, name FROM copy_protection ORDER BY name",
27
            null, null
28
        );
29
30
        \AL\Db\bind_result(
31
            "CopyProtectionDAO: getAllCopyProtections",
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
        $copy_protection_types = [];
37
        while ($stmt->fetch()) {
38
            $copy_protection_types[] = new \AL\Common\Model\Game\CopyProtection(
39
                $id, $name, null
40
            );
41
        }
42
43
        $stmt->close();
44
45
        return $copy_protection_types;
46
    }
47
48
    /**
49
     * Get list of copy_protection IDs for a game 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
     */
53
    public function getCopyProtectionsForRelease($release_id) {
54
        $stmt = \AL\Db\execute_query(
55
            "CopyProtectionDAO: getCopyProtectionsForRelease",
56
            $this->mysqli,
57
            "SELECT copy_protection_id, name, notes
58
            FROM game_release_copy_protection LEFT JOIN 
59
            copy_protection ON (game_release_copy_protection.copy_protection_id = copy_protection.id)
60
            WHERE release_id = ?",
61
            "i", $release_id
62
        );
63
64
        \AL\Db\bind_result(
65
            "CopyProtectionDAO: getCopyProtectionsForRelease",
66
            $stmt,
67
            $copy_protection_id, $name, $notes
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 $notes seems to be never defined.
Loading history...
68
        );
69
70
        $copy_protection_types = [];
71
        while ($stmt->fetch()) {
72
            $copy_protection_types[] = new \AL\Common\Model\Game\CopyProtection(
73
                $copy_protection_id, $name, $notes
74
            );
75
        }
76
77
        $stmt->close();
78
79
        return $copy_protection_types;
80
    }
81
    
82
     /**
83
     * Add copy Protection for release
84
     *
85
     * @param integer Game Release ID
86
     * @param integer protection ID
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\protection 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...
87
     * $param text note
88
     */
89
    public function addCopyProtectionForRelease($game_release_id, $protection_id, $note) {
90
       
91
        $stmt = \AL\Db\execute_query(
92
            "copyProtectionDAO: addCopyProtectionForRelease",
93
            $this->mysqli,
94
            "INSERT INTO game_release_copy_protection (release_id, copy_protection_id, notes) VALUES (?, ?, ?)",
95
            "iis", $game_release_id, $protection_id, $note
96
        );
97
98
        $stmt->close();
99
    }
100
    
101
     /**
102
     * Delete copy Protection for release
103
     *
104
     * @param integer Game Release ID
105
     * @param integer protection ID
106
     */
107
    public function deleteCopyProtectionForRelease($game_release_id, $protection_id) {
108
        $stmt = \AL\Db\execute_query(
109
            "copyProtectionDAO: deleteCopyProtectionForRelease",
110
            $this->mysqli,
111
            "DELETE FROM game_release_copy_protection
112
            WHERE release_id = ? AND copy_protection_id = ?",
113
            "ii", $game_release_id, $protection_id
114
        );
115
116
        $stmt->close();
117
    }
118
     
119
     /**
120
     * add a copy protection to the database
121
     *
122
     * @param varchar copy_protection
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\copy_protection 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 addCopyProtection($copy_protection) {
125
        $stmt = \AL\Db\execute_query(
126
            "CopyProtectionDAO: addCopyProtection",
127
            $this->mysqli,
128
            "INSERT INTO copy_protection (`name`) VALUES (?)",
129
            "s", $copy_protection
130
        );
131
132
        $stmt->close();
133
    }
134
    
135
    /**
136
     * delete a copy_protection
137
     *
138
     * @param int $copy_protection_id
139
     */
140
    public function deleteCopyProtection($copy_protection_id) {
141
        $stmt = \AL\Db\execute_query(
142
            "CopyProtectionDAO: deleteCopyProtection",
143
            $this->mysqli,
144
            "DELETE FROM copy_protection WHERE id = ?",
145
            "i", $copy_protection_id
146
        );
147
148
        $stmt->close();
149
    }
150
    
151
        /**
152
     * update a copy_protection
153
     *
154
     * @param int copy_protection_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\copy_protection_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...
155
     * @param varchar copy_protection
156
     */
157
    public function updateCopyProtection($copy_protection_id, $copy_protection_name) {
158
        $stmt = \AL\Db\execute_query(
159
            "CopyProtectionDAO: updateCopyProtection",
160
            $this->mysqli,
161
            "UPDATE copy_protection SET name = ? WHERE id = ?",
162
            "si", $copy_protection_name, $copy_protection_id
163
        );
164
        
165
        $stmt->close();
166
    }
167
}
168