PubDevDAO   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 163
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 88
dl 0
loc 163
rs 10
c 0
b 0
f 0
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A addDistributorToRelease() 0 9 1
A getPubDevsStartingWith() 0 33 2
A getPubDev() 0 33 2
A getDistributorsForRelease() 0 33 2
A getAllPubDevs() 0 2 1
A deleteDistributorFromRelease() 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/PubDev/PubDev.php" ;
6
7
/**
8
 * DAO for PubDev
9
 */
10
class PubDevDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
    public function getAllPubDevs() {
18
        return $this->getPubDevsStartingWith(".");
19
    }
20
    /**
21
     * Get all publishers and developers
22
     * @return \AL\Common\Model\PubDev\PubDev[] A list of PubDevs
23
     */
24
    public function getPubDevsStartingWith($regexp) {
25
        $stmt = \AL\Db\execute_query(
26
            "PubDevDAO: getAllPubDev",
27
            $this->mysqli,
28
            "SELECT
29
                pub_dev.pub_dev_id,
30
                pub_dev.pub_dev_name,
31
                pub_dev_text.pub_dev_profile,
32
                pub_dev_text.pub_dev_imgext
33
            FROM
34
                pub_dev
35
            LEFT JOIN pub_dev_text ON pub_dev_text.pub_dev_id = pub_dev.pub_dev_id
36
            WHERE LOWER(pub_dev.pub_dev_name) REGEXP ?
37
            ORDER BY pub_dev.pub_dev_name ASC",
38
            "s", strtolower($regexp)
39
        );
40
41
        \AL\Db\bind_result(
42
            "PubDevDAO: getAllPubDev",
43
            $stmt,
44
            $id, $name, $profile, $imgext
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $imgext seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $name seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $profile seems to be never defined.
Loading history...
45
        );
46
47
        $pubdevs = [];
48
        while ($stmt->fetch()) {
49
            $pubdevs[] = new \AL\Common\Model\PubDev\PubDev(
50
                $id, $name, $profile, $imgext
51
            );
52
        }
53
54
        $stmt->close();
55
56
        return $pubdevs;
57
    }
58
59
    /**
60
     * Get a publisher or developer
61
     * @param number $id ID of the pubdev to retrieve
62
     * @return \AL\Common\Model\PubDev\PubDev PubDev, or NULL if not found
63
     */
64
    public function getPubDev($id) {
65
        $stmt = \AL\Db\execute_query(
66
            "PubDevDAO: getPubDev",
67
            $this->mysqli,
68
            "SELECT
69
                pub_dev.pub_dev_id,
70
                pub_dev.pub_dev_name,
71
                pub_dev_text.pub_dev_profile,
72
                pub_dev_text.pub_dev_imgext
73
            FROM
74
                pub_dev
75
            LEFT JOIN pub_dev_text ON pub_dev_text.pub_dev_id = pub_dev.pub_dev_id
76
            WHERE pub_dev.pub_dev_id = ?
77
            ORDER BY pub_dev.pub_dev_name ASC",
78
            "i", $id
79
        );
80
81
        \AL\Db\bind_result(
82
            "PubDevDAO: getPubDev",
83
            $stmt,
84
            $id, $name, $profile, $imgext
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $profile seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $imgext seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $name seems to be never defined.
Loading history...
85
        );
86
87
        $pubdev = null;
88
        if ($stmt->fetch()) {
89
            $pubdev = new \AL\Common\Model\PubDev\PubDev(
90
                $id, $name, $profile, $imgext
91
            );
92
        }
93
94
        $stmt->close();
95
96
        return $pubdev;
97
    }
98
    
99
    
100
    /**
101
     * Get list of distributors for a game_release
102
     *
103
     * @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...
104
     */
105
    public function getDistributorsForRelease($game_release_id) {
106
        $stmt = \AL\Db\execute_query(
107
            "PubDevDAO: getDistributorsForRelease",
108
            $this->mysqli,
109
            "SELECT
110
                pub_dev.pub_dev_id,
111
                pub_dev.pub_dev_name,
112
                pub_dev_text.pub_dev_profile,
113
                pub_dev_text.pub_dev_imgext
114
            FROM
115
                pub_dev
116
            LEFT JOIN pub_dev_text ON pub_dev_text.pub_dev_id = pub_dev.pub_dev_id
117
            LEFT JOIN game_release_distributor ON pub_dev.pub_dev_id = game_release_distributor.pub_dev_id
118
            WHERE game_release_distributor.game_release_id = ?",
119
            "i", $game_release_id
120
        );
121
122
        \AL\Db\bind_result(
123
            "PubDevDAO: getDistributorsForRelease",
124
            $stmt,
125
            $id, $name, $profile, $imgext
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 $imgext seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $profile seems to be never defined.
Loading history...
126
        );
127
128
        $distributors = [];
129
        while ($stmt->fetch()) {
130
            $distributors[] = new \AL\Common\Model\PubDev\PubDev(
131
                $id, $name, $profile, $imgext
132
            );
133
        }
134
135
        $stmt->close();
136
137
        return $distributors;
138
    }
139
    
140
      /**
141
     * add a distributor to a release
142
     *
143
     * @param integer release ID
144
     * @param integer pub_Dev ID
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\pub_Dev 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...
145
     */
146
    public function addDistributorToRelease($release_id, $pub_dev_id) {
147
        $stmt = \AL\Db\execute_query(
148
            "PubDevDAO: addDistributorToRelease",
149
            $this->mysqli,
150
            "INSERT INTO game_release_distributor (game_release_id, pub_dev_id) VALUES (?, ?)",
151
            "ii", $release_id, $pub_dev_id
152
        );
153
154
        $stmt->close();
155
    }
156
    
157
    
158
    /**
159
     * delete a distributor from a release
160
     *
161
     * @param int release_id
162
     * @param int pub_dv_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\pub_dv_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...
163
     */
164
    public function deleteDistributorFromRelease($release_id, $pub_dev_id) {
165
        $stmt = \AL\Db\execute_query(
166
            "PubDevDAO: deleteDistributorFromRelease",
167
            $this->mysqli,
168
            "DELETE FROM game_release_distributor WHERE game_release_id = ? and pub_dev_id = ?",
169
            "ii", $release_id, $pub_dev_id
170
        );
171
172
        $stmt->close();
173
    }
174
}
175