MediaTypeDAO::updateMediaType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 9
rs 10
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/Dump/MediaType.php" ;
6
7
/**
8
 * DAO for Media Type
9
 */
10
class MediaTypeDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
    /**
18
     * Get all Media Types
19
     *
20
     * @return \AL\Common\Model\Dump\MediaType[] An array of media types
21
     */
22
    public function getAllMediaTypes() {
23
        $stmt = \AL\Db\execute_query(
24
            "MediaTypeDAO: getAllMediaTypes",
25
            $this->mysqli,
26
            "SELECT id, name FROM media_type ORDER BY name",
27
            null, null
28
        );
29
30
        \AL\Db\bind_result(
31
            "MediaTypeDAO: getAllMediaTypes",
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
        $media_types = [];
37
        while ($stmt->fetch()) {
38
            $media_types[] = new \AL\Common\Model\Dump\MediaType(
39
                $id, $name
40
            );
41
        }
42
43
        $stmt->close();
44
45
        return $media_types;
46
    }
47
48
     /**
49
     * add a media type to the database
50
     *
51
     * @param varchar media_type
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\media_type 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 addMediaType($media_type) {
54
        $stmt = \AL\Db\execute_query(
55
            "MediaTypeDAO: addMediaType",
56
            $this->mysqli,
57
            "INSERT INTO media_type (`name`) VALUES (?)",
58
            "s", $media_type
59
        );
60
61
        $stmt->close();
62
    }
63
    
64
    /**
65
     * delete a media_type
66
     *
67
     * @param int $media_type_id
68
     */
69
    public function deleteMediaType($media_type_id) {
70
        $stmt = \AL\Db\execute_query(
71
            "MediaTypeDAO: deleteMediaType",
72
            $this->mysqli,
73
            "DELETE FROM media_type WHERE id = ?",
74
            "i", $media_type_id
75
        );
76
77
        $stmt->close();
78
    }
79
    
80
        /**
81
     * update a media_type
82
     *
83
     * @param int media_type_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\media_type_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...
84
     * @param varchar media_type
85
     */
86
    public function updateMediaType($media_type_id, $media_type_name) {
87
        $stmt = \AL\Db\execute_query(
88
            "MediaTypeDAO: updateMediaType",
89
            $this->mysqli,
90
            "UPDATE media_type SET name = ? WHERE id = ?",
91
            "si", $media_type_name, $media_type_id
92
        );
93
        
94
        $stmt->close();
95
    }
96
}
97