EnhancementDAO   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 85
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A updateEnhancement() 0 9 1
A getAllEnhancements() 0 24 2
A addEnhancement() 0 9 1
A deleteEnhancement() 0 9 1
1
<?php
2
namespace AL\Common\DAO;
3
4
require_once __DIR__."/../../lib/Db.php" ;
5
require_once __DIR__."/../Model/Game/Enhancement.php" ;
6
7
/**
8
 * DAO for ports
9
 */
10
class EnhancementDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
    /**
18
     * Get all Enhancements
19
     *
20
     * @return "/../Model/game/Enhancement[] An array of Enhancements
0 ignored issues
show
Documentation Bug introduced by
The doc comment "/../Model/game/Enhancement[] at position 0 could not be parsed: Unknown type name '"/../Model/game/Enhancement' at position 0 in "/../Model/game/Enhancement[].
Loading history...
21
     */
22
    public function getAllEnhancements() {
23
        $stmt = \AL\Db\execute_query(
24
            "EnhancementDAO: getAllEnhancements",
25
            $this->mysqli,
26
            "SELECT id, name FROM enhancement ORDER BY name",
27
            null, null
28
        );
29
30
        \AL\Db\bind_result(
31
            "EnhancementDAO: getAllEnhancements",
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
        $enhancements = [];
37
        while ($stmt->fetch()) {
38
            $enhancements[] = new \AL\Common\Model\Game\Enhancement(
39
                $id, $name
40
            );
41
        }
42
43
        $stmt->close();
44
45
        return $enhancements;
46
    }
47
    
48
    /**
49
     * add an enhancement to the database
50
     *
51
     * @param varchar enhancement
52
     */
53
    public function addEnhancement($enhancement) {
54
        $stmt = \AL\Db\execute_query(
55
            "EnhancementDAO: addEnhancement",
56
            $this->mysqli,
57
            "INSERT INTO enhancement (`name`) VALUES (?)",
58
            "s", $enhancement
59
        );
60
61
        $stmt->close();
62
    }
63
    
64
    /**
65
     * delete a Enhancement
66
     *
67
     * @param int Enhancement_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\Enhancement_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...
68
     */
69
    public function deleteEnhancement($enhancement_id) {
70
        $stmt = \AL\Db\execute_query(
71
            "EnhancementDAO: deleteEnhancement",
72
            $this->mysqli,
73
            "DELETE FROM enhancement WHERE id = ?",
74
            "s", $enhancement_id
75
        );
76
77
        $stmt->close();
78
    }
79
    
80
        /**
81
     * update a Enhancement
82
     *
83
     * @param int Enhancement_id
84
     * @param varchar Enhancement_name
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\Enhancement_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...
85
     */
86
    public function updateEnhancement($enhancement_id, $enhancement_name) {
87
        $stmt = \AL\Db\execute_query(
88
            "EnhancementDAO: updateEnhancement",
89
            $this->mysqli,
90
            "UPDATE enhancement SET name = ? WHERE id = ?",
91
            "ss", $enhancement_name, $enhancement_id
92
        );
93
        
94
        $stmt->close();
95
    }
96
}
97