Failed Conditions
Pull Request — master (#353)
by Florian
04:11 queued 01:30
created

QueryManagerMysqlMonocleAlternate::__destruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
class QueryManagerMysqlMonocleAlternate 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
	public function __construct() {
6
		parent::__construct();
7
	}
8
9
	public function __destruct() {
10
		parent::__destruct();
11
	}
12
13
	///////////
14
	// Tester
15
	///////////
16
17 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...
18
		$req = "SELECT COUNT(*) as total FROM sightings";
19
		$result = $this->mysqli->query($req);
20
		if (!is_object($result)) {
21
			return 1;
22
		} else {
23
			$data = $result->fetch_object();
24
			$total = $data->total;
25
26
			if ($total == 0) {
27
				return 2;
28
			}
29
		}
30
		return 0;
31
	}
32
33 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...
34
		$req = "SELECT COUNT(*) as total FROM forts";
35
		$result = $this->mysqli->query($req);
36
		if (!is_object($result)) {
37
			return 1;
38
		} else {
39
			$data = $result->fetch_object();
40
			$total = $data->total;
41
42
			if ($total == 0) {
43
				return 2;
44
			}
45
		}
46
		return 0;
47
	}
48
49 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...
50
		$req = "SELECT COUNT(*) as total FROM pokestops";
51
		$result = $this->mysqli->query($req);
52
		if (!is_object($result)) {
53
			return 1;
54
		} else {
55
			$data = $result->fetch_object();
56
			$total = $data->total;
57
58
			if ($total == 0) {
59
				return 2;
60
			}
61
		}
62
		return 0;
63
	}
64
	
65
	
66
	/////////////
67
	// Homepage
68
	/////////////
69
70
	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...
71
		$req = "SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP()";
72
		$result = $this->mysqli->query($req);
73
		$data = $result->fetch_object();
74
		return $data;
75
	}
76
77
	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...
78
		$data = (object) array("total" => 0);
79
		return $data;
80
	}
81
82
	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...
83
		$req = "SELECT COUNT(*) AS total FROM forts";
84
		$result = $this->mysqli->query($req);
85
		$data = $result->fetch_object();
86
		return $data;
87
	}
88
89
	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...
90
		$req = "SELECT COUNT(*) AS total FROM raids WHERE time_battle <= UNIX_TIMESTAMP() AND time_end >= UNIX_TIMESTAMP()";
91
		$result = $this->mysqli->query($req);
92
		$data = $result->fetch_object();
93
		return $data;
94
	}
95
96
97
	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...
98
		$req = "SELECT COUNT(*) AS total 
99
					FROM forts f
100
					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
101
					WHERE team = '$team_id'";
102
		$result = $this->mysqli->query($req);
103
		$data = $result->fetch_object();
104
		return $data;
105
	}
106
107
	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...
108
		$req = "SELECT DISTINCT pokemon_id, encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
109
              lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina
110
              FROM sightings
111
              ORDER BY updated DESC
112
              LIMIT 0,12";
113
		$result = $this->mysqli->query($req);
114
		$data = array();
115
		if ($result->num_rows > 0) {
116
			while ($row = $result->fetch_object()) {
117
				$data[] = $row;
118
			}
119
		}
120
		return $data;
121
	}
122
123
	function getRecentMythic($mythic_pokemon) {
0 ignored issues
show
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...
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...
124
		$req = "SELECT pokemon_id, encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
125
                lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina
126
                FROM sightings
127
                WHERE pokemon_id IN (".implode(",", $mythic_pokemon).")
128
                ORDER BY updated DESC
129
                LIMIT 0,12";
130
		$result = $this->mysqli->query($req);
131
		$data = array();
132
		if ($result->num_rows > 0) {
133
			while ($row = $result->fetch_object()) {
134
				$data[] = $row;
135
			}
136
		}
137
		return $data;
138
	}
139
140
	///////////////////
141
	// Single Pokemon
142
	///////////////////
143
144 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...
145
		$req = "SELECT COUNT(DISTINCT(fort_id)) AS total 
146
					FROM forts f
147
					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
148
					WHERE guard_pokemon_id = '".$pokemon_id."'";
149
		$result = $this->mysqli->query($req);
150
		$data = $result->fetch_object();
151
		return $data;
152
	}
153
154 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...
155
		$req = "SELECT FROM_UNIXTIME(expire_timestamp) AS expire_timestamp, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude
156
                FROM sightings
157
                WHERE pokemon_id = '".$pokemon_id."'
158
                ORDER BY expire_timestamp DESC
159
                LIMIT 0,1";
160
		$result = $this->mysqli->query($req);
161
		$data = $result->fetch_object();
162
		return $data;
163
	}
164
165
	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...
166
		$req = "SELECT FROM_UNIXTIME(expire_timestamp) AS distime, pokemon_id as pokemon_id, FROM_UNIXTIME(expire_timestamp) as disappear_time, lat as latitude, lon as longitude,
167
                cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina,
168
                ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS IV, move_1 as move_1, move_2, form
169
                FROM sightings
170
	            WHERE pokemon_id = '" . $pokemon_id . "' AND move_1 IS NOT NULL AND move_1 <> '0'
171
	            ORDER BY $top_order_by $top_direction, expire_timestamp DESC
172
	            LIMIT 0,50";
173
174
		$result = $this->mysqli->query($req);
175
		$top = array();
176
		while ($data = $result->fetch_object()) {
177
			$top[] = $data;
178
		}
179
		return $top;
180
	}
181
182 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...
183
		$trainer_blacklist = "";
184
		if (!empty(self::$config->system->trainer_blacklist)) {
185
			$trainer_blacklist = " AND owner_name NOT IN ('" . implode("','", self::$config->system->trainer_blacklist) . "')";
186
		}
187
188
		$req = "SELECT owner_name as trainer_name, ROUND((100*((atk_iv)+(def_iv)+(sta_iv))/45),1) AS IV, move_1, move_2, cp as cp,
189
                FROM_UNIXTIME(last_modified) AS lasttime, last_modified as last_seen
190
                FROM gym_defenders
191
				WHERE pokemon_id = '" . $pokemon_id . "'" . $trainer_blacklist . "
192
				ORDER BY $best_order_by $best_direction, owner_name ASC
193
				LIMIT 0,50";
194
195
		$result = $this->mysqli->query($req);
196
		$toptrainer = array();
197
		while ($data = $result->fetch_object()) {
198
			$toptrainer[] = $data;
199
		}
200
		return $toptrainer;
201
	}
202
203 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...
204
		$where = " WHERE pokemon_id = ".$pokemon_id." "
205
			. "AND FROM_UNIXTIME(expire_timestamp) BETWEEN '".$start."' AND '".$end."'";
206
		$req 		= "SELECT lat AS latitude, lon AS longitude FROM sightings".$where." ORDER BY expire_timestamp DESC LIMIT 100000";
207
		$result = $this->mysqli->query($req);
208
		$points = array();
209
		while ($data = $result->fetch_object()) {
210
			$points[] = $data;
211
		}
212
		return $points;
213
	}
214
215 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...
216
		$req = "SELECT COUNT(*) AS total, HOUR(disappear_time) AS disappear_hour
217
					FROM (SELECT FROM_UNIXTIME(expire_timestamp) as disappear_time FROM sightings WHERE pokemon_id = '".$pokemon_id."' ORDER BY disappear_time LIMIT 100000) AS pokemonFiltered
218
				GROUP BY disappear_hour
219
				ORDER BY disappear_hour";
220
		$result = $this->mysqli->query($req);
221
		$array = array_fill(0, 24, 0);
222
		while ($result && $data = $result->fetch_object()) {
223
			$array[$data->disappear_hour] = $data->total;
224
		}
225
		// shift array because AM/PM starts at 1AM not 0:00
226
		$array[] = $array[0];
227
		array_shift($array);
228
		return $array;
229
	}
230
231 View Code Duplication
	public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) {
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...
232
		$inmap_pkms_filter = "";
233
		$where = " WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = " . $pokemon_id;
234
235
		$reqTestIv = "SELECT MAX(atk_iv) AS iv FROM sightings " . $where;
236
		$resultTestIv = $this->mysqli->query($reqTestIv);
237
		$testIv = $resultTestIv->fetch_object();
238
		if (!is_null($inmap_pokemons) && ($inmap_pokemons != "")) {
239
			foreach ($inmap_pokemons as $inmap) {
240
				$inmap_pkms_filter .= "'".$inmap."',";
241
			}
242
			$inmap_pkms_filter = rtrim($inmap_pkms_filter, ",");
243
			$where .= " AND encounter_id NOT IN (" . $inmap_pkms_filter . ") ";
244
		}
245
		if ($testIv->iv != null && !is_null($ivMin) && ($ivMin != "")) {
246
			$where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= (" . $ivMin . ") ";
247
		}
248
		if ($testIv->iv != null && !is_null($ivMax) && ($ivMax != "")) {
249
			$where .= " AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= (" . $ivMax . ") ";
250
		}
251
		$req = "SELECT pokemon_id, lat AS latitude, lon AS longitude,
252
    					FROM_UNIXTIME(expire_timestamp) AS disappear_time,
253
    					FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
254
    					atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina,
255
   						move_1, move_2
256
					FROM sightings " . $where . "
257
					ORDER BY disappear_time DESC
258
					LIMIT 5000";
259
		$result = $this->mysqli->query($req);
260
		$spawns = array();
261
		while ($data = $result->fetch_object()) {
262
			$spawns[] = $data;
263
		}
264
		return $spawns;
265
	}
266
267
	public function getPokemonSliderMinMax() {
268
		$req = "SELECT FROM_UNIXTIME(MIN(expire_timestamp)) AS min, FROM_UNIXTIME(MAX(expire_timestamp)) AS max FROM sightings";
269
		$result = $this->mysqli->query($req);
270
		$data = $result->fetch_object();
271
		return $data;
272
	}
273
274
	public function getMapsCoords() {
275
		$req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints";
276
		$result = $this->mysqli->query($req);
277
		$data = $result->fetch_object();
278
		return $data;
279
	}
280
281
282
	///////////////
283
	// Pokestops
284
	//////////////
285
286
287
	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...
288
		$req = "SELECT COUNT(*) as total FROM pokestops";
289
		$result = $this->mysqli->query($req);
290
		$data = $result->fetch_object();
291
		return $data;
292
	}
293
294
	public function getAllPokestops() {
295
		$req = "SELECT lat as latitude, lon as longitude, null AS lure_expiration, UNIX_TIMESTAMP() AS now, null AS lure_expiration_real FROM pokestops";
296
		$result = $this->mysqli->query($req);
297
		$pokestops = array();
298
		while ($data = $result->fetch_object()) {
299
			$pokestops[] = $data;
300
		}
301
		return $pokestops;
302
	}
303
304
305
	/////////
306
	// Gyms
307
	/////////
308
309
	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...
310
		$req = "SELECT COUNT(*) AS total, guard_pokemon_id 
311
					FROM forts f
312
					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
313
					WHERE team = '".$team_id."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 0,3";
314
		$result = $this->mysqli->query($req);
315
316
		$datas = array();
317
		while ($data = $result->fetch_object()) {
318
			$datas[] = $data;
319
		}
320
321
		return $datas;
322
	}
323
324
	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...
325
		$req = "SELECT COUNT(DISTINCT(fs.fort_id)) AS total, ROUND(AVG(fs.total_cp)) AS average_points
326
        			FROM forts f
327
					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
328
        			WHERE fs.team = '" . $team_id . "'";
329
		$result = $this->mysqli->query($req);
330
		$data = $result->fetch_object();
331
		return $data;
332
	}
333
334
	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...
335
		$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 
336
					FROM forts f
337
					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id));";
338
		$result = $this->mysqli->query($req);
339
		$gyms = array();
340
		while ($data = $result->fetch_object()) {
341
			$gyms[] = $data;
342
		}
343
		return $gyms;
344
	}
345
346
	public function getGymData($gym_id) {
347
		$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, fs.total_cp	
348
			FROM forts f
349
			LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
350
			WHERE f.id ='".$gym_id."'";
351
		$result = $this->mysqli->query($req);
352
		$data = $result->fetch_object();
353
		return $data;
354
	}
355
356
	public function getGymDefenders($gym_id) {
357
		$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
358
			FROM gym_defenders 
359
			WHERE fort_id='".$gym_id."'
360
			ORDER BY deployment_time";
361
		$result = $this->mysqli->query($req);
362
		$defenders = array();
363
		while ($data = $result->fetch_object()) {
364
			$defenders[] = $data;
365
		}
366
		return $defenders;
367
	}
368
369
370
	///////////
371
	// Raids
372
	///////////
373
374 View Code Duplication
	public function getAllRaids($page) {
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...
375
		$limit = " LIMIT ".($page * 10).",10";
376
		$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 
377
					FROM forts f
378
					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
379
				 	LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= UNIX_TIMESTAMP())
380
					WHERE r.time_end > UNIX_TIMESTAMP() 
381
					ORDER BY r.level DESC, r.time_battle" . $limit;
382
		$result = $this->mysqli->query($req);
383
		$raids = array();
384
		while ($data = $result->fetch_object()) {
385
			$raids[] = $data;
386
		}
387
		return $raids;
388
	}
389
390
391
392
	////////////////
393
	// Gym History
394
	////////////////
395
396 View Code Duplication
	public function getGymHistories($gym_name, $team, $page, $ranking)
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...
397
	{
398
		$where = '';
399
		if (isset($gym_name) && $gym_name != '') {
400
			$where = " WHERE name LIKE '%".$gym_name."%'";
401
		}
402
		if (isset($team) && $team != '') {
403
			$where .= ($where == "" ? " WHERE" : " AND")." team_id = ".$team;
404
		}
405
		switch ($ranking) {
406
			case 1:
407
				$order = " ORDER BY name, last_modified DESC";
408
				break;
409
			case 2:
410
				$order = " ORDER BY total_cp DESC, last_modified DESC";
411
				break;
412
			default:
413
				$order = " ORDER BY last_modified DESC, name";
414
		}
415
416
		$limit = " LIMIT ".($page * 10).",10";
417
418
		$req = "SELECT f.id as gym_id, fs.total_cp, f.name, fs.team as team_id, (6 - slots_available) as pokemon_count, FROM_UNIXTIME(last_modified) AS last_modified 
419
			FROM forts f
420
			LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
421
			".$where.$order.$limit;
422
423
		$result = $this->mysqli->query($req);
424
		$gym_history = array();
425
		while ($data = $result->fetch_object()) {
426
			$gym_history[] = $data;
427
		}
428
		return $gym_history;
429
	}
430
431
	public function getGymHistoriesPokemon($gym_id)
432
	{
433
		$req = "SELECT DISTINCT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name
434
					FROM gym_defenders
435
					WHERE fort_id = '". $gym_id ."'
436
					ORDER BY deployment_time";
437
		$result = $this->mysqli->query($req);
438
		$pokemons = array();
439
		while ($data = $result->fetch_object()) {
440
			$pokemons[] = $data;
441
		}
442
		return $pokemons;
443
	}
444
445 View Code Duplication
	public function getHistoryForGym($page, $gym_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...
446
	{
447
		if (isset(self::$config->system->gymhistory_hide_cp_changes) && self::$config->system->gymhistory_hide_cp_changes === true) {
448
			$pageSize = 25;
449
		} else {
450
			$pageSize = 10;
451
		}
452
		$req = "SELECT f.id as gym_id, fs.team as team_id, total_cp, FROM_UNIXTIME(fs.last_modified) as last_modified, last_modified as last_modified_real
453
					FROM fort_sightings fs
454
					LEFT JOIN forts f ON f.id = fs.fort_id
455
					WHERE f.id = '". $gym_id ."'
456
					ORDER BY fs.last_modified DESC
457
					LIMIT ".($page * $pageSize).",".($pageSize+1);
458
		$result = $this->mysqli->query($req);
459
		$history = array();
460
		$count = 0;
461
		while ($data = $result->fetch_object()) {
462
			$count++;
463
			if ($data->total_cp == 0) {
464
				$data->pokemon = array();
465
				$data->pokemon_count = 0;
466
				$data->pokemon_uids = "";
467
			} else {
468
				$data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real);
469
				$data->pokemon_count = count($data->pokemon);
470
				$data->pokemon_uids = implode(",", array_keys($data->pokemon));
471
			}
472
			if ($data->total_cp === 0 || $data->pokemon_count !== 0) {
473
				$history[] = $data;
474
			}
475
		}
476
		if ($count !== ($pageSize + 1)) {
477
			$last_page = true;
478
		} else {
479
			$last_page = false;
480
		}
481
		return array("last_page" => $last_page, "data" => $history);
482
	}
483
484 View Code Duplication
	private function getHistoryForGymPokemon($gym_id, $last_modified)
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...
485
	{
486
		$req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name
487
					FROM gym_history_defenders ghd
488
					JOIN gym_defenders gd ON ghd.defender_id = gd.external_id
489
					WHERE ghd.fort_id = '". $gym_id ."' AND date = '".$last_modified."'
490
					ORDER BY gd.deployment_time";
491
		$result = $this->mysqli->query($req);
492
		$pokemons = array();
493
		while ($data = $result->fetch_object()) {
494
			$pokemons[$data->defender_id] = $data;
495
		}
496
		return $pokemons;
497
	}
498
499
500
501
	//////////////
502
	// Trainers
503
	//////////////
504
505 View Code Duplication
	public function getTrainers($trainer_name, $team, $page, $ranking) {
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...
506
		$ranking = $this->getTrainerLevelRanking();
507
		$where = "";
508
		if (!empty(self::$config->system->trainer_blacklist)) {
509
			$where .= " AND gd.owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
510
		}
511
		if ($trainer_name != "") {
512
			$where = " AND gd.owner_name LIKE '%".$trainer_name."%'";
513
		}
514
		if ($team != 0) {
515
			$where .= ($where == "" ? " HAVING" : " AND")." team = ".$team;
516
		}
517
		switch ($rankingNumber) {
0 ignored issues
show
Bug introduced by
The variable $rankingNumber does not exist. Did you mean $ranking?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
518
			case 1:
519
				$order = " ORDER BY ABS(active) DESC, level DESC";
520
				break;
521
			case 2:
522
				$order = " ORDER BY maxCp DESC, level DESC";
523
				break;
524
			default:
525
				$order = " ORDER BY level DESC, active DESC";
526
		}
527
		$order .= ", last_seen DESC, name ";
528
		$limit = " LIMIT ".($page * 10).",10 ";
529
		$req = "SELECT gd.owner_name AS name, MAX(owner_level) as level, MAX(cp) as maxCp, active, team, FROM_UNIXTIME(MAX(last_modified)) as last_seen
530
				  	FROM gym_defenders gd
531
				  	LEFT JOIN (
532
				  		SELECT owner_name, COUNT(*) as active
533
				  		FROM gym_defenders gd2
534
						WHERE fort_id IS NOT NULL
535
				  		GROUP BY owner_name
536
				  	) active ON active.owner_name = gd.owner_name
537
				  	WHERE gd.owner_level IS NOT NULL " . $where . "
538
				  	GROUP BY gd.owner_name" . $order  . $limit;
539
		$result = $this->mysqli->query($req);
540
		$trainers = array();
541
		while ($data = $result->fetch_object()) {
542
			$data->last_seen = date("Y-m-d", strtotime($data->last_seen));
543
            if (is_null($data->active)) {
544
                $data->active = 0;
545
            }
546
			$trainers[$data->name] = $data;
547
548
			$pokemon = array_merge($this->getActivePokemon($data->name),  $this->getInactivePokemon($data->name));
0 ignored issues
show
Coding Style introduced by
Expected 1 space instead of 2 after comma in function call.
Loading history...
549
550
			$trainers[$data->name]->gyms = $data->active;
551
			$trainers[$data->name]->pokemons = $pokemon;
552
			$trainers[$data->name]->rank = $ranking[$data->level];
553
		}
554
		return $trainers;
555
	}
556
557 View Code Duplication
	public function getTrainerLevelRanking() {
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...
558
		$exclue = "";
559
		if (!empty(self::$config->system->trainer_blacklist)) {
560
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
561
		}
562
		$req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL ".$exclue." GROUP BY owner_level, owner_name) x GROUP BY level";
563
		$result = $this->mysqli->query($req);
564
		$levelData = array();
565
		while ($data = $result->fetch_object()) {
566
			$levelData[$data->level] = $data->count;
567
		}
568
		for ($i = 5; $i <= 40; $i++) {
569
			if (!isset($levelData[$i])) {
570
				$levelData[$i] = 0;
571
			}
572
		}
573
		# sort array again
574
		ksort($levelData);
575
		return $levelData;
576
	}
577
578
	public function getActivePokemon($trainer_name) {
579
		$req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, FROM_UNIXTIME(deployment_time) AS deployment_time, '1' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
580
						FROM gym_defenders 
581
						WHERE owner_name = '".$trainer_name."' AND fort_id IS NOT NULL
582
						ORDER BY deployment_time";
583
		$result = $this->mysqli->query($req);
584
		$pokemon = array();
585
		while ($data = $result->fetch_object()) {
586
			$pokemon[] = $data;
587
		}
588
		return $pokemon;
589
	}
590
591
	public function getInactivePokemon($trainer_name) {
592
		$req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, NULL AS deployment_time, '0' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
593
					FROM gym_defenders 
594
					WHERE owner_name = '".$trainer_name."' AND fort_id IS NULL
595
					ORDER BY last_scanned";
596
		$result = $this->mysqli->query($req);
597
		$pokemon = array();
598
		while ($data = $result->fetch_object()) {
599
			$pokemon[] = $data;
600
		}
601
		return $pokemon;
602
	}
603
604 View Code Duplication
	public function getTrainerLevelCount($team_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...
605
		$exclue = "";
606
		if (!empty(self::$config->system->trainer_blacklist)) {
607
			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
608
		}
609
		$req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL AND team = '".$team_id."' ".$exclue." GROUP BY owner_level, owner_name) x GROUP BY level";
610
		$result = $this->mysqli->query($req);
611
		$levelData = array();
612
		while ($data = $result->fetch_object()) {
613
			$levelData[$data->level] = $data->count;
614
		}
615
		for ($i = 5; $i <= 40; $i++) {
616
			if (!isset($levelData[$i])) {
617
				$levelData[$i] = 0;
618
			}
619
		}
620
		# sort array again
621
		ksort($levelData);
622
		return $levelData;
623
	}
624
625
626
	/////////
627
	// Cron
628
	/////////
629
630
	public function getPokemonCountsActive() {
631
		$req = "SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP() GROUP BY pokemon_id";
632
		$result = $this->mysqli->query($req);
633
		$counts = array();
634
		while ($data = $result->fetch_object()) {
635
			$counts[$data->pokemon_id] = $data->total;
636
		}
637
		return $counts;
638
	}
639
640
	public function getPokemonCountsLastDay() {
641
		$req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day
642
					FROM sightings
643
					WHERE expire_timestamp >= (SELECT MAX(expire_timestamp) - 86400 FROM sightings)
644
					GROUP BY pokemon_id
645
				  	ORDER BY pokemon_id ASC";
646
		$result = $this->mysqli->query($req);
647
		$counts = array();
648
		while ($data = $result->fetch_object()) {
649
			$counts[$data->pokemon_id] = $data->spawns_last_day;
650
		}
651
		return $counts;
652
	}
653
654 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...
655
		$where = "WHERE p.pokemon_id = '".$pokemon_id."' AND p.expire_timestamp - (coalesce(CASE WHEN duration = 0 THEN NULL ELSE duration END ,30)*60) > '".$last_update."'";
656
		$req = "SELECT count, p.expire_timestamp - (coalesce(CASE WHEN duration = 0 THEN NULL ELSE duration END ,30)*60) AS last_timestamp, (FROM_UNIXTIME(p.expire_timestamp)) AS disappear_time_real, p.lat as latitude, p.lon as longitude
657
					FROM sightings p
658
					LEFT JOIN spawnpoints s ON p.spawn_id = s.spawn_id
659
					JOIN (SELECT COUNT(*) AS count
660
						FROM sightings p
661
						LEFT JOIN spawnpoints s ON p.spawn_id = s.spawn_id
662
                    	" . $where."
663
                    ) x
664
					" . $where . "
665
					ORDER BY last_timestamp DESC
666
					LIMIT 0 , 1";
667
		$result = $this->mysqli->query($req);
668
		$data = $result->fetch_object();
669
		return $data;
670
	}
671
672 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...
673
		$where = "WHERE pokemon_id = '".$pokemon_id."AND".$last_update."'";
674
		$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
675
					FROM raids r
676
					JOIN forts g
677
					JOIN (SELECT COUNT(*) AS count
678
						FROM raids
679
                    	" . $where."
680
                    ) x 
681
					ON r.fort_id = g.id
682
                    " . $where . "
683
                    ORDER BY time_battle DESC
684
					LIMIT 0 , 1";
685
		$result = $this->mysqli->query($req);
686
		$data = $result->fetch_object();
687
		return $data;
688
	}
689
690
	public function getCaptchaCount() {
691
		$req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL";
692
		$result = $this->mysqli->query($req);
693
		$data = $result->fetch_object();
694
		return $data;
695
	}
696
697 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...
698
		$pokemon_exclude_sql = "";
699
		if (!empty(self::$config->system->nest_exclude_pokemon)) {
700
			$pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", self::$config->system->nest_exclude_pokemon) . ")";
701
		}
702
		$req = "SELECT p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(s.updated) as latest_seen, coalesce(CASE WHEN MAX(duration) = 0 THEN NULL ELSE MAX(duration) END ,30)*60 as duration
703
			          FROM sightings p
704
			          INNER JOIN spawnpoints s ON (p.spawn_id = s.spawn_id)
705
			          WHERE p.expire_timestamp > UNIX_TIMESTAMP() - 86400
706
			          " . $pokemon_exclude_sql . "
707
			          GROUP BY p.spawn_id, p.pokemon_id
708
			          HAVING COUNT(p.pokemon_id) >= 6
709
			          ORDER BY p.pokemon_id";
710
		$result = $this->mysqli->query($req);
711
		$nests = array();
712
		while ($data = $result->fetch_object()) {
713
			$nests[] = $data;
714
		}
715
		return $nests;
716
	}
717
718
}
719