Failed Conditions
Pull Request — master (#353)
by Florian
03:03
created

QueryManagerMonocleHydro::testTotalGyms()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 11

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 3
nop 0
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class QueryManagerMonocleHydro extends QueryManagerMysql
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
	public function __construct()
7
	{
8
		parent::__construct();
9
	}
10
11
	///////////
12
	// Tester
13
	///////////
14
15 View Code Duplication
	function testTotalPokemon() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for testTotalPokemon.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
16
		$req = "SELECT COUNT(*) as total FROM sightings";
17
		$result = $this->mysqli->query($req);
18
		if (!is_object($result)) {
19
			return 1;
20
		} else {
21
			$data = $result->fetch_object();
22
			$total = $data->total;
23
24
			if ($total == 0) {
25
				return 2;
26
			}
27
		}
28
		return 0;
29
	}
30
31 View Code Duplication
	function testTotalGyms() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for testTotalGyms.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
32
		$req = "SELECT COUNT(*) as total FROM forts";
33
		$result = $this->mysqli->query($req);
34
		if (!is_object($result)) {
35
			return 1;
36
		} else {
37
			$data = $result->fetch_object();
38
			$total = $data->total;
39
40
			if ($total == 0) {
41
				return 2;
42
			}
43
		}
44
		return 0;
45
	}
46
47 View Code Duplication
	function testTotalPokestops() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for testTotalPokestops.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
48
		$req = "SELECT COUNT(*) as total FROM pokestops";
49
		$result = $this->mysqli->query($req);
50
		if (!is_object($result)) {
51
			return 1;
52
		} else {
53
			$data = $result->fetch_object();
54
			$total = $data->total;
55
56
			if ($total == 0) {
57
				return 2;
58
			}
59
		}
60
		return 0;
61
	}
62
	
63
	
64
	/////////////
65
	// Homepage
66
	/////////////
67
68
	function getTotalPokemon() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTotalPokemon.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
69
		$req = "SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP()";
70
		$result = $this->mysqli->query($req);
71
		$data = $result->fetch_object();
72
		return $data;
73
	}
74
75
	function getTotalLures() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTotalLures.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
76
		$data = (object) array("total" => 0);
77
		return $data;
78
	}
79
80
	function getTotalGyms() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTotalGyms.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
81
		$req = "SELECT COUNT(*) AS total FROM forts";
82
		$result = $this->mysqli->query($req);
83
		$data = $result->fetch_object();
84
		return $data;
85
	}
86
87
	function getTotalRaids() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTotalRaids.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
88
		$req = "SELECT COUNT(*) AS total FROM raids WHERE time_battle <= UNIX_TIMESTAMP() AND time_end >= UNIX_TIMESTAMP()";
89
		$result = $this->mysqli->query($req);
90
		$data = $result->fetch_object();
91
		return $data;
92
	}
93
94
95
	function getTotalGymsForTeam($team_id) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTotalGymsForTeam.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
96
		$req = "SELECT COUNT(*) AS total FROM fort_sightings WHERE team = '$team_id'";
97
		$result = $this->mysqli->query($req);
98
		$data = $result->fetch_object();
99
		return $data;
100
	}
101
102
	function getRecentAll() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getRecentAll.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
103
		$req = "SELECT DISTINCT pokemon_id, encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated+0) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
104
              lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina
105
              FROM sightings
106
              ORDER BY last_modified DESC
107
              LIMIT 0,12";
108
		$result = $this->mysqli->query($req);
109
		$data = array();
110
		if ($result->num_rows > 0) {
111
			while ($row = $result->fetch_object()) {
112
				$data[] = $row;
113
			}
114
		}
115
		return $data;
116
	}
117
118
	function getRecentMythic($mythic_pokemon) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getRecentMythic.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
119
		$req = "SELECT DISTINCT pokemon_id as pokemon_id, CONCAT('A', encounter_id) as encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated+0) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
120
                lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina
121
                FROM sightings
122
                WHERE pokemon_id+0 IN (".implode(",", $mythic_pokemon).")
123
                ORDER BY last_modified DESC
124
                LIMIT 0,12";
125
		$result = $this->mysqli->query($req);
126
		$data = array();
127
		if ($result->num_rows > 0) {
128
			while ($row = $result->fetch_object()) {
129
				$data[] = $row;
130
			}
131
		}
132
		return $data;
133
	}
134
135
	///////////////////
136
	// Single Pokemon
137
	///////////////////
138
139 View Code Duplication
	function getGymsProtectedByPokemon($pokemon_id) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getGymsProtectedByPokemon.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
140
		$req = "SELECT COUNT(DISTINCT(fort_id)) AS total FROM fort_sightings WHERE guard_pokemon_id = '".$pokemon_id."'";
141
		$result = $this->mysqli->query($req);
142
		$data = $result->fetch_object();
143
		return $data;
144
	}
145
146 View Code Duplication
	function getPokemonLastSeen($pokemon_id) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getPokemonLastSeen.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
147
		$req = "SELECT FROM_UNIXTIME(expire_timestamp) AS expire_timestamp, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude
148
                FROM sightings
149
                WHERE pokemon_id = '".$pokemon_id."'
150
                ORDER BY expire_timestamp DESC
151
                LIMIT 0,1";
152
		$result = $this->mysqli->query($req);
153
		$data = $result->fetch_object();
154
		return $data;
155
	}
156
157
	function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTop50Pokemon.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
158
		$req = "SELECT FROM_UNIXTIME(expire_timestamp+0) AS distime, pokemon_id+0 as pokemon_id, FROM_UNIXTIME(expire_timestamp+0) as disappear_time, lat as latitude, lon as longitude,
159
                cp, atk_iv+0 as individual_attack, def_iv+0 as individual_defense, sta_iv+0 as individual_stamina,
160
                ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS IV, move_1+0 as move_1, move_2, form
161
                FROM sightings
162
	            WHERE pokemon_id+0 = '" . $pokemon_id . "' AND move_1+0 IS NOT NULL AND move_1+0 <> '0'
163
	            GROUP BY encounter_id+0
164
	            ORDER BY $top_order_by $top_direction, expire_timestamp+0 DESC
165
	            LIMIT 0,50";
166
167
		$result = $this->mysqli->query($req);
168
		$top = array();
169
		while ($data = $result->fetch_object()) {
170
			$top[] = $data;
171
		}
172
		return $top;
173
	}
174
175 View Code Duplication
	function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTop50Trainers.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
176
		$trainer_blacklist = "";
177
		if (!empty(self::$config->system->trainer_blacklist)) {
178
			$trainer_blacklist = " AND owner_name NOT IN ('" . implode("','", self::$config->system->trainer_blacklist) . "')";
179
		}
180
181
		$req = "SELECT owner_name as trainer_name, ROUND(SUM(100*((atk_iv+0)+(def_iv+0)+(sta_iv+0))/45),1) AS IV, move_1, move_2, cp+0 as cp,
182
                FROM_UNIXTIME(last_modified+0) AS lasttime, last_modified+0 as last_seen
183
                FROM gym_defenders
184
				WHERE pokemon_id+0 = '" . $pokemon_id . "'" . $trainer_blacklist . "
185
				GROUP BY external_id
186
				ORDER BY $best_order_by $best_direction, owner_name+'' ASC
187
				LIMIT 0,50";
188
189
		$result = $this->mysqli->query($req);
190
		$toptrainer = array();
191
		while ($data = $result->fetch_object()) {
192
			$toptrainer[] = $data;
193
		}
194
		return $toptrainer;
195
	}
196
197 View Code Duplication
	public  function getPokemonHeatmap($pokemon_id, $start, $end) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
198
		$where = " WHERE pokemon_id = ".$pokemon_id." "
199
			. "AND FROM_UNIXTIME(expire_timestamp) BETWEEN '".$start."' AND '".$end."'";
200
		$req 		= "SELECT lat AS latitude, lon AS longitude FROM sightings".$where." ORDER BY expire_timestamp DESC LIMIT 100000";
201
		$result = $this->mysqli->query($req);
202
		$points = array();
203
		while ($data = $result->fetch_object()) {
204
			$points[] = $data;
205
		}
206
		return $points;
207
	}
208
209 View Code Duplication
	public function getPokemonGraph($pokemon_id) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
210
		$req = "SELECT COUNT(*) AS total, HOUR(disappear_time) AS disappear_hour
211
					FROM (SELECT FROM_UNIXTIME(expire_timestamp) as disappear_time FROM sightings WHERE pokemon_id = '".$pokemon_id."' ORDER BY disappear_time LIMIT 100000) AS pokemonFiltered
212
				GROUP BY disappear_hour
213
				ORDER BY disappear_hour";
214
		$result = $this->mysqli->query($req);
215
		$array = array_fill(0, 24, 0);
216
		while ($result && $data = $result->fetch_object()) {
217
			$array[$data->disappear_hour] = $data->total;
218
		}
219
		// shift array because AM/PM starts at 1AM not 0:00
220
		$array[] = $array[0];
221
		array_shift($array);
222
		return $array;
223
	}
224
225 View Code Duplication
	public  function getPokemonLive($pokemon_id, $ivMin, $ivMax) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
getPokemonLive uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
226
		$inmap_pkms_filter = "";
227
		$where = " WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = " . $pokemon_id;
228
229
		$reqTestIv = "SELECT MAX(atk_iv) AS iv FROM sightings " . $where;
230
		$resultTestIv = $this->mysqli->query($reqTestIv);
231
		$testIv = $resultTestIv->fetch_object();
232
		if (isset($_POST['inmap_pokemons']) && ($_POST['inmap_pokemons'] != "")) {
233
			foreach ($_POST['inmap_pokemons'] as $inmap) {
234
				$inmap_pkms_filter .= "'".$inmap."',";
235
			}
236
			$inmap_pkms_filter = rtrim($inmap_pkms_filter, ",");
237
			$where .= " AND encounter_id NOT IN (" . $inmap_pkms_filter . ") ";
238
		}
239
		if ($testIv->iv != null && isset($_POST['ivMin']) && ($_POST['ivMin'] != "")) {
240
			$where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= (" . $ivMin . ") ";
241
		}
242
		if ($testIv->iv != null && isset($_POST['ivMax']) && ($_POST['ivMax'] != "")) {
243
			$where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= (" . $ivMax . ") ";
244
		}
245
		$req = "SELECT pokemon_id, lat AS latitude, lon AS longitude,
246
    					FROM_UNIXTIME(expire_timestamp) AS disappear_time,
247
    					FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
248
    					atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina,
249
   						move_1, move_2
250
					FROM sightings " . $where . "
251
					ORDER BY disappear_time DESC
252
					LIMIT 5000";
253
		$result = $this->mysqli->query($req);
254
		$spawns = array();
255
		while ($data = $result->fetch_object()) {
256
			$spawns[] = $data;
257
		}
258
		return $spawns;
259
	}
260
261
	public function getPokemonSliederMinMax() {
262
		$req = "SELECT FROM_UNIXTIME(MIN(expire_timestamp)) AS min, FROM_UNIXTIME(MAX(expire_timestamp)) AS max FROM sightings";
263
		$result = $this->mysqli->query($req);
264
		$data = $result->fetch_object();
265
		return $data;
266
	}
267
268
	public function getMapsCoords() {
269
		$req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints";
270
		$result = $this->mysqli->query($req);
271
		$data = $result->fetch_object();
272
		return $data;
273
	}
274
275
276
	///////////////
277
	// Pokestops
278
	//////////////
279
280
281
	function getTotalPokestops() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTotalPokestops.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
282
		$req = "SELECT COUNT(*) as total FROM pokestops";
283
		$result = $this->mysqli->query($req);
284
		$data = $result->fetch_object();
285
		return $data;
286
	}
287
288
	public  function getAllPokestops() {
0 ignored issues
show
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
289
		$req = "SELECT lat as latitude, lon as longitude, null AS lure_expiration, UNIX_TIMESTAMP() AS now, null AS lure_expiration_real FROM pokestops";
290
		$result = $this->mysqli->query($req);
291
		$pokestops = array();
292
		while ($data = $result->fetch_object()) {
293
			$pokestops[] = $data;
294
		}
295
		return $pokestops;
296
	}
297
298
299
	/////////
300
	// Gyms
301
	/////////
302
303
	function getTeamGuardians($team_id) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getTeamGuardians.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
304
		$req = "SELECT COUNT(*) AS total, guard_pokemon_id FROM fort_sightings WHERE team = '".$team_id."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 0,3";
305
		$result = $this->mysqli->query($req);
306
307
		$datas = array();
308
		while ($data = $result->fetch_object()) {
309
			$datas[] = $data;
310
		}
311
312
		return $datas;
313
	}
314
315
	function getOwnedAndPoints($team_id) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getOwnedAndPoints.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
316
		$req = "SELECT COUNT(DISTINCT(fs.fort_id)) AS total, ROUND((SUM(gd.cp)) / COUNT(DISTINCT(fs.fort_id)),0) AS average_points
317
        			FROM fort_sightings fs
318
        			JOIN gym_defenders gd ON fs.fort_id = gd.fort_id
319
        			WHERE fs.team = '" . $team_id . "'";
320
		$result = $this->mysqli->query($req);
321
		$data = $result->fetch_object();
322
		return $data;
323
	}
324
325
	function getAllGyms() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for getAllGyms.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
326
		$req = "SELECT f.id as gym_id, team as team_id, f.lat as latitude, f.lon as longitude, updated as last_scanned, (6 - fs.slots_available) AS level FROM forts f LEFT JOIN fort_sightings fs ON f.id = fs.fort_id;";
327
		$result = $this->mysqli->query($req);
328
		$gyms = array();
329
		while ($data = $result->fetch_object()) {
330
			$gyms[] = $data;
331
		}
332
		return $gyms;
333
	}
334
335
	public function getGymData($gym_id) {
0 ignored issues
show
Coding Style introduced by
getGymData uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
336
		$gym_id = $this->mysqli->real_escape_string($_GET['gym_id']);
337
		$req = "SELECT f.name AS name, null AS description, f.url AS url, fs.team AS team, FROM_UNIXTIME(fs.updated) AS last_scanned, fs.guard_pokemon_id AS guard_pokemon_id, (6 - fs.slots_available) AS level, SUM(gd.cp) as total_cp	
338
			FROM fort_sightings fs
339
			LEFT JOIN forts f ON f.id = fs.fort_id
340
			JOIN gym_defenders gd ON f.id = gd.fort_id
341
			WHERE f.id ='".$gym_id."'";
342
		$result = $this->mysqli->query($req);
343
		$data = $result->fetch_object();
344
		return $data;
345
	}
346
347
	public function getGymDefenders($gym_id) {
348
		$req = "SELECT DISTINCT external_id as pokemon_uid, pokemon_id, atk_iv as iv_attack, def_iv as iv_defense, sta_iv as iv_stamina, cp, fort_id as gym_id
349
			FROM gym_defenders 
350
			WHERE fort_id='".$gym_id."'
351
			ORDER BY cp DESC";
352
		$result = $this->mysqli->query($req);
353
		$defenders = array();
354
		while ($data = $result->fetch_object()) {
355
			$defenders[] = $data;
356
		}
357
		return $defenders;
358
	}
359
360
361
	///////////
362
	// Raids
363
	///////////
364
365
	public function getAllRaids($page) {
366
		$limit = " LIMIT ".($page * 10).",10";
367
		$req = "SELECT r.fort_id AS gym_id, r.level AS level, r.pokemon_id AS pokemon_id, r.cp AS cp, r.move_1 AS move_1, r.move_2 AS move_2, FROM_UNIXTIME(r.time_spawn) AS spawn, FROM_UNIXTIME(r.time_battle) AS start, FROM_UNIXTIME(r.time_end) AS end, FROM_UNIXTIME(fs.updated) AS last_scanned, f.name, f.lat AS latitude, f.lon as longitude 
368
					FROM raids r 
369
					JOIN forts f ON f.id = r.fort_id 
370
					JOIN fort_sightings fs ON fs.fort_id = r.fort_id 
371
					WHERE r.time_end > UNIX_TIMESTAMP() 
372
					ORDER BY r.level DESC, r.time_battle" . $limit;
373
		$result = $this->mysqli->query($req);
374
		$raids = array();
375
		while ($data = $result->fetch_object()) {
376
			$raids[] = $data;
377
		}
378
		return $raids;
379
	}
380
381
382
	//////////////
383
	// Trainers
384
	//////////////
385
386
	public  function getTrainers($trainer_name, $team, $page, $ranking) {
0 ignored issues
show
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
387
		return array(); // Waiting for Monocle to store level
388
	}
389
390
	public function getTrainerLevelCount($team_id) {
391
		$levelData = array();
392 View Code Duplication
		for ($i = 5; $i <= 40; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
393
			if (!isset($levelData[$i])) {
394
				$levelData[$i] = 0;
395
			}
396
		}
397
		return $levelData; // Waiting for Monocle to store level
398
	}
399
400
401
	/////////
402
	// Cron
403
	/////////
404
405
	public function getPokemonCountsActive() {
406
		$req = "SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP() GROUP BY pokemon_id";
407
		$result = $this->mysqli->query($req);
408
		$counts = array();
409
		while ($data = $result->fetch_object()) {
410
			$counts[$data->pokemon_id] = $data->total;
411
		}
412
		return $counts;
413
	}
414
415
	public  function getPoekmonCountsLastDay() {
0 ignored issues
show
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
416
		$req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day
417
					FROM sightings
418
					WHERE FROM_UNIXTIME(expire_timestamp) >= (SELECT FROM_UNIXTIME(MAX(expire_timestamp)) FROM sightings) - INTERVAL 1 DAY
419
					GROUP BY pokemon_id
420
				  	ORDER BY pokemon_id ASC";
421
		$result = $this->mysqli->query($req);
422
		$counts = array();
423
		while ($data = $result->fetch_object()) {
424
			$counts[$data->pokemon_id] = $data->spawns_last_day;
425
		}
426
		return $counts;
427
	}
428
429 View Code Duplication
	public  function getPokemonSinceLastUpdate($pokemon_id, $last_update) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
430
		$req = "SELECT COUNT(*) AS count, MAX(expire_timestamp) AS last_timestamp, (FROM_UNIXTIME(MAX(expire_timestamp))) AS disappear_time_real, lat as latitude, lon as longitude
431
					FROM sightings
432
					WHERE pokemon_id = '".$pokemon_id."' && expire_timestamp > '".$last_update."'";
433
		$result = $this->mysqli->query($req);
434
		$data = $result->fetch_object();
435
		return $data;
436
	}
437
438 View Code Duplication
	public  function getRaidsSinceLastUpdate($pokemon_id, $last_update) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
439
		$where = "WHERE pokemon_id = '".$pokemon_id."' && time_battle > '".$last_update."'";
440
		$req = "SELECT time_battle AS start_timestamp, time_end as end, (FROM_UNIXTIME(time_end)) AS end_time_real, lat as latitude, lon as longitude, count
441
					FROM raids r
442
					JOIN forts g
443
					JOIN (SELECT COUNT(*) AS count
444
					FROM raids
445
                    " . $where."
446
                ) x 
447
				ON r.fort_id = g.id
448
                " . $where."
449
                ORDER BY time_battle DESC
450
				LIMIT 0 , 1";
451
		$result = $this->mysqli->query($req);
452
		$data = $result->fetch_object();
453
		return $data;
454
	}
455
456
	public  function getCaptchaCount() {
0 ignored issues
show
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
457
		$req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL";
458
		$result = $this->mysqli->query($req);
459
		$data = $result->fetch_object();
460
		return $data;
461
	}
462
463 View Code Duplication
	public  function getNestData() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
464
		$pokemon_exclude_sql = "";
465
		if (!empty(self::$config->system->nest_exclude_pokemon)) {
466
			$pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", self::$config->system->nest_exclude_pokemon) . ")";
467
		}
468
		$req = "SELECT p.pokemon_id, p.lat AS latitude, p.lon AS longitude, count(p.pokemon_id) AS total_pokemon, s.updated, coalesce(duration,30)*60 as duration
469
			          FROM sightings p
470
			          INNER JOIN spawnpoints s ON (p.spawn_id = s.spawn_id)
471
			          WHERE p.expire_timestamp > UNIX_TIMESTAMP() - 86400
472
			          " . $pokemon_exclude_sql . "
473
			          GROUP BY p.spawn_id, p.pokemon_id
474
			          HAVING COUNT(p.pokemon_id) >= 6
475
			          ORDER BY p.pokemon_id";
476
		$result = $this->mysqli->query($req);
477
		$nests = array();
478
		while ($data = $result->fetch_object()) {
479
			$nests[] = $data;
480
		}
481
		return $nests;
482
	}
483
484
}