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

QueryManagerMysqlRocketmap::getGymData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
final class QueryManagerMysqlRocketmap 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 pokemon";
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 gym";
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 pokestop";
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 pokemon WHERE disappear_time >= UTC_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
		$req = "SELECT COUNT(*) AS total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()";
79
		$result = $this->mysqli->query($req);
80
		$data = $result->fetch_object();
81
		return $data;
82
	}
83
	
84
	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...
85
		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym";
86
		$result = $this->mysqli->query($req);
87
		$data = $result->fetch_object();
88
		return $data;
89
	}
90
	
91
	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...
92
		$req = "SELECT COUNT(*) AS total FROM raid WHERE start <= UTC_TIMESTAMP AND  end >= UTC_TIMESTAMP()";
93
		$result = $this->mysqli->query($req);
94
		$data = $result->fetch_object();
95
		return $data;
96
	}
97
	
98
	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...
99
		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE team_id = '".$team_id."'";
100
		$result = $this->mysqli->query($req);
101
		$data = $result->fetch_object();
102
		return $data;
103
	}
104
	
105
	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...
106
		$req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real,
107
					latitude, longitude, cp, individual_attack, individual_defense, individual_stamina
108
					FROM pokemon
109
					ORDER BY last_modified DESC
110
					LIMIT 0,12";
111
		$result = $this->mysqli->query($req);
112
		$data = array();
113
		if ($result->num_rows > 0) {
114
			while ($row = $result->fetch_object()) {
115
				$data[] = $row;
116
			}
117
		}
118
		return $data;
119
	}
120
	
121 View Code Duplication
	function getRecentMythic($mythic_pokemons) {
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...
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...
122
		$req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real,
123
					latitude, longitude, cp, individual_attack, individual_defense, individual_stamina
124
					FROM pokemon
125
					WHERE pokemon_id IN (".implode(",", $mythic_pokemons).")
126
					ORDER BY last_modified DESC
127
					LIMIT 0,12";
128
		$result = $this->mysqli->query($req);
129
		$data = array();
130
		if ($result->num_rows > 0) {
131
			while ($row = $result->fetch_object()) {
132
				$data[] = $row;
133
			}
134
		}
135
		return $data;
136
	}
137
	
138
	///////////////////
139
	// Single Pokemon
140
	///////////////////
141
	
142 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...
143
		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE guard_pokemon_id = '".$pokemon_id."'";
144
		$result = $this->mysqli->query($req);
145
		$data = $result->fetch_object();
146
		return $data;
147
	}
148
	
149 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...
150
		$req = "SELECT disappear_time, (CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real, latitude, longitude
151
							FROM pokemon
152
							WHERE pokemon_id = '".$pokemon_id."'
153
							ORDER BY disappear_time DESC
154
							LIMIT 0,1";
155
		$result = $this->mysqli->query($req);
156
		$data = $result->fetch_object();
157
		return $data;
158
	}
159
160 View Code Duplication
	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...
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 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...
161
		$req = "SELECT (CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS distime, pokemon_id, disappear_time, latitude, longitude,
162
							cp, individual_attack, individual_defense, individual_stamina,
163
							ROUND(100*(individual_attack+individual_defense+individual_stamina)/45,1) AS IV, move_1, move_2, form
164
							FROM pokemon
165
							WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0'
166
							ORDER BY $top_order_by $top_direction, disappear_time DESC
167
							LIMIT 0,50";
168
169
		$result = $this->mysqli->query($req);
170
		$top = array();
171
		while ($data = $result->fetch_object()) {
172
			$top[] = $data;
173
		}
174
		return $top;
175
	}
176
177 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...
178
		$trainer_blacklist = "";
179
		if (!empty(self::$config->system->trainer_blacklist)) {
180
			$trainer_blacklist = " AND trainer_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
181
		}
182
183
		$req = "SELECT trainer_name, ROUND(SUM(100*(iv_attack+iv_defense+iv_stamina)/45),1) AS IV, move_1, move_2, cp,
184
						DATE_FORMAT(last_seen, '%Y-%m-%d') AS lasttime, last_seen
185
						FROM gympokemon
186
						WHERE pokemon_id = '".$pokemon_id."'".$trainer_blacklist."
187
						ORDER BY $best_order_by $best_direction, trainer_name ASC
188
						LIMIT 0,50";
189
190
		$result = $this->mysqli->query($req);
191
		$toptrainer = array();
192
		while ($data = $result->fetch_object()) {
193
			$toptrainer[] = $data;
194
		}
195
		return $toptrainer;
196
	}
197
198 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...
199
		$where = " WHERE pokemon_id = ".$pokemon_id." "
200
			. "AND disappear_time BETWEEN '".$start."' AND '".$end."'";
201
		$req 		= "SELECT latitude, longitude FROM pokemon".$where." ORDER BY disappear_time DESC LIMIT 10000";
202
		$result = $this->mysqli->query($req);
203
		$points = array();
204
		while ($data = $result->fetch_object()) {
205
			$points[] = $data;
206
		}
207
		return $points;
208
	}
209
210 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...
211
		$req = "SELECT COUNT(*) AS total,
212
					HOUR(CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_hour
213
					FROM (SELECT disappear_time FROM pokemon WHERE pokemon_id = '".$pokemon_id."' ORDER BY disappear_time LIMIT 100000) AS pokemonFiltered
214
					GROUP BY disappear_hour
215
					ORDER BY disappear_hour";
216
		$result = $this->mysqli->query($req);
217
		$array = array_fill(0, 24, 0);
218
		while ($result && $data = $result->fetch_object()) {
219
			$array[$data->disappear_hour] = $data->total;
220
		}
221
		// shift array because AM/PM starts at 1AM not 0:00
222
		$array[] = $array[0];
223
		array_shift($array);
224
		return $array;
225
	}
226
227 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...
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...
228
		$inmap_pkms_filter = "";
229
		$where = " WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = ".$pokemon_id;
230
231
		$reqTestIv = "SELECT MAX(individual_attack) AS iv FROM pokemon ".$where;
232
		$resultTestIv = $this->mysqli->query($reqTestIv);
233
		$testIv = $resultTestIv->fetch_object();
234
		if (!is_null($inmap_pokemons) && ($inmap_pokemons != "")) {
235
			foreach ($_POST['inmap_pokemons'] as $inmap) {
236
				$inmap_pkms_filter .= "'".$inmap."',";
237
			}
238
			$inmap_pkms_filter = rtrim($inmap_pkms_filter, ",");
239
			$where .= " AND encounter_id NOT IN (".$inmap_pkms_filter.") ";
240
		}
241
		if ($testIv->iv != null && !is_null($ivMin) && ($ivMin != "")) {
242
			$where .= " AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= (".$ivMin.") ";
243
		}
244
		if ($testIv->iv != null && !is_null($ivMax) && ($ivMax != "")) {
245
			$where .= " AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= (".$ivMax.") ";
246
		}
247
		$req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time,
248
						(CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real,
249
						individual_attack, individual_defense, individual_stamina, move_1, move_2
250
						FROM pokemon ".$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 getPokemonSliderMinMax() {
262
		$req = "SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon";
263
		$result = $this->mysqli->query($req);
264
		$data = $result->fetch_object();
265
		return $data;
266
	}
267
268
	public function getMapsCoords() {
269
		$req = "SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude, MAX(longitude) AS max_longitude, MIN(longitude) as min_longitude FROM spawnpoint";
270
		$result = $this->mysqli->query($req);
271
		$data = $result->fetch_object();
272
		return $data;
273
	}
274
275
276
	///////////////
277
	// Pokestops
278
	//////////////
279
280
	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...
281
		$req = "SELECT COUNT(*) as total FROM pokestop";
282
		$result = $this->mysqli->query($req);
283
		$data = $result->fetch_object();
284
		return $data;
285
	}
286
287
	public function getAllPokestops() {
288
		$req = "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() AS now, (CONVERT_TZ(lure_expiration, '+00:00', '".self::$time_offset."')) AS lure_expiration_real FROM pokestop";
289
		$result = $this->mysqli->query($req);
290
		$pokestops = array();
291
		while ($data = $result->fetch_object()) {
292
			$pokestops[] = $data;
293
		}
294
		return $pokestops;
295
	}
296
297
298
	/////////
299
	// Gyms
300
	/////////
301
302
	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...
303
		$req = "SELECT COUNT(*) AS total, guard_pokemon_id FROM gym WHERE team_id = '".$team_id ."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 0,3";
304
		$result = $this->mysqli->query($req);
305
		$datas = array();
306
		while ($data = $result->fetch_object()) {
307
			$datas[] = $data;
308
		}
309
		return $datas;
310
	}
311
312
	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...
313
		$req 	= "SELECT COUNT(DISTINCT(gym_id)) AS total, ROUND(AVG(total_cp),0) AS average_points FROM gym WHERE team_id = '".$team_id."'";
314
		$result = $this->mysqli->query($req);
315
		$data = $result->fetch_object();
316
		return $data;
317
	}
318
319
	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...
320
		$req = "SELECT gym_id, team_id, latitude, longitude, (CONVERT_TZ(last_scanned, '+00:00', '".self::$time_offset."')) AS last_scanned, (6 - slots_available) AS level FROM gym";
321
		$result = $this->mysqli->query($req);
322
		$gyms = array();
323
		while ($data = $result->fetch_object()) {
324
			$gyms[] = $data;
325
		}
326
		return $gyms;
327
	}
328
329 View Code Duplication
	public function getGymData($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...
330
		$req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team,
331
					(CONVERT_TZ(gym.last_scanned, '+00:00', '".self::$time_offset."')) AS last_scanned, gym.guard_pokemon_id AS guard_pokemon_id, gym.total_cp AS total_cp, (6 - gym.slots_available) AS level
332
					FROM gymdetails
333
					LEFT JOIN gym ON gym.gym_id = gymdetails.gym_id
334
					WHERE gym.gym_id='".$gym_id."'";
335
		$result = $this->mysqli->query($req);
336
		$data = $result->fetch_object();
337
		return $data;
338
	}
339
340
	public function getGymDefenders($gym_id) {
341
		$req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id
342
					FROM gympokemon INNER JOIN gymmember ON gympokemon.pokemon_uid=gymmember.pokemon_uid
343
					GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id
344
					HAVING gymmember.gym_id='".$gym_id."'
345
					ORDER BY cp DESC";
346
		$result = $this->mysqli->query($req);
347
		$defenders = array();
348
		while ($data = $result->fetch_object()) {
349
			$defenders[] = $data;
350
		}
351
		return $defenders;
352
	}
353
354
355
356
	////////////////
357
	// Gym History
358
	////////////////
359
360
	public function getGymHistories($gym_name, $team, $page, $ranking) {
361
		$where = '';
362
		$order = '';
0 ignored issues
show
Unused Code introduced by
$order is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
363
		if (isset($gym_name) && $gym_name != '') {
364
			$where = " WHERE name LIKE '%".$gym_name."%'";
365
		}
366
		if (isset($team) && $team != '') {
367
			$where .= ($where == "" ? " WHERE" : " AND")." team_id = ".$team;
368
		}
369 View Code Duplication
		switch ($ranking) {
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...
370
			case 1:
371
				$order = " ORDER BY name, last_modified DESC";
372
				break;
373
			case 2:
374
				$order = " ORDER BY total_cp DESC, last_modified DESC";
375
				break;
376
			default:
377
				$order = " ORDER BY last_modified DESC, name";
378
		}
379
380
		$limit = " LIMIT ".($page * 10).",10";
381
382
		$req = "SELECT gymdetails.gym_id, name, team_id, total_cp, (6 - slots_available) as pokemon_count, (CONVERT_TZ(last_modified, '+00:00', '" . self::$time_offset . "')) as last_modified
383
				FROM gymdetails
384
				LEFT JOIN gym
385
				ON gymdetails.gym_id = gym.gym_id
386
				".$where.$order.$limit;
387
388
		$result = $this->mysqli->query($req);
389
		$gym_history = array();
390
		while ($data = $result->fetch_object()) {
391
			$gym_history[] = $data;
392
		}
393
		return $gym_history;
394
	}
395
396
	public function getGymHistoriesPokemon($gym_id) {
397
		$req = "SELECT DISTINCT gymmember.pokemon_uid, pokemon_id, cp, trainer_name
398
					FROM gymmember
399
					LEFT JOIN gympokemon
400
					ON gymmember.pokemon_uid = gympokemon.pokemon_uid
401
					WHERE gymmember.gym_id = '". $gym_id ."'
402
					ORDER BY deployment_time";
403
		$result = $this->mysqli->query($req);
404
		$pokemons = array();
405
		while ($data = $result->fetch_object()) {
406
			$pokemons[] = $data;
407
		}
408
		return $pokemons;
409
	}
410
411
	public function getHistoryForGym($page, $gym_id) {
412
		$req = "SELECT gym_id, team_id, total_cp, pokemon_uids, pokemon_count, (CONVERT_TZ(last_modified, '+00:00', '".self::$time_offset."')) as last_modified
413
					FROM gymhistory
414
					WHERE gym_id='".$gym_id."'
415
					ORDER BY last_modified DESC
416
					LIMIT ".($page * 10).",11";
417
		$result = $this->mysqli->query($req);
418
		$history = array();
419
		while ($data = $result->fetch_object()) {
420
			$history[] = $data;
421
		}
422
		return $history;
423
	}
424
425 View Code Duplication
	public function getHistoryForGymPokemon($pkm_uids) {
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...
426
		$req = "SELECT DISTINCT pokemon_uid, pokemon_id, cp, trainer_name
427
								FROM gympokemon
428
								WHERE pokemon_uid IN ('".implode("','", $pkm_uids)."')
429
								ORDER BY FIND_IN_SET(pokemon_uid, '".implode(",", $pkm_uids)."')";
430
		$result = $this->mysqli->query($req);
431
		$pokemons = array();
432
		while ($data = $result->fetch_object()) {
433
			$pokemons[] = $data;
434
		}
435
		return $pokemons;
436
	}
437
438
439
	///////////
440
	// Raids
441
	///////////
442
443
	public function getAllRaids($page) {
444
		$limit = " LIMIT ".($page * 10).",10";
445
		$req = "SELECT raid.gym_id, raid.level, raid.pokemon_id, raid.cp, raid.move_1, raid.move_2, CONVERT_TZ(raid.spawn, '+00:00', '".self::$time_offset."') AS spawn, CONVERT_TZ(raid.start, '+00:00', '".self::$time_offset."') AS start, CONVERT_TZ(raid.end, '+00:00', '".self::$time_offset."') AS end, CONVERT_TZ(raid.last_scanned, '+00:00', '".self::$time_offset."') AS last_scanned, gymdetails.name, gym.latitude, gym.longitude FROM raid
446
					JOIN gymdetails ON gymdetails.gym_id = raid.gym_id
447
					JOIN gym ON gym.gym_id = raid.gym_id
448
					WHERE raid.end > UTC_TIMESTAMP()
449
					ORDER BY raid.level DESC, raid.start".$limit;
450
		$result = $this->mysqli->query($req);
451
		$raids = array();
452
		while ($data = $result->fetch_object()) {
453
			$raids[] = $data;
454
		}
455
		return $raids;
456
	}
457
458
459
	//////////////
460
	// Trainers
461
	//////////////
462
463
	public function getTrainers($trainer_name, $team, $page, $ranking) {
464
		$trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking);
465
		foreach ($trainers as $trainer) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
466
467
			$trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank;
468
469
			$active_gyms = 0;
470
			$pkmCount = 0;
471
472
			$trainer->pokemons = array();
473
			$active_pokemon = $this->getTrainerActivePokemon($trainer->name);
474
			foreach ($active_pokemon as $pokemon) {
475
				$active_gyms++;
476
				$trainer->pokemons[$pkmCount++] = $pokemon;
477
			}
478
479
			$inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name);
480
			foreach ($inactive_pokemon as $pokemon) {
481
				$trainer->pokemons[$pkmCount++] = $pokemon;
482
			}
483
			$trainer->gyms = "".$active_gyms;
484
		}
485
		return $trainers;
486
	}
487
488
	public function getTrainerLevelCount($team_id) {
489
		$req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'";
490
		if (!empty(self::$config->system->trainer_blacklist)) {
491
			$req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
492
		}
493
		$req .= " GROUP BY level";
494
		$result = $this->mysqli->query($req);
495
		$levelData = array();
496
		while ($data = $result->fetch_object()) {
497
			$levelData[$data['level']] = $data['count'];
498
		}
499
		for ($i = 5; $i <= 40; $i++) {
500
			if (!isset($levelData[$i])) {
501
				$levelData[$i] = 0;
502
			}
503
		}
504
		# sort array again
505
		ksort($levelData);
506
		return $levelData;
507
	}
508
509
	private function getTrainerData($trainer_name, $team, $page, $ranking) {
510
		$where = "";
511
512
		if (!empty(self::$config->system->trainer_blacklist)) {
513
			$where .= ($where == "" ? " HAVING" : " AND")." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
514
		}
515
		if ($trainer_name != "") {
516
			$where = " HAVING name LIKE '%".$trainer_name."%'";
517
		}
518
		if ($team != 0) {
519
			$where .= ($where == "" ? " HAVING" : " AND")." team = ".$team;
520
		}
521 View Code Duplication
		switch ($ranking) {
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...
522
			case 1:
523
				$order = " ORDER BY active DESC, level DESC";
524
				break;
525
			case 2:
526
				$order = " ORDER BY maxCp DESC, level DESC";
527
				break;
528
			default:
529
				$order = " ORDER BY level DESC, active DESC";
530
		}
531
		$order .= ", last_seen DESC, name ";
532
		$limit = " LIMIT ".($page * 10).",10 ";
533
		$req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp
534
				FROM trainer
535
				LEFT JOIN (SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.trainer_name, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned
536
				FROM gympokemon
537
				INNER JOIN (SELECT gymmember.pokemon_uid, gymmember.gym_id FROM gymmember GROUP BY gymmember.pokemon_uid, gymmember.gym_id HAVING gymmember.gym_id <> '') AS filtered_gymmember
538
				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name
539
				GROUP BY trainer.name " . $where . $order . $limit;
540
541
		$result = $this->mysqli->query($req);
542
		$trainers = array();
543
		while ($data = $result->fetch_object()) {
544
			$data->last_seen = date("Y-m-d", strtotime($data->last_seen));
545
			$trainers[$data->name] = $data;
546
		}
547
		return $trainers;
548
	}
549
550
	private function getTrainerLevelRating($level) {
551
		$req = "SELECT COUNT(1) AS rank FROM trainer WHERE level = ".$level;
552
		if (!empty(self::$config->system->trainer_blacklist)) {
553
			$req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
554
		}
555
		$result = $this->mysqli->query($req);
556
		$data = $result->fetch_object();
557
		return $data;
558
	}
559
560 View Code Duplication
	private function getTrainerActivePokemon($trainer_name){
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...
561
		$req = "(SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, filtered_gymmember.gym_id, CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, '1' AS active
562
					FROM gympokemon INNER JOIN
563
					(SELECT gymmember.pokemon_uid, gymmember.gym_id, gymmember.deployment_time FROM gymmember GROUP BY gymmember.pokemon_uid, gymmember.deployment_time, gymmember.gym_id HAVING gymmember.gym_id <> '') AS filtered_gymmember
564
					ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
565
					WHERE gympokemon.trainer_name='".$trainer_name."'
566
					ORDER BY gympokemon.cp DESC)";
567
		$result = $this->mysqli->query($req);
568
		$pokemons = array();
569
		while ($data = $result->fetch_object()) {
570
			$pokemons[] = $data;
571
		}
572
		return $pokemons;
573
	}
574
575 View Code Duplication
	private function getTrainerInactivePokemon($trainer_name){
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...
576
		$req = "(SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, null AS gym_id, CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, '0' AS active
577
					FROM gympokemon LEFT JOIN
578
					(SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember
579
					ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
580
					WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."'
581
					ORDER BY gympokemon.cp DESC)";
582
		$result = $this->mysqli->query($req);
583
		$pokemons = array();
584
		while ($data = $result->fetch_object()) {
585
			$pokemons[] = $data;
586
		}
587
		return $pokemons;
588
	}
589
590
591
	/////////
592
	// Cron
593
	/////////
594
595
	public function getPokemonCountsActive() {
596
		$req = "SELECT pokemon_id, COUNT(*) as total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP() GROUP BY pokemon_id";
597
		$result = $this->mysqli->query($req);
598
		$counts = array();
599
		while ($data = $result->fetch_object()) {
600
			$counts[$data->pokemon_id] = $data->total;
601
		}
602
		return $counts;
603
	}
604
605
	public function getPokemonCountsLastDay() {
606
		$req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day
607
					FROM pokemon
608
					WHERE disappear_time >= (SELECT MAX(disappear_time) FROM pokemon) - INTERVAL 1 DAY
609
					GROUP BY pokemon_id
610
				  	ORDER BY pokemon_id ASC";
611
		$result = $this->mysqli->query($req);
612
		$counts = array();
613
		while ($data = $result->fetch_object()) {
614
			$counts[$data->pokemon_id] = $data->spawns_last_day;
615
		}
616
		return $counts;
617
	}
618
619 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...
620
		$where = "WHERE p.pokemon_id = '".$pokemon_id."' AND (UNIX_TIMESTAMP(p.disappear_time) - (LENGTH(s.kind) - LENGTH( REPLACE ( kind, \"s\", \"\") )) * 900) > '".$last_update."'";
621
		$req = "SELECT count, (UNIX_TIMESTAMP(p.disappear_time) - (LENGTH(s.kind) - LENGTH( REPLACE ( kind, \"s\", \"\") )) * 900) as last_timestamp, (CONVERT_TZ(p.disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real, p.latitude, p.longitude 
622
				FROM pokemon p
623
				JOIN spawnpoint s ON p.spawnpoint_id = s.id
624
				JOIN (SELECT count(*) as count
625
                    FROM pokemon p
626
                    JOIN spawnpoint s ON p.spawnpoint_id = s.id
627
                    " . $where."
628
                ) x
629
				" . $where . "
630
				ORDER BY last_timestamp DESC
631
                LIMIT 0,1";
632
		$result = $this->mysqli->query($req);
633
		$data = $result->fetch_object();
634
		return $data;
635
	}
636
637 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...
638
		$where = "WHERE pokemon_id = '".$pokemon_id."' AND UNIX_TIMESTAMP(start) > '".$last_update."'";
639
		$req = "SELECT UNIX_TIMESTAMP(start) as start_timestamp, end, (CONVERT_TZ(end, '+00:00', '".self::$time_offset."')) AS end_time_real, latitude, longitude, count
640
                FROM raid r
641
                JOIN gym g
642
                JOIN (SELECT count(*) as count
643
                    FROM raid
644
                    " . $where."
645
                ) x
646
                ON r.gym_id = g.gym_id
647
                " . $where."
648
                ORDER BY start DESC
649
                LIMIT 0,1";
650
		$result = $this->mysqli->query($req);
651
		$data = $result->fetch_object();
652
		return $data;
653
	}
654
655
	public function getCaptchaCount() {
656
		$req = "SELECT SUM(accounts_captcha) AS total FROM mainworker";
657
		$result = $this->mysqli->query($req);
658
		$data = $result->fetch_object();
659
		return $data;
660
	}
661
662 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...
663
		$pokemon_exclude_sql = "";
664
		if (!empty(self::$config->system->nest_exclude_pokemon)) {
665
			$pokemon_exclude_sql = "AND p.pokemon_id NOT IN (".implode(",", self::$config->system->nest_exclude_pokemon).")";
666
		}
667
		$req = "SELECT p.pokemon_id, MAX(p.latitude) AS latitude, MAX(p.longitude) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(UNIX_TIMESTAMP(s.latest_seen)) as latest_seen, (LENGTH(s.kind) - LENGTH( REPLACE ( MAX(kind), \"s\", \"\") )) * 900 AS duration
668
			          FROM pokemon p 
669
			          INNER JOIN spawnpoint s ON (p.spawnpoint_id = s.id) 
670
			          WHERE p.disappear_time > UTC_TIMESTAMP() - INTERVAL 24 HOUR 
671
			          " . $pokemon_exclude_sql . " 
672
			          GROUP BY p.spawnpoint_id, p.pokemon_id 
673
			          HAVING COUNT(p.pokemon_id) >= 6 
674
			          ORDER BY p.pokemon_id";
675
		$result = $this->mysqli->query($req);
676
		$nests = array();
677
		while ($data = $result->fetch_object()) {
678
			$nests[] = $data;
679
		}
680
		return $nests;
681
	}
682
683
}