Failed Conditions
Pull Request — master (#313)
by
unknown
02:39
created

rocketmap.php ➔ req_pokemon_count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 11 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
// Manage Time Interval
4
#######################
5
include_once('../timezone.loader.php');
6
7
8
// Genearl
9
##########
10
11
function req_maps_localization_coordinates()
12
{
13
    return "SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude, MAX(longitude) AS max_longitude, MIN(longitude) AS min_longitude FROM spawnpoint";
14
15
}
16
17
// Pokemon
18
############
19
20
function req_pokemon_count()
21
{
22
    return "SELECT COUNT(*) AS total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()";
23
}
24
25
function req_pokemon_count_id()
26
{
27
    return "SELECT pokemon_id FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()";
28
29
}
30
31
function req_mystic_pokemon($mythic_pokemon)
32
{
33
    global $time_offset;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
34
    return "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '" . $time_offset . "')) AS disappear_time_real,
35
	            latitude, longitude, cp, individual_attack, individual_defense, individual_stamina
36
                FROM pokemon
37
                WHERE pokemon_id IN (" . implode(",", $mythic_pokemon) . ")
38
                ORDER BY last_modified DESC
39
                LIMIT 0,12";
40
}
41
42
function req_all_pokemon()
43
{
44
    global $time_offset;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
45
    return "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, (CONVERT_TZ(disappear_time, '+00:00', '" . $time_offset . "')) AS disappear_time_real,
46
                latitude, longitude, cp, individual_attack, individual_defense, individual_stamina
47
                FROM pokemon
48
                ORDER BY last_modified DESC
49
                LIMIT 0,12";
50
}
51
52
53
// Single Pokemon
54
##########
55
56
function req_pokemon_total_count($pokemon_id)
57
{
58
    return "SELECT COUNT(*) AS pokemon_spawns FROM pokemon WHERE pokemon_id = '" . $pokemon_id . "'";
59
}
60
61
function req_pokemon_total_gym_protected($pokemon_id)
62
{
63
    return "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE guard_pokemon_id = '" . $pokemon_id . "'";
64
}
65
66
function req_pokemon_last_seen($pokemon_id)
67
{
68
    global $time_offset;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
69
    return "SELECT disappear_time, (CONVERT_TZ(disappear_time, '+00:00', '" . $time_offset . "')) AS disappear_time_real, latitude, longitude
70
	            FROM pokemon
71
	            WHERE pokemon_id = '" . $pokemon_id . "'
72
	            ORDER BY disappear_time DESC
73
	            LIMIT 0,1";
74
}
75
76
function req_pokemon_get_top_50($pokemon_id, $top_order_by, $top_direction)
77
{
78
    global $time_offset;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
79
    return "SELECT (CONVERT_TZ(disappear_time, '+00:00', '" . $time_offset . "')) AS distime, pokemon_id, disappear_time, latitude, longitude,
80
	            cp, individual_attack, individual_defense, individual_stamina,
81
	            ROUND(SUM(100*(individual_attack+individual_defense+individual_stamina)/45),1) AS IV, move_1, move_2, form
82
	            FROM pokemon
83
	            WHERE pokemon_id = '" . $pokemon_id . "' AND move_1 IS NOT NULL AND move_1 <> '0'
84
	            GROUP BY encounter_id
85
	            ORDER BY $top_order_by $top_direction, disappear_time DESC
86
	            LIMIT 0,50";
87
}
88
89
function req_pokemon_get_top_trainers($pokemon_id, $best_order_by, $best_direction)
90
{
91
    global $config;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
92
    $trainer_blacklist = "";
93
    if (!empty($config->system->trainer_blacklist)) {
94
        $trainer_blacklist = " AND trainer_name NOT IN ('" . implode("','", $config->system->trainer_blacklist) . "')";
95
    }
96
    return "SELECT trainer_name, ROUND(SUM(100*(iv_attack+iv_defense+iv_stamina)/45),1) AS IV, move_1, move_2, cp,
97
				DATE_FORMAT(last_seen, '%Y-%m-%d') AS lasttime, last_seen
98
				FROM gympokemon
99
				WHERE pokemon_id = '" . $pokemon_id . "'" . $trainer_blacklist . "
100
				GROUP BY pokemon_uid
101
				ORDER BY $best_order_by $best_direction, trainer_name ASC
102
				LIMIT 0,50";
103
}
104
105
function req_pokemon_slider_init()
106
{
107
    return "SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon";
108
}
109
110
function req_pokemon_headmap_points($pokemon_id, $start, $end)
111
{
112
    $where = " WHERE pokemon_id = " . $pokemon_id . " "
113
        . "AND disappear_time BETWEEN '" . $start . "' AND '" . $end . "'";
114
    return "SELECT latitude, longitude FROM pokemon" . $where . " ORDER BY disappear_time DESC LIMIT 10000";
115
}
116
117
function req_pokemon_graph_data($pokemon_id)
118
{
119
    global $time_offset;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
120
    return "SELECT COUNT(*) AS total,
121
			    HOUR(CONVERT_TZ(disappear_time, '+00:00', '" . $time_offset . "')) AS disappear_hour
122
				FROM (SELECT disappear_time FROM pokemon WHERE pokemon_id = '" . $pokemon_id . "' ORDER BY disappear_time LIMIT 10000) AS pokemonFiltered
123
				GROUP BY disappear_hour
124
				ORDER BY disappear_hour";
125
}
126
127
function req_pokemon_live_data_test($pokemon_id)
128
{
129
    $where = " WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = " . $pokemon_id;
130
    return "SELECT MAX(individual_attack) AS iv FROM pokemon " . $where;
131
}
132
133
function req_pokemon_live_data($pokemon_id, $testIv, $post)
134
{
135
    global $mysqli, $time_offset;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
136
    $inmap_pkms_filter = "";
137
    $where = " WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = " . $pokemon_id;
138
    if (isset($post['inmap_pokemons']) && ($post['inmap_pokemons'] != "")) {
139
        foreach ($post['inmap_pokemons'] as $inmap) {
140
            $inmap_pkms_filter .= "'" . $inmap . "',";
141
        }
142
        $inmap_pkms_filter = rtrim($inmap_pkms_filter, ",");
143
        $where .= " AND encounter_id NOT IN (" . $inmap_pkms_filter . ") ";
144
    }
145 View Code Duplication
    if ($testIv->iv != null && isset($post['ivMin']) && ($post['ivMin'] != "")) {
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...
146
        $ivMin = mysqli_real_escape_string($mysqli, $post['ivMin']);
147
        $where .= " AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= (" . $ivMin . ") ";
148
    }
149 View Code Duplication
    if ($testIv->iv != null && isset($post['ivMax']) && ($post['ivMax'] != "")) {
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...
150
        $ivMax = mysqli_real_escape_string($mysqli, $post['ivMax']);
151
        $where .= " AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <=(" . $ivMax . ") ";
152
    }
153
    return "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time,
154
						(CONVERT_TZ(disappear_time, '+00:00', '" . $time_offset . "')) AS disappear_time_real,
155
						individual_attack, individual_defense, individual_stamina, move_1, move_2
156
						FROM pokemon " . $where . "
157
						ORDER BY disappear_time DESC
158
						LIMIT 5000";
159
}
160
161
function req_pokemon_count_24h()
162
{
163
    return "SELECT pokemon_id, COUNT(*) AS spawns_last_day
164
		FROM pokemon
165
		WHERE disappear_time >= (SELECT MAX(disappear_time) FROM pokemon) - INTERVAL 1 DAY
166
		GROUP BY pokemon_id
167
		ORDER BY pokemon_id ASC";
168
}
169
170
171
// Pokestops
172
############
173
174
function req_pokestop_count()
175
{
176
    return "SELECT COUNT(*) AS total FROM pokestop";
177
}
178
179
function req_pokestop_lure_count()
180
{
181
    return "SELECT COUNT(*) AS total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()";
182
}
183
184
function req_pokestop_data()
185
{
186
    global $time_offset;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
187
    return "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() AS now, (CONVERT_TZ(lure_expiration, '+00:00', '" . $time_offset . "')) AS lure_expiration_real FROM pokestop ";
188
}
189
190
// Gyms
191
#######
192
193
function req_gym_count()
194
{
195
    return "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym";
196
}
197
198
function req_gym_count_for_team($team_id)
199
{
200
    return "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE team_id = '$team_id'";
201
}
202
203
function req_gym_guards_for_team($team_id)
204
{
205
    return "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";
206
}
207
208
function req_gym_count_cp_for_team($team_id)
209
{
210
    return "SELECT COUNT(DISTINCT(gym_id)) AS total, ROUND(AVG(total_cp),0) AS average_points FROM gym WHERE team_id = '$team_id'";
211
}
212
213
function req_gym_data()
214
{
215
    global $time_offset;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
216
    return "SELECT gym_id, team_id, latitude, longitude, (CONVERT_TZ(last_scanned, '+00:00', '" . $time_offset . "')) AS last_scanned, (6 - slots_available) AS level FROM gym";
217
}
218
219
function req_gym_data_simple($gym_id)
220
{
221
    global $time_offset;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
222
    return "SELECT gym_id, team_id, guard_pokemon_id, latitude, longitude, (CONVERT_TZ(last_scanned, '+00:00', '" . $time_offset . "')) AS last_scanned, total_cp, (6 - slots_available) AS level
223
				FROM gym WHERE gym_id='" . $gym_id . "'";
224
}
225
226
function req_gym_defender_for($gym_id)
227
{
228
    global $time_offset;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
229
    return "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team,
230
	            (CONVERT_TZ(gym.last_scanned, '+00:00', '" . $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
231
			    FROM gymdetails
232
			    LEFT JOIN gym ON gym.gym_id = gymdetails.gym_id
233
			    WHERE gym.gym_id='" . $gym_id . "'";
234
}
235
236
function req_gym_defender_stats_for($gym_id)
237
{
238
    return "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id
239
			    FROM gympokemon INNER JOIN gymmember ON gympokemon.pokemon_uid=gymmember.pokemon_uid
240
			    GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id
241
			    HAVING gymmember.gym_id='" . $gym_id . "'
242
			    ORDER BY cp DESC";
243
}
244
245
// Trainer
246
##########
247
248
function req_trainers($get)
249
{
250
    global $config, $mysqli;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
251
    $name = "";
0 ignored issues
show
Unused Code introduced by
$name 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...
252
    $page = "0";
253
    $where = "";
254
    $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...
255
    $team = 0;
0 ignored issues
show
Unused Code introduced by
$team 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...
256
    $ranking = 0;
257
    if (isset($get['name'])) {
258
        $trainer_name = mysqli_real_escape_string($mysqli, $get['name']);
259
        $where = " HAVING name LIKE '%" . $trainer_name . "%'";
260
    }
261
    if (isset($get['team']) && $get['team'] != 0) {
262
        $team = mysqli_real_escape_string($mysqli, $get['team']);
263
        $where .= ($where == "" ? " HAVING" : " AND") . " team = " . $team;
264
    }
265
    if (!empty($config->system->trainer_blacklist)) {
266
        $where .= ($where == "" ? " HAVING" : " AND") . " name NOT IN ('" . implode("','", $config->system->trainer_blacklist) . "')";
267
    }
268
    if (isset($get['page'])) {
269
        $page = mysqli_real_escape_string($mysqli, $get['page']);
270
    }
271
    if (isset($get['ranking'])) {
272
        $ranking = mysqli_real_escape_string($mysqli, $get['ranking']);
273
    }
274
275
    switch ($ranking) {
276
        case 1:
277
            $order = " ORDER BY active DESC, level DESC";
278
            break;
279
        case 2:
280
            $order = " ORDER BY maxCp DESC, level DESC";
281
            break;
282
        default:
283
            $order = " ORDER BY level DESC, active DESC";
284
    }
285
    $order .= ", last_seen DESC, name ";
286
    $limit = " LIMIT " . ($page * 10) . ",10 ";
287
    return "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp
288
				FROM trainer
289
				LEFT JOIN (SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.trainer_name, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned
290
				FROM gympokemon
291
				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
292
				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name
293
				GROUP BY trainer.name " . $where . $order . $limit;
294
}
295
296
function req_trainer_active_pokemon($name)
297
{
298
    global $time_offset;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
299
    return "(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', '" . $time_offset . "') as deployment_time, '1' AS active
300
	            FROM gympokemon INNER JOIN
301
				(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
302
				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
303
				WHERE gympokemon.trainer_name='" . $name . "'
304
				ORDER BY gympokemon.cp DESC)";
305
}
306
307
function req_trainer_inactive_pokemon($name)
308
{
309
    global $time_offset;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
310
    return "(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', '" . $time_offset . "') as deployment_time, '0' AS active
311
				FROM gympokemon LEFT JOIN
312
				(SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember
313
				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
314
				WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='" . $name . "'
315
				ORDER BY gympokemon.cp DESC)";
316
}
317
318
function req_trainer_ranking($trainer)
319
{
320
    global $config;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
321
    $reqRanking = "SELECT COUNT(1) AS rank FROM trainer WHERE level = " . $trainer->level;
322
    if (!empty($config->system->trainer_blacklist)) {
323
        $reqRanking .= " AND name NOT IN ('" . implode("','", $config->system->trainer_blacklist) . "')";
324
    }
325
    return $reqRanking;
326
}
327
328 View Code Duplication
function req_trainer_levels_for_team($teamid)
0 ignored issues
show
Duplication introduced by
This function 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...
329
{
330
    global $config;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
331
    $reqLevels = "SELECT level, count(level) AS count FROM trainer WHERE team = '" . $teamid . "'";
332
    if (!empty($config->system->trainer_blacklist)) {
333
        $reqLevels .= " AND name NOT IN ('" . implode("','", $config->system->trainer_blacklist) . "')";
334
    }
335
    $reqLevels .= " GROUP BY level";
336
    return $reqLevels;
337
}
338
339
// Raids
340
########
341
342
function req_raids_data($page)
343
{
344
    global $time_offset;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
345
    $limit = " LIMIT " . ($page * 10) . ",10";
346
    return "SELECT raid.gym_id, raid.level, raid.pokemon_id, raid.cp, raid.move_1, raid.move_2, CONVERT_TZ(raid.spawn, '+00:00', '" . $time_offset . "') AS spawn, CONVERT_TZ(raid.start, '+00:00', '" . $time_offset . "') AS start, CONVERT_TZ(raid.end, '+00:00', '" . $time_offset . "') AS end, CONVERT_TZ(raid.last_scanned, '+00:00', '" . $time_offset . "') AS last_scanned, gymdetails.name, gym.latitude, gym.longitude FROM raid
347
				JOIN gymdetails ON gymdetails.gym_id = raid.gym_id
348
				JOIN gym ON gym.gym_id = raid.gym_id
349
				WHERE raid.end > UTC_TIMESTAMP()
350
				ORDER BY raid.level DESC, raid.start" . $limit;
351
}
352
353
// Captcha
354
##########
355
356
function req_captcha_count()
357
{
358
    return "SELECT SUM(accounts_captcha) AS total FROM mainworker";
359
360
}
361
362
// Test
363
#######
364
365
function req_tester_pokemon()
366
{
367
    return "SELECT COUNT(*) AS total FROM pokemon";
368
}
369
370
function req_tester_gym()
371
{
372
    return "SELECT COUNT(*) AS total FROM gym";
373
}
374
375
function req_tester_pokestop()
376
{
377
    return "SELECT COUNT(*) AS total FROM pokestop";
378
}
379
380
// Nests
381
########
382
383 View Code Duplication
function req_map_data()
0 ignored issues
show
Duplication introduced by
This function 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...
384
{
385
    global $config;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
386
    $pokemon_exclude_sql = "";
387
    if (!empty($config->system->nest_exclude_pokemon)) {
388
        $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", $config->system->nest_exclude_pokemon) . ")";
389
    }
390
    return "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
391
          FROM pokemon p 
392
          INNER JOIN spawnpoint s ON (p.spawnpoint_id = s.id) 
393
          WHERE p.disappear_time > UTC_TIMESTAMP() - INTERVAL 24 HOUR 
394
          " . $pokemon_exclude_sql . " 
395
          GROUP BY p.spawnpoint_id, p.pokemon_id 
396
          HAVING COUNT(p.pokemon_id) >= 6 
397
          ORDER BY p.pokemon_id";
398
}