DeveloperRoleDAO::getRoleForId()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 17
nc 2
nop 1
dl 0
loc 26
rs 9.7
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/PubDev/DeveloperRole.php" ;
6
7
/**
8
 * DAO for Developer Roles
9
 */
10
class DeveloperRoleDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
    /**
18
     * Get all Roles
19
     *
20
     * @return \AL\Common\Model\PubDev\DeveloperRole[] An array of roles
21
     */
22
    public function getAllDeveloperRoles() {
23
        $stmt = \AL\Db\execute_query(
24
            "DeveloperRoleDAO: getAllDeveloperRoles",
25
            $this->mysqli,
26
            "SELECT id, name FROM developer_role ORDER BY name",
27
            null, null
28
        );
29
30
        \AL\Db\bind_result(
31
            "DeveloperRoleDAO: getAllDeveloperRoles",
32
            $stmt,
33
            $id, $role
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $role seems to be never defined.
Loading history...
34
        );
35
36
        $developer_roles = [];
37
        while ($stmt->fetch()) {
38
            $developer_roles[] = new \AL\Common\Model\PubDev\DeveloperRole(
39
                $id, $role
40
            );
41
        }
42
43
        $stmt->close();
44
45
        return $developer_roles;
46
    }
47
48
    /**
49
     * Get role for a role id
50
     *
51
     * @param integer role ID
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\role 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 getRoleForId($id) {
54
        $stmt = \AL\Db\execute_query(
55
            "DeveloperRoleDAO: getRoleForId",
56
            $this->mysqli,
57
            "SELECT id, name
58
            FROM developer_role
59
            WHERE id = ?",
60
            "i", $id
61
        );
62
63
        \AL\Db\bind_result(
64
            "DeveloperRoleDAO: getRoleForId",
65
            $stmt,
66
            $id, $role
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $role seems to be never defined.
Loading history...
67
        );
68
69
        $developer_roles = null;
70
        while ($stmt->fetch()) {
71
            $developer_roles = new \AL\Common\Model\PubDev\DeveloperRole(
72
                $id, $role
73
            );
74
        }
75
76
        $stmt->close();
77
78
        return $developer_roles;
79
    }
80
81
    /**
82
     * add a role to the database
83
     *
84
     * @param varchar role
85
     */
86
    public function addDeveloperRole($role) {
87
        $stmt = \AL\Db\execute_query(
88
            "DeveloperRoleDAO: addDeveloperRole",
89
            $this->mysqli,
90
            "INSERT INTO developer_role (`name`) VALUES (?)",
91
            "s", $role
92
        );
93
94
        $stmt->close();
95
    }
96
97
    /**
98
     * delete a role
99
     *
100
     * @param int role_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\role_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...
101
     */
102
    public function deleteDeveloperRole($role_id) {
103
        $stmt = \AL\Db\execute_query(
104
            "DeveloperRoleDAO: deleteDeveloperRole",
105
            $this->mysqli,
106
            "DELETE FROM developer_role WHERE id = ?",
107
            "i", $role_id
108
        );
109
110
        $stmt->close();
111
    }
112
113
        /**
114
     * update a role
115
     *
116
     * @param int role_id
117
     * @param varchar role_name
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\role_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...
118
     */
119
    public function updateDeveloperRole($role_id, $role_name) {
120
        $stmt = \AL\Db\execute_query(
121
            "DeveloperRoleDAO: updateDeveloperRole",
122
            $this->mysqli,
123
            "UPDATE developer_role SET name = ? WHERE id = ?",
124
            "si", $role_name, $role_id
125
        );
126
127
        $stmt->close();
128
    }
129
}
130