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

QueryManagerRocketmap   D

Complexity

Total Complexity 93

Size/Duplication

Total Lines 587
Duplicated Lines 39.35 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 231
loc 587
rs 4.8717
c 0
b 0
f 0
wmc 93
lcom 1
cbo 1

40 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A testTotalPokemon() 15 15 3
A testTotalGyms() 15 15 3
A testTotalPokestops() 15 15 3
A getTotalPokemon() 0 6 1
A getTotalLures() 0 6 1
A getTotalGyms() 0 6 1
A getTotalRaids() 0 6 1
A getTotalGymsForTeam() 0 6 1
A getRecentAll() 0 15 3
A getRecentMythic() 0 16 3
A getGymsProtectedByPokemon() 6 6 1
A getPokemonLastSeen() 10 10 1
A getTop50Pokemon() 0 17 2
A getTop50Trainers() 21 21 3
A getPokemonHeatmap() 11 11 2
A getPokemonGraph() 16 16 3
C getPokemonLive() 33 33 11
A getPokemonSliederMinMax() 0 6 1
A getMapsCoords() 0 6 1
A getTotalPokestops() 0 6 1
A getAllPokestops() 0 9 2
A getTeamGuardians() 0 9 2
A getOwnedAndPoints() 0 6 1
A getAllGyms() 0 9 2
A getGymData() 11 11 1
A getGymDefenders() 0 13 2
A getAllRaids() 0 14 2
B getTrainers() 0 24 4
B getTrainerLevelCount() 5 20 5
D getTrainerData() 0 40 9
A getTrainerLevelRating() 0 9 2
A getTrainerActivePokemon() 14 14 2
A getTrainerInactivePokemon() 14 14 2
A getPokemonCountsActive() 0 9 2
A getPoekmonCountsLastDay() 0 13 2
A getPokemonSinceLastUpdate() 8 8 1
A getRaidsSinceLastUpdate() 17 17 1
A getCaptchaCount() 0 6 1
A getNestData() 20 20 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like QueryManagerRocketmap often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use QueryManagerRocketmap, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
final class QueryManagerRocketmap 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
	///////////
10
	// Tester
11
	///////////
12
	
13 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...
14
		$req = "SELECT COUNT(*) as total FROM pokemon";
15
		$result = $this->mysqli->query($req);
16
		if (!is_object($result)) {
17
			return 1;
18
		} else {
19
			$data = $result->fetch_object();
20
			$total = $data->total;
21
	
22
			if ($total == 0) {
23
				return 2;
24
			}
25
		}
26
		return 0;
27
	}
28
	
29 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...
30
		$req = "SELECT COUNT(*) as total FROM gym";
31
		$result = $this->mysqli->query($req);
32
		if (!is_object($result)) {
33
			return 1;
34
		} else {
35
			$data = $result->fetch_object();
36
			$total = $data->total;
37
	
38
			if ($total == 0) {
39
				return 2;
40
			}
41
		}
42
		return 0;
43
	}
44
	
45 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...
46
		$req = "SELECT COUNT(*) as total FROM pokestop";
47
		$result = $this->mysqli->query($req);
48
		if (!is_object($result)) {
49
			return 1;
50
		} else {
51
			$data = $result->fetch_object();
52
			$total = $data->total;
53
	
54
			if ($total == 0) {
55
				return 2;
56
			}
57
		}
58
		return 0;
59
	}
60
	
61
	
62
	/////////////
63
	// Homepage
64
	/////////////
65
	
66
	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...
67
		$req = "SELECT COUNT(*) AS total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()";
68
		$result = $this->mysqli->query($req);
69
		$data = $result->fetch_object();
70
		return $data;
71
	}
72
	
73
	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...
74
		$req = "SELECT COUNT(*) AS total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()";
75
		$result = $this->mysqli->query($req);
76
		$data = $result->fetch_object();
77
		return $data;
78
	}
79
	
80
	function getTotalGyms() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

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

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

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

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

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

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

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

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

Loading history...
88
		$req = "SELECT COUNT(*) AS total FROM raid WHERE start <= UTC_TIMESTAMP AND  end >= UTC_TIMESTAMP()";
89
		$result = $this->mysqli->query($req);
90
		$data = $result->fetch_object();
91
		return $data;
92
	}
93
	
94
	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...
95
		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE team_id = '".$team_id."'";
96
		$result = $this->mysqli->query($req);
97
		$data = $result->fetch_object();
98
		return $data;
99
	}
100
	
101
	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...
102
		$req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '".$this->time_offset."')) AS disappear_time_real,
103
					latitude, longitude, cp, individual_attack, individual_defense, individual_stamina
104
					FROM pokemon
105
					ORDER BY last_modified DESC
106
					LIMIT 0,12";
107
		$result = $this->mysqli->query($req);
108
		$data = array();
109
		if ($result->num_rows > 0) {
110
			while ($row = $result->fetch_object()) {
111
				$data[] = $row;
112
			}
113
		}
114
		return $data;
115
	}
116
	
117
	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...
118
		$req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '".$this->time_offset."')) AS disappear_time_real,
119
					latitude, longitude, cp, individual_attack, individual_defense, individual_stamina
120
					FROM pokemon
121
					WHERE pokemon_id IN (".implode(",", $mythic_pokemons).")
122
					ORDER BY last_modified DESC
123
					LIMIT 0,12";
124
		$result = $this->mysqli->query($req);
125
		$data = array();
126
		if ($result->num_rows > 0) {
127
			while ($row = $result->fetch_object()) {
128
				$data[] = $row;
129
			}
130
		}
131
		return $data;
132
	}
133
	
134
	///////////////////
135
	// Single Pokemon
136
	///////////////////
137
	
138 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...
139
		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE guard_pokemon_id = '".$pokemon_id."'";
140
		$result = $this->mysqli->query($req);
141
		$data = $result->fetch_object();
142
		return $data;
143
	}
144
	
145 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...
146
		$req = "SELECT disappear_time, (CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real, latitude, longitude
147
							FROM pokemon
148
							WHERE pokemon_id = '".$pokemon_id."'
149
							ORDER BY disappear_time DESC
150
							LIMIT 0,1";
151
		$result = $this->mysqli->query($req);
152
		$data = $result->fetch_object();
153
		return $data;
154
	}
155
156
	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...
157
		$req = "SELECT (CONVERT_TZ(disappear_time, '+00:00', '".$this->time_offset."')) AS distime, pokemon_id, disappear_time, latitude, longitude,
158
							cp, individual_attack, individual_defense, individual_stamina,
159
							ROUND(100*(individual_attack+individual_defense+individual_stamina)/45,1) AS IV, move_1, move_2, form
160
							FROM pokemon
161
							WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0'
162
							GROUP BY encounter_id
163
							ORDER BY $top_order_by $top_direction, disappear_time DESC
164
							LIMIT 0,50";
165
166
		$result = $this->mysqli->query($req);
167
		$top = array();
168
		while ($data = $result->fetch_object()) {
169
			$top[] = $data;
170
		}
171
		return $top;
172
	}
173
174 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...
175
		$trainer_blacklist = "";
176
		if (!empty(self::$config->system->trainer_blacklist)) {
177
			$trainer_blacklist = " AND trainer_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
178
		}
179
180
		$req = "SELECT trainer_name, ROUND(SUM(100*(iv_attack+iv_defense+iv_stamina)/45),1) AS IV, move_1, move_2, cp,
181
						DATE_FORMAT(last_seen, '%Y-%m-%d') AS lasttime, last_seen
182
						FROM gympokemon
183
						WHERE pokemon_id = '".$pokemon_id."'".$trainer_blacklist."
184
						GROUP BY pokemon_uid
185
						ORDER BY $best_order_by $best_direction, trainer_name ASC
186
						LIMIT 0,50";
187
188
		$result = $this->mysqli->query($req);
189
		$toptrainer = array();
190
		while ($data = $result->fetch_object()) {
191
			$toptrainer[] = $data;
192
		}
193
		return $toptrainer;
194
	}
195
196 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...
197
		$where = " WHERE pokemon_id = ".$pokemon_id." "
198
			. "AND disappear_time BETWEEN '".$start."' AND '".$end."'";
199
		$req 		= "SELECT latitude, longitude FROM pokemon".$where." ORDER BY disappear_time DESC LIMIT 10000";
200
		$result = $this->mysqli->query($req);
201
		$points = array();
202
		while ($data = $result->fetch_object()) {
203
			$points[] = $data;
204
		}
205
		return $points;
206
	}
207
208 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...
209
		$req = "SELECT COUNT(*) AS total,
210
					HOUR(CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_hour
211
					FROM (SELECT disappear_time FROM pokemon WHERE pokemon_id = '".$pokemon_id."' ORDER BY disappear_time LIMIT 100000) AS pokemonFiltered
212
					GROUP BY disappear_hour
213
					ORDER BY disappear_hour";
214
		$result = $this->mysqli->query($req);
215
		$array = array_fill(0, 24, 0);
216
		while ($result && $data = $result->fetch_object()) {
217
			$array[$data->disappear_hour] = $data->total;
218
		}
219
		// shift array because AM/PM starts at 1AM not 0:00
220
		$array[] = $array[0];
221
		array_shift($array);
222
		return $array;
223
	}
224
225 View Code Duplication
	public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $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...
226
		$inmap_pkms_filter = "";
227
		$where = " WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = ".$pokemon_id;
228
229
		$reqTestIv = "SELECT MAX(individual_attack) AS iv FROM pokemon ".$where;
230
		$resultTestIv = $this->mysqli->query($reqTestIv);
231
		$testIv = $resultTestIv->fetch_object();
232
		if (!is_null($inmap_pokemons) && ($inmap_pokemons != "")) {
233
			foreach ($_POST['inmap_pokemons'] as $inmap) {
234
				$inmap_pkms_filter .= "'".$inmap."',";
235
			}
236
			$inmap_pkms_filter = rtrim($inmap_pkms_filter, ",");
237
			$where .= " AND encounter_id NOT IN (".$inmap_pkms_filter.") ";
238
		}
239
		if ($testIv->iv != null && !is_null($ivMin) && ($ivMin != "")) {
240
			$where .= " AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= (".$ivMin.") ";
241
		}
242
		if ($testIv->iv != null && !is_null($ivMax) && ($ivMax != "")) {
243
			$where .= " AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= (".$ivMax.") ";
244
		}
245
		$req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time,
246
						(CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real,
247
						individual_attack, individual_defense, individual_stamina, move_1, move_2
248
						FROM pokemon ".$where."
249
						ORDER BY disappear_time DESC
250
						LIMIT 5000";
251
		$result = $this->mysqli->query($req);
252
		$spawns = array();
253
		while ($data = $result->fetch_object()) {
254
			$spawns[] = $data;
255
		}
256
		return $spawns;
257
	}
258
259
	public function getPokemonSliederMinMax() {
260
		$req = "SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon";
261
		$result = $this->mysqli->query($req);
262
		$data = $result->fetch_object();
263
		return $data;
264
	}
265
266
	public function getMapsCoords() {
267
		$req = "SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude, MAX(longitude) AS max_longitude, MIN(longitude) as min_longitude FROM spawnpoint";
268
		$result = $this->mysqli->query($req);
269
		$data = $result->fetch_object();
270
		return $data;
271
	}
272
273
274
	///////////////
275
	// Pokestops
276
	//////////////
277
278
	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...
279
		$req = "SELECT COUNT(*) as total FROM pokestop";
280
		$result = $this->mysqli->query($req);
281
		$data = $result->fetch_object();
282
		return $data;
283
	}
284
285
	public function getAllPokestops() {
286
		$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";
287
		$result = $this->mysqli->query($req);
288
		$pokestops = array();
289
		while ($data = $result->fetch_object()) {
290
			$pokestops[] = $data;
291
		}
292
		return $pokestops;
293
	}
294
295
296
	/////////
297
	// Gyms
298
	/////////
299
300
	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...
301
		$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";
302
		$result = $this->mysqli->query($req);
303
		$datas = array();
304
		while ($data = $result->fetch_object()) {
305
			$datas[] = $data;
306
		}
307
		return $datas;
308
	}
309
310
	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...
311
		$req 	= "SELECT COUNT(DISTINCT(gym_id)) AS total, ROUND(AVG(total_cp),0) AS average_points FROM gym WHERE team_id = '".$team_id."'";
312
		$result = $this->mysqli->query($req);
313
		$data = $result->fetch_object();
314
		return $data;
315
	}
316
317
	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...
318
		$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";
319
		$result = $this->mysqli->query($req);
320
		$gyms = array();
321
		while ($data = $result->fetch_object()) {
322
			$gyms[] = $data;
323
		}
324
		return $gyms;
325
	}
326
327 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...
Coding Style introduced by
getGymData uses the super-global variable $_GET which is generally not recommended.

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

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

// Better
class Router
{
    private $host;

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

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

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

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
328
		$gym_id = $this->mysqli->real_escape_string($_GET['gym_id']);
329
		$req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team,
330
					(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
331
					FROM gymdetails
332
					LEFT JOIN gym ON gym.gym_id = gymdetails.gym_id
333
					WHERE gym.gym_id='".$gym_id."'";
334
		$result = $this->mysqli->query($req);
335
		$data = $result->fetch_object();
336
		return $data;
337
	}
338
339
	public function getGymDefenders($gym_id) {
340
		$req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id
341
					FROM gympokemon INNER JOIN gymmember ON gympokemon.pokemon_uid=gymmember.pokemon_uid
342
					GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id
343
					HAVING gymmember.gym_id='".$gym_id."'
344
					ORDER BY cp DESC";
345
		$result = $this->mysqli->query($req);
346
		$defenders = array();
347
		while ($data = $result->fetch_object()) {
348
			$defenders[] = $data;
349
		}
350
		return $defenders;
351
	}
352
353
354
	///////////
355
	// Raids
356
	///////////
357
358
	public function getAllRaids($page) {
359
		$limit = " LIMIT ".($page * 10).",10";
360
		$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
361
					JOIN gymdetails ON gymdetails.gym_id = raid.gym_id
362
					JOIN gym ON gym.gym_id = raid.gym_id
363
					WHERE raid.end > UTC_TIMESTAMP()
364
					ORDER BY raid.level DESC, raid.start".$limit;
365
		$result = $this->mysqli->query($req);
366
		$raids = array();
367
		while ($data = $result->fetch_object()) {
368
			$raids[] = $data;
369
		}
370
		return $raids;
371
	}
372
373
374
	//////////////
375
	// Trainers
376
	//////////////
377
378
	public function getTrainers($trainer_name, $team, $page, $ranking) {
379
		$trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking);
380
		foreach ($trainers as $trainer) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
381
382
			$trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank;
383
384
			$active_gyms = 0;
385
			$pkmCount = 0;
386
387
			$trainer->pokemons = array();
388
			$active_pokemon = $this->getTrainerActivePokemon($trainer->name);
389
			foreach ($active_pokemon as $pokemon) {
390
				$active_gyms++;
391
				$trainer->pokemons[$pkmCount++] = $pokemon;
392
			}
393
394
			$inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name);
395
			foreach ($inactive_pokemon as $pokemon) {
396
				$trainer->pokemons[$pkmCount++] = $pokemon;
397
			}
398
			$trainer->gyms = "".$active_gyms;
399
		}
400
		return $trainers;
401
	}
402
403
	public function getTrainerLevelCount($team_id) {
404
		$req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'";
405
		if (!empty(self::$config->system->trainer_blacklist)) {
406
			$req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
407
		}
408
		$req .= " GROUP BY level";
409
		$result = $this->mysqli->query($req);
410
		$levelData = array();
411
		while ($data = $result->fetch_object()) {
412
			$levelData[$data['level']] = $data['count'];
413
		}
414 View Code Duplication
		for ($i = 5; $i <= 40; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
415
			if (!isset($levelData[$i])) {
416
				$levelData[$i] = 0;
417
			}
418
		}
419
		# sort array again
420
		ksort($levelData);
421
		return $levelData;
422
	}
423
424
	private function getTrainerData($trainer_name, $team, $page, $ranking) {
425
		$where = "";
426
427
		if (!empty(self::$config->system->trainer_blacklist)) {
428
			$where .= ($where == "" ? " HAVING" : " AND")." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
429
		}
430
		if ($trainer_name != "") {
431
			$where = " HAVING name LIKE '%".$trainer_name."%'";
432
		}
433
		if ($team != 0) {
434
			$where .= ($where == "" ? " HAVING" : " AND")." team = ".$team;
435
		}
436
		switch ($ranking) {
437
			case 1:
438
				$order = " ORDER BY active DESC, level DESC";
439
				break;
440
			case 2:
441
				$order = " ORDER BY maxCp DESC, level DESC";
442
				break;
443
			default:
444
				$order = " ORDER BY level DESC, active DESC";
445
		}
446
		$order .= ", last_seen DESC, name ";
447
		$limit = " LIMIT ".($page * 10).",10 ";
448
		$req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp
449
				FROM trainer
450
				LEFT JOIN (SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.trainer_name, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned
451
				FROM gympokemon
452
				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
453
				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name
454
				GROUP BY trainer.name " . $where.$order.$limit;
455
456
		$result = $this->mysqli->query($req);
457
		$trainers = array();
458
		while ($data = $result->fetch_object()) {
459
			$data->last_seen = date("Y-m-d", strtotime($data->last_seen));
460
			$trainers[$data->name] = $data;
461
		}
462
		return $trainers;
463
	}
464
465
	private function getTrainerLevelRating($level) {
466
		$req = "SELECT COUNT(1) AS rank FROM trainer WHERE level = ".$level;
467
		if (!empty(self::$config->system->trainer_blacklist)) {
468
			$req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
469
		}
470
		$result = $this->mysqli->query($req);
471
		$data = $result->fetch_object();
472
		return $data;
473
	}
474
475 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...
476
		$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
477
					FROM gympokemon INNER JOIN
478
					(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
479
					ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
480
					WHERE gympokemon.trainer_name='".$trainer_name."'
481
					ORDER BY gympokemon.cp DESC)";
482
		$result = $this->mysqli->query($req);
483
		$pokemons = array();
484
		while ($data = $result->fetch_object()) {
485
			$pokemons[] = $data;
486
		}
487
		return $pokemons;
488
	}
489
490 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...
491
		$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
492
					FROM gympokemon LEFT JOIN
493
					(SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember
494
					ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
495
					WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."'
496
					ORDER BY gympokemon.cp DESC)";
497
		$result = $this->mysqli->query($req);
498
		$pokemons = array();
499
		while ($data = $result->fetch_object()) {
500
			$pokemons[] = $data;
501
		}
502
		return $pokemons;
503
	}
504
505
506
	/////////
507
	// Cron
508
	/////////
509
510
	public function getPokemonCountsActive() {
511
		$req = "SELECT pokemon_id, COUNT(*) as total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP() GROUP BY pokemon_id";
512
		$result = $this->mysqli->query($req);
513
		$counts = array();
514
		while ($data = $result->fetch_object()) {
515
			$counts[$data->pokemon_id] = $data->total;
516
		}
517
		return $counts;
518
	}
519
520
	public function getPoekmonCountsLastDay() {
521
		$req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day
522
					FROM pokemon
523
					WHERE disappear_time >= (SELECT MAX(disappear_time) FROM pokemon) - INTERVAL 1 DAY
524
					GROUP BY pokemon_id
525
				  	ORDER BY pokemon_id ASC";
526
		$result = $this->mysqli->query($req);
527
		$counts = array();
528
		while ($data = $result->fetch_object()) {
529
			$counts[$data->pokemon_id] = $data->spawns_last_day;
530
		}
531
		return $counts;
532
	}
533
534 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...
535
		$req = "SELECT COUNT(*) as count, UNIX_TIMESTAMP(MAX(disappear_time)) as last_timestamp, (CONVERT_TZ(MAX(disappear_time), '+00:00', '".self::$time_offset."')) AS disappear_time_real, latitude, longitude 
536
				FROM pokemon 
537
				WHERE pokemon_id = '".$pokemon_id."' && UNIX_TIMESTAMP(disappear_time) > '".$last_update."'";
538
		$result = $this->mysqli->query($req);
539
		$data = $result->fetch_object();
540
		return $data;
541
	}
542
543 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...
544
		$where = "WHERE pokemon_id = '".$pokemon_id."' && UNIX_TIMESTAMP(start) > '".$last_update."'";
545
		$req = "SELECT UNIX_TIMESTAMP(start) as start_timestamp, end, (CONVERT_TZ(end, '+00:00', '".self::$time_offset."')) AS end_time_real, latitude, longitude, count
546
                FROM raid r
547
                JOIN gym g
548
                JOIN (SELECT count(*) as count
549
                    FROM raid
550
                    " . $where."
551
                ) x
552
                ON r.gym_id = g.gym_id
553
                " . $where."
554
                ORDER BY start DESC
555
                LIMIT 0,1";
556
		$result = $this->mysqli->query($req);
557
		$data = $result->fetch_object();
558
		return $data;
559
	}
560
561
	public function getCaptchaCount() {
562
		$req = "SELECT SUM(accounts_captcha) AS total FROM mainworker";
563
		$result = $this->mysqli->query($req);
564
		$data = $result->fetch_object();
565
		return $data;
566
	}
567
568 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...
569
		$pokemon_exclude_sql = "";
570
		if (!empty(self::$config->system->nest_exclude_pokemon)) {
571
			$pokemon_exclude_sql = "AND p.pokemon_id NOT IN (".implode(",", self::$config->system->nest_exclude_pokemon).")";
572
		}
573
		$req = "SELECT p.pokemon_id, max(p.latitude) AS latitude, max(p.longitude) AS longitude, count(p.pokemon_id) AS total_pokemon, s.latest_seen, (LENGTH(s.kind) - LENGTH( REPLACE ( kind, \"s\", \"\") )) * 900 AS duration
574
			          FROM pokemon p 
575
			          INNER JOIN spawnpoint s ON (p.spawnpoint_id = s.id) 
576
			          WHERE p.disappear_time > UTC_TIMESTAMP() - INTERVAL 24 HOUR 
577
			          " . $pokemon_exclude_sql . " 
578
			          GROUP BY p.spawnpoint_id, p.pokemon_id 
579
			          HAVING COUNT(p.pokemon_id) >= 6 
580
			          ORDER BY p.pokemon_id";
581
		$result = $this->mysqli->query($req);
582
		$nests = array();
583
		while ($data = $result->fetch_object()) {
584
			$nests[] = $data;
585
		}
586
		return $nests;
587
	}
588
589
}