Failed Conditions
Pull Request — master (#312)
by
unknown
02:18
created

rocketmap.php ➔ req_mystic_pokemon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 10
rs 9.4285
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
    if (isset($get['name'])) {
252
        $trainer_name = mysqli_real_escape_string($mysqli, $get['name']);
253
        $where = " HAVING name LIKE '%" . $trainer_name . "%'";
254
    }
255
    if (isset($get['team']) && $get['team'] != 0) {
256
        $team = mysqli_real_escape_string($mysqli, $get['team']);
257
        $where .= ($where == "" ? " HAVING" : " AND") . " team = " . $team;
0 ignored issues
show
Bug introduced by
The variable $where does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
258
    }
259
    if (!empty($config->system->trainer_blacklist)) {
260
        $where .= ($where == "" ? " HAVING" : " AND") . " name NOT IN ('" . implode("','", $config->system->trainer_blacklist) . "')";
261
    }
262
    if (isset($get['page'])) {
263
        $page = mysqli_real_escape_string($mysqli, $get['page']);
264
    }
265
    if (isset($get['ranking'])) {
266
        $ranking = mysqli_real_escape_string($mysqli, $get['ranking']);
267
    }
268
269
    switch ($ranking) {
0 ignored issues
show
Bug introduced by
The variable $ranking does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
270
        case 1:
271
            $order = " ORDER BY active DESC, level DESC";
272
            break;
273
        case 2:
274
            $order = " ORDER BY maxCp DESC, level DESC";
275
            break;
276
        default:
277
            $order = " ORDER BY level DESC, active DESC";
278
    }
279
    $order .= ", last_seen DESC, name ";
280
    $limit = " LIMIT " . ($page * 10) . ",10 ";
0 ignored issues
show
Bug introduced by
The variable $page does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
281
    return "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp
282
				FROM trainer
283
				LEFT JOIN (SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.trainer_name, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned
284
				FROM gympokemon
285
				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
286
				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name
287
				GROUP BY trainer.name " . $where . $order . $limit;
288
}
289
290
function req_trainer_active_pokemon($name)
291
{
292
    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...
293
    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
294
	            FROM gympokemon INNER JOIN
295
				(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
296
				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
297
				WHERE gympokemon.trainer_name='" . $name . "'
298
				ORDER BY gympokemon.cp DESC)";
299
}
300
301
function req_trainer_inactive_pokemon($name)
302
{
303
    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...
304
    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
305
				FROM gympokemon LEFT JOIN
306
				(SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember
307
				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
308
				WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='" . $name . "'
309
				ORDER BY gympokemon.cp DESC)";
310
}
311
312
function req_trainer_ranking($trainer)
313
{
314
    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...
315
    $reqRanking = "SELECT COUNT(1) AS rank FROM trainer WHERE level = " . $trainer->level;
316
    if (!empty($config->system->trainer_blacklist)) {
317
        $reqRanking .= " AND name NOT IN ('" . implode("','", $config->system->trainer_blacklist) . "')";
318
    }
319
    return $reqRanking;
320
}
321
322 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...
323
{
324
    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...
325
    $reqLevels = "SELECT level, count(level) AS count FROM trainer WHERE team = '" . $teamid . "'";
326
    if (!empty($config->system->trainer_blacklist)) {
327
        $reqLevels .= " AND name NOT IN ('" . implode("','", $config->system->trainer_blacklist) . "')";
328
    }
329
    $reqLevels .= " GROUP BY level";
330
    return $reqLevels;
331
}
332
333
// Raids
334
########
335
336
function req_raids_data($page)
337
{
338
    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...
339
    $limit = " LIMIT " . ($page * 10) . ",10";
340
    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
341
				JOIN gymdetails ON gymdetails.gym_id = raid.gym_id
342
				JOIN gym ON gym.gym_id = raid.gym_id
343
				WHERE raid.end > UTC_TIMESTAMP()
344
				ORDER BY raid.level DESC, raid.start" . $limit;
345
}
346
347
// Captcha
348
##########
349
350
function req_captcha_count()
351
{
352
    return "SELECT SUM(accounts_captcha) AS total FROM mainworker";
353
354
}
355
356
// Test
357
#######
358
359
function req_tester_pokemon()
360
{
361
    return "SELECT COUNT(*) AS total FROM pokemon";
362
}
363
364
function req_tester_gym()
365
{
366
    return "SELECT COUNT(*) AS total FROM gym";
367
}
368
369
function req_tester_pokestop()
370
{
371
    return "SELECT COUNT(*) AS total FROM pokestop";
372
}
373
374
// Nests
375
########
376
377 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...
378
{
379
    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...
380
    $pokemon_exclude_sql = "";
381
    if (!empty($config->system->nest_exclude_pokemon)) {
382
        $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", $config->system->nest_exclude_pokemon) . ")";
383
    }
384
    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
385
          FROM pokemon p 
386
          INNER JOIN spawnpoint s ON (p.spawnpoint_id = s.id) 
387
          WHERE p.disappear_time > UTC_TIMESTAMP() - INTERVAL 24 HOUR 
388
          " . $pokemon_exclude_sql . " 
389
          GROUP BY p.spawnpoint_id, p.pokemon_id 
390
          HAVING COUNT(p.pokemon_id) >= 6 
391
          ORDER BY p.pokemon_id";
392
}