Failed Conditions
Pull Request — master (#373)
by Florian
02:49
created

QueryManagerMysqlRealDeviceMap::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Worldopole;
4
5
class QueryManagerMysqlRealDeviceMap extends QueryManagerMysql
6
{
7
    public function __construct()
8
    {
9
        parent::__construct();
10
    }
11
12
    public function __destruct()
13
    {
14
        parent::__destruct();
15
    }
16
17
    ///////////
18
    // Tester
19
    ///////////
20
21
    public function testTotalPokemon()
22
    {
23
        $req = 'SELECT COUNT(*) as total FROM pokemon';
24
        $result = $this->mysqli->query($req);
25
        if (!is_object($result)) {
26
            return 1;
27
        } else {
28
            $data = $result->fetch_object();
29
            $total = $data->total;
30
31
            if (0 == $total) {
32
                return 2;
33
            }
34
        }
35
36
        return 0;
37
    }
38
39
    public function testTotalGyms()
40
    {
41
        $req = 'SELECT COUNT(*) as total FROM gym';
42
        $result = $this->mysqli->query($req);
43
        if (!is_object($result)) {
44
            return 1;
45
        } else {
46
            $data = $result->fetch_object();
47
            $total = $data->total;
48
49
            if (0 == $total) {
50
                return 2;
51
            }
52
        }
53
54
        return 0;
55
    }
56
57
    public function testTotalPokestops()
58
    {
59
        $req = 'SELECT COUNT(*) as total FROM pokestop';
60
        $result = $this->mysqli->query($req);
61
        if (!is_object($result)) {
62
            return 1;
63
        } else {
64
            $data = $result->fetch_object();
65
            $total = $data->total;
66
67
            if (0 == $total) {
68
                return 2;
69
            }
70
        }
71
72
        return 0;
73
    }
74
75
    /////////////
76
    // Homepage
77
    /////////////
78
79
    public function getTotalPokemon()
80
    {
81
        $req = 'SELECT COUNT(*) AS total FROM pokemon WHERE expire_timestamp >= UNIX_TIMESTAMP()';
82
        $result = $this->mysqli->query($req);
83
        $data = $result->fetch_object();
84
85
        return $data;
86
    }
87
88
    public function getTotalLures()
89
    {
90
        $req = 'SELECT COUNT(*) as total FROM pokestop WHERE lure_expire_timestamp >= UNIX_TIMESTAMP()';
91
        $result = $this->mysqli->query($req);
92
        $data = $result->fetch_object();
93
94
        return $data;
95
    }
96
97
    public function getTotalGyms()
98
    {
99
        $req = 'SELECT COUNT(*) AS total FROM gym';
100
        $result = $this->mysqli->query($req);
101
        $data = $result->fetch_object();
102
103
        return $data;
104
    }
105
106
    public function getTotalRaids()
107
    {
108
        $req = 'SELECT COUNT(*) AS total FROM gym WHERE raid_battle_timestamp <= UNIX_TIMESTAMP() AND raid_end_timestamp >= UNIX_TIMESTAMP()';
109
        $result = $this->mysqli->query($req);
110
        $data = $result->fetch_object();
111
112
        return $data;
113
    }
114
115 View Code Duplication
    public function getTotalGymsForTeam($team_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...
116
    {
117
        $req = 'SELECT COUNT(*) AS total FROM gym WHERE team_id = '.$team_id;
118
        $result = $this->mysqli->query($req);
119
        $data = $result->fetch_object();
120
121
        return $data;
122
    }
123
124 View Code Duplication
    public function getRecentAll()
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...
125
    {
126
        $req = 'SELECT pokemon_id, id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
127
              lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina
128
              FROM pokemon
129
              ORDER BY changed DESC
130
              LIMIT 0,12;';
131
        $result = $this->mysqli->query($req);
132
        $data = array();
133
        if ($result->num_rows > 0) {
134
            while ($row = $result->fetch_object()) {
135
                $data[] = $row;
136
            }
137
        }
138
139
        return $data;
140
    }
141
142 View Code Duplication
    public function getRecentMythic($mythic_pokemon)
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...
143
    {
144
        $req = 'SELECT pokemon_id, id as encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
145
                lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina
146
                FROM pokemon
147
                WHERE pokemon_id IN ('.implode(',', $mythic_pokemon).')
148
                ORDER BY changed DESC
149
                LIMIT 0,12';
150
        $result = $this->mysqli->query($req);
151
        $data = array();
152
        if ($result->num_rows > 0) {
153
            while ($row = $result->fetch_object()) {
154
                $data[] = $row;
155
            }
156
        }
157
158
        return $data;
159
    }
160
161
    ///////////////////
162
    // Single Pokemon
163
    ///////////////////
164
165
    public function getGymsProtectedByPokemon($pokemon_id)
166
    {
167
        return array();
168
    }
169
170 View Code Duplication
    public function getPokemonLastSeen($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...
171
    {
172
        $req = "SELECT FROM_UNIXTIME(expire_timestamp) AS expire_timestamp, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude
173
                FROM pokemon
174
                WHERE pokemon_id = '".$pokemon_id."'
175
                ORDER BY expire_timestamp DESC
176
                LIMIT 0,1";
177
        $result = $this->mysqli->query($req);
178
        $data = $result->fetch_object();
179
180
        return $data;
181
    }
182
183 View Code Duplication
    public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction)
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...
184
    {
185
        $req = "SELECT FROM_UNIXTIME(expire_timestamp) AS distime, pokemon_id as pokemon_id, FROM_UNIXTIME(expire_timestamp) as disappear_time, lat as latitude, lon as longitude,
186
                cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina,
187
                iv AS IV, move_1 as move_1, move_2, form
188
                FROM pokemon
189
	            WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0'
190
	            ORDER BY $top_order_by $top_direction, expire_timestamp DESC
191
	            LIMIT 0,50";
192
193
        $result = $this->mysqli->query($req);
194
        $top = array();
195
        while ($data = $result->fetch_object()) {
196
            $top[] = $data;
197
        }
198
199
        return $top;
200
    }
201
202
    public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction)
203
    {
204
        return array();
205
    }
206
207 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...
208
    {
209
        $where = ' WHERE pokemon_id = '.$pokemon_id.' '
210
            ."AND FROM_UNIXTIME(expire_timestamp) BETWEEN '".$start."' AND '".$end."'";
211
        $req = 'SELECT lat AS latitude, lon AS longitude FROM pokemon'.$where.' LIMIT 100000';
212
        $result = $this->mysqli->query($req);
213
        $points = array();
214
        while ($data = $result->fetch_object()) {
215
            $points[] = $data;
216
        }
217
218
        return $points;
219
    }
220
221 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...
222
    {
223
        $req = "SELECT COUNT(*) AS total, HOUR(disappear_time) AS disappear_hour
224
					FROM (SELECT FROM_UNIXTIME(expire_timestamp) as disappear_time FROM pokemon WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered
225
				GROUP BY disappear_hour
226
				ORDER BY disappear_hour";
227
        $result = $this->mysqli->query($req);
228
        $array = array_fill(0, 24, 0);
229
        while ($result && $data = $result->fetch_object()) {
230
            $array[$data->disappear_hour] = $data->total;
231
        }
232
        // shift array because AM/PM starts at 1AM not 0:00
233
        $array[] = $array[0];
234
        array_shift($array);
235
236
        return $array;
237
    }
238
239
    public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons)
240
    {
241
        $inmap_pkms_filter = '';
242
        $where = ' WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = '.$pokemon_id;
243
244
        $reqTestIv = 'SELECT MAX(iv) AS iv FROM pokemon '.$where;
245
        $resultTestIv = $this->mysqli->query($reqTestIv);
246
        $testIv = $resultTestIv->fetch_object();
247
        if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) {
248
            foreach ($inmap_pokemons as $inmap) {
249
                $inmap_pkms_filter .= "'".$inmap."',";
250
            }
251
            $inmap_pkms_filter = rtrim($inmap_pkms_filter, ',');
252
            $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') ';
253
        }
254 View Code Duplication
        if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin) && !($ivMax == 100 && $ivMin == 0)) {
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...
255
            $where .= ' AND iv >= ('.$ivMin.') ';
256
        }
257 View Code Duplication
        if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax) && !($ivMax == 100 && $ivMin == 0)) {
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...
258
            $where .= ' AND iv <= ('.$ivMax.') ';
259
        }
260
        $req = 'SELECT pokemon_id, lat AS latitude, lon AS longitude,
261
    					FROM_UNIXTIME(expire_timestamp) AS disappear_time,
262
    					FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
263
    					atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina,
264
   						move_1, move_2
265
					FROM pokemon '.$where.'
266
					LIMIT 5000';
267
        $result = $this->mysqli->query($req);
268
        $spawns = array();
269
        while ($data = $result->fetch_object()) {
270
            $spawns[] = $data;
271
        }
272
273
        return $spawns;
274
    }
275
276
    public function getPokemonSliderMinMax()
277
    {
278
        $req = 'SELECT FROM_UNIXTIME(MIN(expire_timestamp)) AS min, FROM_UNIXTIME(MAX(expire_timestamp)) AS max FROM pokemon';
279
        $result = $this->mysqli->query($req);
280
        $data = $result->fetch_object();
281
282
        return $data;
283
    }
284
285
    public function getMapsCoords()
286
    {
287
        $req = 'SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoint';
288
        $result = $this->mysqli->query($req);
289
        $data = $result->fetch_object();
290
291
        return $data;
292
    }
293
294 View Code Duplication
    public function getPokemonCount($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...
295
    {
296
        $req = 'SELECT COALESCE(SUM(count),0) as count, MAX(date) as last_seen_day
297
					FROM pokemon_stats
298
					WHERE pokemon_id = '.$pokemon_id;
299
        $result = $this->mysqli->query($req);
300
        $data = $result->fetch_object();
301
302
        return $data;
303
    }
304
305 View Code Duplication
    public function getPokemonCountAll()
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...
306
    {
307
        $req = 'SELECT pokemon_id, SUM(count) as count, MAX(date) as last_seen_day
308
					FROM pokemon_stats
309
					GROUP BY pokemon_id';
310
        $result = $this->mysqli->query($req);
311
        $array = array();
312
        while ($data = $result->fetch_object()) {
313
            $array[] = $data;
314
        }
315
316
        return $array;
317
    }
318
319
320 View Code Duplication
    public function getRaidCount($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...
321
    {
322
        $req = 'SELECT COALESCE(SUM(count),0) as count, MAX(date) as last_seen_day
323
					FROM raid_stats
324
					WHERE pokemon_id = '.$pokemon_id;
325
        $result = $this->mysqli->query($req);
326
        $data = $result->fetch_object();
327
328
        return $data;
329
    }
330
331 View Code Duplication
    public function getRaidCountAll()
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...
332
    {
333
        $req = 'SELECT pokemon_id, SUM(count) as count, MAX(date) as last_seen_day
334
					FROM raid_stats
335
					GROUP BY pokemon_id';
336
        $result = $this->mysqli->query($req);
337
        $array = array();
338
        while ($data = $result->fetch_object()) {
339
            $array[] = $data;
340
        }
341
342
        return $array;
343
    }
344
345
    ///////////////
346
    // Pokestops
347
    //////////////
348
349
    public function getTotalPokestops()
350
    {
351
        $req = 'SELECT COUNT(*) as total FROM pokestop';
352
        $result = $this->mysqli->query($req);
353
        $data = $result->fetch_object();
354
355
        return $data;
356
    }
357
358 View Code Duplication
    public function getAllPokestops()
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...
359
    {
360
        $req = 'SELECT lat as latitude, lon as longitude, lure_expire_timestamp AS lure_expiration, UNIX_TIMESTAMP() AS now, FROM_UNIXTIME(lure_expire_timestamp) AS lure_expiration_real FROM pokestop';
361
        $result = $this->mysqli->query($req);
362
        $pokestops = array();
363
        while ($data = $result->fetch_object()) {
364
            $pokestops[] = $data;
365
        }
366
367
        return $pokestops;
368
    }
369
370
    /////////
371
    // Gyms
372
    /////////
373
374
    public function getTeamGuardians($team_id)
375
    {
376
        return array();
377
    }
378
379 View Code Duplication
    public function getOwnedAndPoints($team_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...
380
    {
381
        $req = "SELECT COUNT(id) AS total, ROUND(AVG(total_cp)) AS average_points
382
        			FROM gym
383
        			WHERE team_id = '".$team_id."'";
384
        $result = $this->mysqli->query($req);
385
        $data = $result->fetch_object();
386
387
        return $data;
388
    }
389
390 View Code Duplication
    public function getAllGyms()
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...
391
    {
392
        $req = 'SELECT id as gym_id, team_id, lat as latitude, lon as longitude, updated as last_scanned, (6 - availble_slots) AS level
393
					FROM gym';
394
        $result = $this->mysqli->query($req);
395
        $gyms = array();
396
        while ($data = $result->fetch_object()) {
397
            $gyms[] = $data;
398
        }
399
400
        return $gyms;
401
    }
402
403 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...
404
    {
405
        $req = "SELECT name, null AS description, url, team_id AS team, FROM_UNIXTIME(updated) AS last_scanned, guarding_pokemon_id AS guard_pokemon_id, (6 - availble_slots) AS level, total_cp
406
                FROM gym
407
                WHERE id = '".$gym_id."'";
408
        $result = $this->mysqli->query($req);
409
        $data = $result->fetch_object();
410
411
        return $data;
412
    }
413
414
    public function getGymDefenders($gym_id)
415
    {
416
        return array();
417
    }
418
419
    ///////////
420
    // Raids
421
    ///////////
422
423
    public function getAllRaids($page)
424
    {
425
        $limit = ' LIMIT '.($page * 10).',10';
426
        $req = 'SELECT id AS gym_id, raid_level AS level, raid_pokemon_id AS pokemon_id, raid_pokemon_cp AS cp, raid_pokemon_move_1 AS move_1, raid_pokemon_move_2 AS move_2, FROM_UNIXTIME(raid_spawn_timestamp) AS spawn, FROM_UNIXTIME(raid_battle_timestamp) AS start, FROM_UNIXTIME(raid_end_timestamp) AS end, FROM_UNIXTIME(updated) AS last_scanned, name, lat AS latitude, lon as longitude
427
                FROM gym
428
                WHERE raid_end_timestamp > UNIX_TIMESTAMP()
429
                ORDER BY raid_level DESC, raid_battle_timestamp'.$limit;
430
        $result = $this->mysqli->query($req);
431
        $raids = array();
432
        while ($data = $result->fetch_object()) {
433
            $raids[] = $data;
434
        }
435
436
        return $raids;
437
    }
438
439
    ////////////////
440
    // Gym History
441
    ////////////////
442
443
    public function getGymHistories($gym_name, $team, $page, $ranking)
444
    {
445
        return array();
446
    }
447
448
    public function getGymHistoriesPokemon($gym_id)
449
    {
450
        return array();
451
    }
452
453
    public function getHistoryForGym($page, $gym_id)
454
    {
455
        return array();
456
    }
457
458
    //////////////
459
    // Trainers
460
    //////////////
461
462
    public function getTrainers($trainer_name, $team, $page, $rankingNumber)
463
    {
464
        return array();
465
    }
466
467
    public function getTrainerLevelRanking()
468
    {
469
        return array();
470
    }
471
472
    public function getActivePokemon($trainer_name)
0 ignored issues
show
Unused Code introduced by
The parameter $trainer_name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
473
    {
474
        return array();
475
    }
476
477
    public function getInactivePokemon($trainer_name)
0 ignored issues
show
Unused Code introduced by
The parameter $trainer_name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
478
    {
479
        return array();
480
    }
481
482
    public function getTrainerLevelCount($team_id)
483
    {
484
        return array();
485
    }
486
487
    /////////
488
    // Cron
489
    /////////
490
491 View Code Duplication
    public function getPokemonCountsActive()
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...
492
    {
493
        $req = 'SELECT pokemon_id, COUNT(*) as total FROM pokemon WHERE expire_timestamp >= UNIX_TIMESTAMP() GROUP BY pokemon_id';
494
        $result = $this->mysqli->query($req);
495
        $counts = array();
496
        while ($data = $result->fetch_object()) {
497
            $counts[$data->pokemon_id] = $data->total;
498
        }
499
500
        return $counts;
501
    }
502
503
    public function getTotalPokemonIV()
504
    {
505
        $req = 'SELECT COUNT(*) as total FROM pokemon WHERE expire_timestamp >= UNIX_TIMESTAMP() AND iv IS NOT NULL';
506
        $result = $this->mysqli->query($req);
507
        $data = $result->fetch_object();
508
509
        return $data;
510
    }
511
512 View Code Duplication
    public function getPokemonCountsLastDay()
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...
513
    {
514
        $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day
515
					FROM pokemon
516
					WHERE expire_timestamp >= (SELECT MAX(expire_timestamp) - 86400 FROM pokemon)
517
					GROUP BY pokemon_id
518
				  	ORDER BY pokemon_id ASC';
519
        $result = $this->mysqli->query($req);
520
        $counts = array();
521
        while ($data = $result->fetch_object()) {
522
            $counts[$data->pokemon_id] = $data->spawns_last_day;
523
        }
524
525
        return $counts;
526
    }
527
528
    public function getCaptchaCount()
529
    {
530
        return ["total"=>0];
531
    }
532
533
    public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
534
    {
535
        $pokemon_exclude_sql = '';
536
        if (!empty(self::$config->system->nest_exclude_pokemon)) {
537
            $pokemon_exclude_sql = 'AND p.pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')';
538
        }
539
540
        $req = 'SELECT p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(p.updated) as latest_seen, 0 as duration
541
			          FROM pokemon p
542
			          WHERE p.expire_timestamp > UNIX_TIMESTAMP() - '.($time * 3600).' AND p.spawn_id IS NOT NULL
543
			            AND p.lat >= '.$minLatitude.' AND p.lat < '.$maxLatitude.' AND p.lon >= '.$minLongitude.' AND p.lon < '.$maxLongitude.'
544
			          '.$pokemon_exclude_sql.'
545
			          GROUP BY p.spawn_id, p.pokemon_id
546
			          HAVING COUNT(p.pokemon_id) >= '.($time / 4).'
547
			          ORDER BY p.pokemon_id';
548
        $result = $this->mysqli->query($req);
549
        $nests = array();
550
        while ($data = $result->fetch_object()) {
551
            $nests[] = $data;
552
        }
553
        $req = 'SELECT p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(p.updated) as latest_seen, 0 as duration
554
			          FROM pokemon p
555
			          WHERE p.expire_timestamp > UNIX_TIMESTAMP() - '.($time * 3600).' AND p.pokestop_id IS NOT NULL
556
			            AND p.lat >= '.$minLatitude.' AND p.lat < '.$maxLatitude.' AND p.lon >= '.$minLongitude.' AND p.lon < '.$maxLongitude.'
557
			          '.$pokemon_exclude_sql.'
558
			          GROUP BY p.pokestop_id, p.pokemon_id
559
			          HAVING COUNT(p.pokemon_id) >= '.($time / 4).'
560
			          ORDER BY p.pokemon_id';
561
        $result = $this->mysqli->query($req);
562
        while ($data = $result->fetch_object()) {
563
            $nests[] = $data;
564
        }
565
566
        return $nests;
567
    }
568
569 View Code Duplication
    public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
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...
570
    {
571
        $req = 'SELECT COUNT(*) as total 
572
					FROM spawnpoint
573
 					WHERE lat >= '.$minLatitude.' AND lat < '.$maxLatitude.' AND lon >= '.$minLongitude.' AND lon < '.$maxLongitude;
574
        $result = $this->mysqli->query($req);
575
        $data = $result->fetch_object();
576
577
        return $data;
578
    }
579
}
580