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

QueryManagerRocketmap   D

Complexity

Total Complexity 92

Size/Duplication

Total Lines 586
Duplicated Lines 39.42 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

39 Methods

Rating   Name   Duplication   Size   Complexity  
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 10 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 41 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
6
	///////////
7
	// Tester
8
	///////////
9
	
10 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...
11
		$req = "SELECT COUNT(*) as total FROM pokemon";
12
		$result = $this->mysqli->query($req);
13
		if (!is_object($result)) {
14
			return 1;
15
		} else {
16
			$data = $result->fetch_object();
17
			$total = $data->total;
18
	
19
			if ($total == 0) {
20
				return 2;
21
			}
22
		}
23
		return 0;
24
	}
25
	
26 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...
27
		$req = "SELECT COUNT(*) as total FROM gym";
28
		$result = $this->mysqli->query($req);
29
		if (!is_object($result)) {
30
			return 1;
31
		} else {
32
			$data = $result->fetch_object();
33
			$total = $data->total;
34
	
35
			if ($total == 0) {
36
				return 2;
37
			}
38
		}
39
		return 0;
40
	}
41
	
42 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...
43
		$req = "SELECT COUNT(*) as total FROM pokestop";
44
		$result = $this->mysqli->query($req);
45
		if (!is_object($result)) {
46
			return 1;
47
		} else {
48
			$data = $result->fetch_object();
49
			$total = $data->total;
50
	
51
			if ($total == 0) {
52
				return 2;
53
			}
54
		}
55
		return 0;
56
	}
57
	
58
	
59
	/////////////
60
	// Homepage
61
	/////////////
62
	
63
	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...
64
		$req = "SELECT COUNT(*) AS total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()";
65
		$result = $this->mysqli->query($req);
66
		$data = $result->fetch_object();
67
		return $data;
68
	}
69
	
70
	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...
71
		$req = "SELECT COUNT(*) AS total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()";
72
		$result = $this->mysqli->query($req);
73
		$data = $result->fetch_object();
74
		return $data;
75
	}
76
	
77
	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...
78
		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym";
79
		$result = $this->mysqli->query($req);
80
		$data = $result->fetch_object();
81
		return $data;
82
	}
83
	
84
	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...
85
		$req = "SELECT COUNT(*) AS total FROM raid WHERE start <= UTC_TIMESTAMP AND  end >= UTC_TIMESTAMP()";
86
		$result = $this->mysqli->query($req);
87
		$data = $result->fetch_object();
88
		return $data;
89
	}
90
	
91
	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...
92
		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE team_id = '".$team_id."'";
93
		$result = $this->mysqli->query($req);
94
		$data = $result->fetch_object();
95
		return $data;
96
	}
97
	
98
	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...
99
		$req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '".$this->time_offset."')) AS disappear_time_real,
100
					latitude, longitude, cp, individual_attack, individual_defense, individual_stamina
101
					FROM pokemon
102
					ORDER BY last_modified DESC
103
					LIMIT 0,12";
104
		$result = $this->mysqli->query($req);
105
		$data = array();
106
		if ($result->num_rows > 0) {
107
			while ($row = $result->fetch_object()) {
108
				$data[] = $row;
109
			}
110
		}
111
		return $data;
112
	}
113
	
114
	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...
115
		$req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '".$this->time_offset."')) AS disappear_time_real,
116
					latitude, longitude, cp, individual_attack, individual_defense, individual_stamina
117
					FROM pokemon
118
					WHERE pokemon_id IN (".implode(",", $mythic_pokemons).")
119
					ORDER BY last_modified DESC
120
					LIMIT 0,12";
121
		$result = $this->mysqli->query($req);
122
		$data = array();
123
		if ($result->num_rows > 0) {
124
			while ($row = $result->fetch_object()) {
125
				$data[] = $row;
126
			}
127
		}
128
		return $data;
129
	}
130
	
131
	///////////////////
132
	// Single Pokemon
133
	///////////////////
134
	
135 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...
136
		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE guard_pokemon_id = '".$pokemon_id."'";
137
		$result = $this->mysqli->query($req);
138
		$data = $result->fetch_object();
139
		return $data;
140
	}
141
	
142 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...
143
		$req = "SELECT disappear_time, (CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real, latitude, longitude
144
							FROM pokemon
145
							WHERE pokemon_id = '".$pokemon_id."'
146
							ORDER BY disappear_time DESC
147
							LIMIT 0,1";
148
		$result = $this->mysqli->query($req);
149
		$data = $result->fetch_object();
150
		return $data;
151
	}
152
153
	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...
154
		$req = "SELECT (CONVERT_TZ(disappear_time, '+00:00', '".$this->time_offset."')) AS distime, pokemon_id, disappear_time, latitude, longitude,
155
							cp, individual_attack, individual_defense, individual_stamina,
156
							ROUND(100*(individual_attack+individual_defense+individual_stamina)/45,1) AS IV, move_1, move_2, form
157
							FROM pokemon
158
							WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0'
159
							GROUP BY encounter_id
160
							ORDER BY $top_order_by $top_direction, disappear_time DESC
161
							LIMIT 0,50";
162
163
		$result = $this->mysqli->query($req);
164
		$top = array();
165
		while ($data = $result->fetch_object()) {
166
			$top[] = $data;
167
		}
168
		return $top;
169
	}
170
171 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...
172
		$trainer_blacklist = "";
173
		if (!empty(self::$config->system->trainer_blacklist)) {
174
			$trainer_blacklist = " AND trainer_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
175
		}
176
177
		$req = "SELECT trainer_name, ROUND(SUM(100*(iv_attack+iv_defense+iv_stamina)/45),1) AS IV, move_1, move_2, cp,
178
						DATE_FORMAT(last_seen, '%Y-%m-%d') AS lasttime, last_seen
179
						FROM gympokemon
180
						WHERE pokemon_id = '".$pokemon_id."'".$trainer_blacklist."
181
						GROUP BY pokemon_uid
182
						ORDER BY $best_order_by $best_direction, trainer_name ASC
183
						LIMIT 0,50";
184
185
		$result = $this->mysqli->query($req);
186
		$toptrainer = array();
187
		while ($data = $result->fetch_object()) {
188
			$toptrainer[] = $data;
189
		}
190
		return $toptrainer;
191
	}
192
193 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...
194
		$where = " WHERE pokemon_id = ".$pokemon_id." "
195
			. "AND disappear_time BETWEEN '".$start."' AND '".$end."'";
196
		$req 		= "SELECT latitude, longitude FROM pokemon".$where." ORDER BY disappear_time DESC LIMIT 10000";
197
		$result = $this->mysqli->query($req);
198
		$points = array();
199
		while ($data = $result->fetch_object()) {
200
			$points[] = $data;
201
		}
202
		return $points;
203
	}
204
205 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...
206
		$req = "SELECT COUNT(*) AS total,
207
					HOUR(CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_hour
208
					FROM (SELECT disappear_time FROM pokemon WHERE pokemon_id = '".$pokemon_id."' ORDER BY disappear_time LIMIT 100000) AS pokemonFiltered
209
					GROUP BY disappear_hour
210
					ORDER BY disappear_hour";
211
		$result = $this->mysqli->query($req);
212
		$array = array_fill(0, 24, 0);
213
		while ($result && $data = $result->fetch_object()) {
214
			$array[$data->disappear_hour] = $data->total;
215
		}
216
		// shift array because AM/PM starts at 1AM not 0:00
217
		$array[] = $array[0];
218
		array_shift($array);
219
		return $array;
220
	}
221
222 View Code Duplication
	public  function getPokemonLive($pokemon_id, $ivMin, $ivMax) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

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

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

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

// Better
class Router
{
    private $host;

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

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

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

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
223
		$inmap_pkms_filter = "";
224
		$where = " WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = ".$pokemon_id;
225
226
		$reqTestIv = "SELECT MAX(individual_attack) AS iv FROM pokemon ".$where;
227
		$resultTestIv = $this->mysqli->query($reqTestIv);
228
		$testIv = $resultTestIv->fetch_object();
229
		if (isset($_POST['inmap_pokemons']) && ($_POST['inmap_pokemons'] != "")) {
230
			foreach ($_POST['inmap_pokemons'] as $inmap) {
231
				$inmap_pkms_filter .= "'".$inmap."',";
232
			}
233
			$inmap_pkms_filter = rtrim($inmap_pkms_filter, ",");
234
			$where .= " AND encounter_id NOT IN (".$inmap_pkms_filter.") ";
235
		}
236
		if ($testIv->iv != null && isset($_POST['ivMin']) && ($_POST['ivMin'] != "")) {
237
			$where .= " AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= (".$ivMin.") ";
238
		}
239
		if ($testIv->iv != null && isset($_POST['ivMax']) && ($_POST['ivMax'] != "")) {
240
			$where .= " AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= (".$ivMax.") ";
241
		}
242
		$req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time,
243
						(CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_time_real,
244
						individual_attack, individual_defense, individual_stamina, move_1, move_2
245
						FROM pokemon ".$where."
246
						ORDER BY disappear_time DESC
247
						LIMIT 5000";
248
		$result = $this->mysqli->query($req);
249
		$spawns = array();
250
		while ($data = $result->fetch_object()) {
251
			$spawns[] = $data;
252
		}
253
		return $spawns;
254
	}
255
256
	public function getPokemonSliederMinMax() {
257
		$req = "SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon";
258
		$result = $this->mysqli->query($req);
259
		$data = $result->fetch_object();
260
		return $data;
261
	}
262
263
	public function getMapsCoords() {
264
		$req = "SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude, MAX(longitude) AS max_longitude, MIN(longitude) as min_longitude FROM spawnpoint";
265
		$result = $this->mysqli->query($req);
266
		$data = $result->fetch_object();
267
		return $data;
268
	}
269
270
271
	///////////////
272
	// Pokestops
273
	//////////////
274
275
	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...
276
		$req = "SELECT COUNT(*) as total FROM pokestop";
277
		$result = $this->mysqli->query($req);
278
		$data = $result->fetch_object();
279
		return $data;
280
	}
281
282
	public  function getAllPokestops()
0 ignored issues
show
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
283
	{
284
		$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";
285
		$result = $this->mysqli->query($req);
286
		$pokestops = array();
287
		while ($data = $result->fetch_object()) {
288
			$pokestops[] = $data;
289
		}
290
		return $pokestops;
291
	}
292
293
294
	/////////
295
	// Gyms
296
	/////////
297
298
	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...
299
		$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";
300
		$result = $this->mysqli->query($req);
301
		$datas = array();
302
		while ($data = $result->fetch_object()) {
303
			$datas[] = $data;
304
		}
305
		return $datas;
306
	}
307
308
	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...
309
		$req 	= "SELECT COUNT(DISTINCT(gym_id)) AS total, ROUND(AVG(total_cp),0) AS average_points FROM gym WHERE team_id = '".$team_id."'";
310
		$result = $this->mysqli->query($req);
311
		$data = $result->fetch_object();
312
		return $data;
313
	}
314
315
	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...
316
		$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";
317
		$result = $this->mysqli->query($req);
318
		$gyms = array();
319
		while ($data = $result->fetch_object()) {
320
			$gyms[] = $data;
321
		}
322
		return $gyms;
323
	}
324
325 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...
326
		$gym_id = $this->mysqli->real_escape_string($_GET['gym_id']);
327
		$req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team,
328
					(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
329
					FROM gymdetails
330
					LEFT JOIN gym ON gym.gym_id = gymdetails.gym_id
331
					WHERE gym.gym_id='".$gym_id."'";
332
		$result = $this->mysqli->query($req);
333
		$data = $result->fetch_object();
334
		return $data;
335
	}
336
337
	public function getGymDefenders($gym_id) {
338
		$req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id
339
					FROM gympokemon INNER JOIN gymmember ON gympokemon.pokemon_uid=gymmember.pokemon_uid
340
					GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id
341
					HAVING gymmember.gym_id='".$gym_id."'
342
					ORDER BY cp DESC";
343
		$result = $this->mysqli->query($req);
344
		$defenders = array();
345
		while ($data = $result->fetch_object()) {
346
			$defenders[] = $data;
347
		}
348
		return $defenders;
349
	}
350
351
352
	///////////
353
	// Raids
354
	///////////
355
356
	public function getAllRaids($page) {
357
		$limit = " LIMIT ".($page * 10).",10";
358
		$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
359
					JOIN gymdetails ON gymdetails.gym_id = raid.gym_id
360
					JOIN gym ON gym.gym_id = raid.gym_id
361
					WHERE raid.end > UTC_TIMESTAMP()
362
					ORDER BY raid.level DESC, raid.start".$limit;
363
		$result = $this->mysqli->query($req);
364
		$raids = array();
365
		while ($data = $result->fetch_object()) {
366
			$raids[] = $data;
367
		}
368
		return $raids;
369
	}
370
371
372
	//////////////
373
	// Trainers
374
	//////////////
375
376
	public function getTrainers($trainer_name, $team, $page, $ranking) {
377
		$trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking);
378
		foreach ($trainers as $trainer) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
379
380
			$trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank;
381
382
			$active_gyms = 0;
383
			$pkmCount = 0;
384
385
			$trainer->pokemons = array();
386
			$active_pokemon = $this->getTrainerActivePokemon($trainer->name);
387
			foreach ($active_pokemon as $pokemon) {
388
				$active_gyms++;
389
				$trainer->pokemons[$pkmCount++] = $pokemon;
390
			}
391
392
			$inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name);
393
			foreach ($inactive_pokemon as $pokemon) {
394
				$trainer->pokemons[$pkmCount++] = $pokemon;
395
			}
396
			$trainer->gyms = "".$active_gyms;
397
		}
398
		return $trainers;
399
	}
400
401
	public function getTrainerLevelCount($team_id) {
402
		$req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'";
403
		if (!empty(self::$config->system->trainer_blacklist)) {
404
			$req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
405
		}
406
		$req .= " GROUP BY level";
407
		$result = $this->mysqli->query($req);
408
		$levelData = array();
409
		while ($data = $result->fetch_object()) {
410
			$levelData[$data['level']] = $data['count'];
411
		}
412 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...
413
			if (!isset($levelData[$i])) {
414
				$levelData[$i] = 0;
415
			}
416
		}
417
		# sort array again
418
		ksort($levelData);
419
		return $levelData;
420
	}
421
422
	private function getTrainerData($trainer_name, $team, $page, $ranking) {
423
		$where = "";
424
		$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...
425
426
		if (!empty(self::$config->system->trainer_blacklist)) {
427
			$where .= ($where == "" ? " HAVING" : " AND")." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
428
		}
429
		if ($trainer_name != "") {
430
			$where = " HAVING name LIKE '%".$trainer_name."%'";
431
		}
432
		if ($team != 0) {
433
			$where .= ($where == "" ? " HAVING" : " AND")." team = ".$team;
434
		}
435
		switch ($ranking) {
436
			case 1:
437
				$order = " ORDER BY active DESC, level DESC";
438
				break;
439
			case 2:
440
				$order = " ORDER BY maxCp DESC, level DESC";
441
				break;
442
			default:
443
				$order = " ORDER BY level DESC, active DESC";
444
		}
445
		$order .= ", last_seen DESC, name ";
446
		$limit = " LIMIT ".($page * 10).",10 ";
447
		$req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp
448
				FROM trainer
449
				LEFT JOIN (SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.trainer_name, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned
450
				FROM gympokemon
451
				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
452
				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name
453
				GROUP BY trainer.name " . $where.$order.$limit;
454
455
		$result = $this->mysqli->query($req);
456
		$trainers = array();
457
		while ($data = $result->fetch_object()) {
458
			$data->last_seen = date("Y-m-d", strtotime($data->last_seen));
459
			$trainers[$data->name] = $data;
460
		}
461
		return $trainers;
462
	}
463
464
	private function getTrainerLevelRating($level) {
465
		$req = "SELECT COUNT(1) AS rank FROM trainer WHERE level = ".$level;
466
		if (!empty(self::$config->system->trainer_blacklist)) {
467
			$req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
468
		}
469
		$result = $this->mysqli->query($req);
470
		$data = $result->fetch_object();
471
		return $data;
472
	}
473
474 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...
475
		$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
476
					FROM gympokemon INNER JOIN
477
					(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
478
					ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
479
					WHERE gympokemon.trainer_name='".$trainer_name."'
480
					ORDER BY gympokemon.cp DESC)";
481
		$result = $this->mysqli->query($req);
482
		$pokemons = array();
483
		while ($data = $result->fetch_object()) {
484
			$pokemons[] = $data;
485
		}
486
		return $pokemons;
487
	}
488
489 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...
490
		$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
491
					FROM gympokemon LEFT JOIN
492
					(SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember
493
					ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
494
					WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."'
495
					ORDER BY gympokemon.cp DESC)";
496
		$result = $this->mysqli->query($req);
497
		$pokemons = array();
498
		while ($data = $result->fetch_object()) {
499
			$pokemons[] = $data;
500
		}
501
		return $pokemons;
502
	}
503
504
505
	/////////
506
	// Cron
507
	/////////
508
509
	public function getPokemonCountsActive() {
510
		$req = "SELECT pokemon_id, COUNT(*) as total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP() GROUP BY pokemon_id";
511
		$result = $this->mysqli->query($req);
512
		$counts = array();
513
		while ($data = $result->fetch_object()) {
514
			$counts[$data->pokemon_id] = $data->total;
515
		}
516
		return $counts;
517
	}
518
519
	public  function getPoekmonCountsLastDay() {
0 ignored issues
show
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
520
		$req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day
521
					FROM pokemon
522
					WHERE disappear_time >= (SELECT MAX(disappear_time) FROM pokemon) - INTERVAL 1 DAY
523
					GROUP BY pokemon_id
524
				  	ORDER BY pokemon_id ASC";
525
		$result = $this->mysqli->query($req);
526
		$counts = array();
527
		while ($data = $result->fetch_object()) {
528
			$counts[$data->pokemon_id] = $data->spawns_last_day;
529
		}
530
		return $counts;
531
	}
532
533 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...
534
		$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 
535
				FROM pokemon 
536
				WHERE pokemon_id = '".$pokemon_id."' && UNIX_TIMESTAMP(disappear_time) > '".$last_update."'";
537
		$result = $this->mysqli->query($req);
538
		$data = $result->fetch_object();
539
		return $data;
540
	}
541
542 View Code Duplication
	public  function getRaidsSinceLastUpdate($pokemon_id, $last_update) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
543
		$where = "WHERE pokemon_id = '".$pokemon_id."' && UNIX_TIMESTAMP(start) > '".$last_update."'";
544
		$req = "SELECT UNIX_TIMESTAMP(start) as start_timestamp, end, (CONVERT_TZ(end, '+00:00', '".self::$time_offset."')) AS end_time_real, latitude, longitude, count
545
                FROM raid r
546
                JOIN gym g
547
                JOIN (SELECT count(*) as count
548
                    FROM raid
549
                    " . $where."
550
                ) x
551
                ON r.gym_id = g.gym_id
552
                " . $where."
553
                ORDER BY start DESC
554
                LIMIT 0,1";
555
		$result = $this->mysqli->query($req);
556
		$data = $result->fetch_object();
557
		return $data;
558
	}
559
560
	public  function getCaptchaCount() {
0 ignored issues
show
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
561
		$req = "SELECT SUM(accounts_captcha) AS total FROM mainworker";
562
		$result = $this->mysqli->query($req);
563
		$data = $result->fetch_object();
564
		return $data;
565
	}
566
567 View Code Duplication
	public  function getNestData() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
Coding Style introduced by
Scope keyword "public" must be followed by a single space
Loading history...
568
		$pokemon_exclude_sql = "";
569
		if (!empty(self::$config->system->nest_exclude_pokemon)) {
570
			$pokemon_exclude_sql = "AND p.pokemon_id NOT IN (".implode(",", self::$config->system->nest_exclude_pokemon).")";
571
		}
572
		$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
573
			          FROM pokemon p 
574
			          INNER JOIN spawnpoint s ON (p.spawnpoint_id = s.id) 
575
			          WHERE p.disappear_time > UTC_TIMESTAMP() - INTERVAL 24 HOUR 
576
			          " . $pokemon_exclude_sql . " 
577
			          GROUP BY p.spawnpoint_id, p.pokemon_id 
578
			          HAVING COUNT(p.pokemon_id) >= 6 
579
			          ORDER BY p.pokemon_id";
580
		$result = $this->mysqli->query($req);
581
		$nests = array();
582
		while ($data = $result->fetch_object()) {
583
			$nests[] = $data;
584
		}
585
		return $nests;
586
	}
587
588
}