LocationDAO   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 74
dl 0
loc 150
rs 10
c 0
b 0
f 0
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllLocations() 0 26 2
A getAllLocationsAsMap() 0 8 2
A getLocationsForRelease() 0 28 2
A setLocationsForRelease() 0 18 2
A getLocationsIdsForRelease() 0 26 2
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/Location/Location.php" ;
6
7
/**
8
 * DAO for Locations
9
 */
10
class LocationDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
    /**
18
     * Get all locations
19
     *
20
     * @return \AL\Common\Model\Location\Location[] A list of locations
21
     */
22
    public function getAllLocations() {
23
        $stmt = \AL\Db\execute_query(
24
            "LocationDAO: getAllLocations",
25
            $this->mysqli,
26
            "SELECT id, continent_code, name, country_iso2, country_iso3, type
27
            FROM location
28
            ORDER by continent_code, type, name",
29
            null, null
30
        );
31
32
        \AL\Db\bind_result(
33
            "LocationDAO: getAllLocations",
34
            $stmt,
35
            $id, $continent_code, $name, $country_iso2, $country_iso3, $type
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $country_iso2 seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $continent_code 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 $type seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $country_iso3 seems to be never defined.
Loading history...
36
        );
37
38
        $locations = [];
39
        while ($stmt->fetch()) {
40
            $locations[] = new \AL\Common\Model\Location\Location(
41
                $id, $continent_code, $name, $country_iso2, $country_iso3, $type
42
            );
43
        }
44
45
        $stmt->close();
46
47
        return $locations;
48
    }
49
50
    /**
51
     * Get all the locations IDs for a game release
52
     *
53
     * @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...
54
     * @return \AL\Common\Model\Location\Location[] A list of locations
55
     */
56
    public function getLocationsIdsForRelease($release_id) {
57
        $stmt = \AL\Db\execute_query(
58
            "LocationDAO: getLocationsIdsForRelease",
59
            $this->mysqli,
60
            "SELECT location_id
61
            FROM game_release_location
62
            LEFT JOIN location on location.id = game_release_location.location_id
63
            WHERE game_release_id = ?
64
            ORDER by continent_code, type, name",
65
            "i", $release_id
66
        );
67
68
        \AL\Db\bind_result(
69
            "LocationDAO: getLocationsIdsForRelease",
70
            $stmt,
71
            $location_id
72
        );
73
74
        $locations = [];
75
        while ($stmt->fetch()) {
76
            $locations[] = $location_id;
77
        }
78
79
        $stmt->close();
80
81
        return $locations;
82
    }
83
84
    /**
85
     * Get all the locations for a release
86
     *
87
     * @param integer Release ID
88
     * @return \AL\Common\Model\Location\Location[] A list of locations
89
     */
90
    public function getLocationsForRelease($release_id) {
91
        $stmt = \AL\Db\execute_query(
92
            "LocationDAO: getLocationsIdsForRelease",
93
            $this->mysqli,
94
            "SELECT location.id, continent_code, name, country_iso2, country_iso3, type
95
            FROM game_release_location
96
            LEFT JOIN location on location.id = game_release_location.location_id
97
            WHERE game_release_id = ?
98
            ORDER by continent_code, type, name",
99
            "i", $release_id
100
        );
101
102
        \AL\Db\bind_result(
103
            "LocationDAO: getLocationsIdsForRelease",
104
            $stmt,
105
            $id, $continent_code, $name, $country_iso2, $country_iso3, $type
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $country_iso2 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 $country_iso3 seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $continent_code seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $type seems to be never defined.
Loading history...
106
        );
107
108
        $locations = [];
109
        while ($stmt->fetch()) {
110
            $locations[] = new \AL\Common\Model\Location\Location(
111
                $id, $continent_code, $name, $country_iso2, $country_iso3, $type
112
            );
113
        }
114
115
        $stmt->close();
116
117
        return $locations;
118
    }
119
120
    /**
121
     * Set the list of locations a release was released in
122
     *
123
     * @param integer Release ID
124
     * @param integer[] List of location IDs
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\List 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...
125
     * @return \AL\Common\Model\Location\Location[] A list of locations
126
     */
127
    public function setLocationsForRelease($release_id, $locations) {
128
        $stmt = \AL\Db\execute_query(
129
            "LocationDAO: setLocationsForRelease",
130
            $this->mysqli,
131
            "DELETE FROM game_release_location WHERE game_release_id = ?",
132
            "i", $release_id
133
        );
134
135
        foreach ($locations as $id) {
136
            $stmt = \AL\Db\execute_query(
137
                "LocationDAO: setLocationsForRelease",
138
                $this->mysqli,
139
                "INSERT INTO game_release_location (game_release_id, location_id) VALUES (?, ?)",
140
                "ii", $release_id, $id
141
            );
142
        }
143
144
        $stmt->close();
145
    }
146
147
    /**
148
     * Get a map containing all locations, indexed by ID
149
     *
150
     * @return \AL\Common\Model\Location\Location[] A map of locations
151
     */
152
    public function getAllLocationsAsMap() {
153
        $locations = $this->getAllLocations();
154
        $locationsMap = array();
155
        foreach ($locations as $location) {
156
            $locationsMap[$location->getId()] = $location;
157
        }
158
159
        return $locationsMap;
160
    }
161
}
162