Completed
Push — master ( 8b0327...527817 )
by Yannick
07:05
created

Stats   D

Complexity

Total Complexity 296

Size/Duplication

Total Lines 1391
Duplicated Lines 50.9 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 708
loc 1391
rs 4.4102
c 0
b 0
f 0
wmc 296
lcom 1
cbo 4

61 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getLastStatsUpdate() 11 11 2
A countAllAircraftTypes() 0 16 4
A countAllPilots() 0 16 4
A countAllOwners() 0 16 4
A countAllDates() 16 16 3
A getAllAirlineNames() 0 11 2
A getAllAircraftTypes() 0 11 2
A getAllAirportNames() 0 11 2
A countAllAirlineCountries() 0 17 4
A countAllAircraftManufacturers() 0 16 4
A countAllArrivalCountries() 0 16 4
A countAllDepartureCountries() 0 16 4
A countAllAirlines() 0 16 4
A countAllAircraftRegistrations() 0 16 4
A countAllCallsigns() 0 16 4
B countAllFlightOverCountries() 0 23 4
C countAllDepartureAirports() 34 34 8
C countAllArrivalAirports() 34 34 8
B countAllMonthsLastYear() 0 23 6
A countAllDatesLastMonth() 16 16 3
A countAllDatesLast7Days() 0 21 4
A countAllMonths() 15 15 3
A countAllMilitaryMonths() 15 15 3
A addLastStatsUpdate() 11 11 2
C countAllHours() 0 26 7
A countOverallFlights() 8 8 2
A countOverallMilitaryFlights() 8 8 2
A countOverallArrival() 8 8 2
A countOverallAircrafts() 8 8 2
A countOverallAirlines() 8 8 2
A countOverallOwners() 8 8 2
A countOverallPilots() 8 8 2
A getLast7DaysAirports() 12 12 2
A getStats() 12 12 2
A getSumStats() 17 17 3
A getStatsTotal() 0 17 3
A getStatsAircraftTotal() 16 16 3
A getStatsAirlineTotal() 16 16 3
A getStatsOwnerTotal() 16 16 3
A getStatsPilotTotal() 16 16 3
A addStat() 15 15 3
A updateStat() 16 16 3
A getStatsSource() 17 17 3
A addStatSource() 15 15 3
A addStatFlight() 10 10 2
A addStatAircraftRegistration() 15 15 3
A addStatCallsign() 15 15 3
A addStatCountry() 15 15 3
A addStatAircraft() 15 15 3
A addStatAirline() 15 15 3
A addStatOwner() 15 15 3
A addStatPilot() 15 15 3
A addStatDepartureAirports() 15 15 3
A addStatDepartureAirportsDaily() 15 15 3
A addStatArrivalAirports() 15 15 3
A addStatArrivalAirportsDaily() 15 15 3
A deleteStat() 10 10 2
A deleteStatFlight() 0 10 2
A deleteStatAirport() 0 10 2
F addOldStats() 147 486 107

How to fix   Duplicated Code    Complexity   

Duplicated Code

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

Common duplication problems, and corresponding solutions are:

Complex Class

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

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

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

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

1
<?php
2
/*
3
* This class save stats older than a year and $globalArchiveMonths
4
*/
5
6
require_once(dirname(__FILE__).'/class.Spotter.php');
7
require_once(dirname(__FILE__).'/class.SpotterArchive.php');
8
require_once(dirname(__FILE__).'/class.Common.php');
9
class Stats {
10
	public $db;
11
        function __construct($dbc = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
12
		$Connection = new Connection($dbc);
13
		$this->db = $Connection->db;
14
        }
15
              
16 View Code Duplication
	public function addLastStatsUpdate($type,$stats_date) {
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...
17
                $query = "DELETE FROM config WHERE name = :type;
18
            		INSERT INTO config (name,value) VALUES (:type,:stats_date);";
19
                $query_values = array('type' => $type,':stats_date' => $stats_date);
20
                 try {
21
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
22
                        $sth->execute($query_values);
23
                } catch(PDOException $e) {
24
                        return "error : ".$e->getMessage();
25
                }
26
        }
27
28 View Code Duplication
	public function getLastStatsUpdate($type = 'last_update_stats') {
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...
29
                $query = "SELECT value FROM config WHERE name = :type";
30
                 try {
31
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
32
                        $sth->execute(array(':type' => $type));
33
                } catch(PDOException $e) {
34
                        echo "error : ".$e->getMessage();
35
                }
36
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
37
                return $all;
38
        }
39
	public function getAllAirlineNames($airline_type = '') {
0 ignored issues
show
Unused Code introduced by
The parameter $airline_type 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...
40
                $query = "SELECT * FROM stats_airline ORDER BY airline_name ASC";
41
                 try {
42
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
43
                        $sth->execute();
44
                } catch(PDOException $e) {
45
                        echo "error : ".$e->getMessage();
46
                }
47
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
48
                return $all;
49
        }
50
	public function getAllAircraftTypes() {
51
                $query = "SELECT * FROM stats_aircraft ORDER BY aircraft_name ASC";
52
                 try {
53
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
54
                        $sth->execute();
55
                } catch(PDOException $e) {
56
                        echo "error : ".$e->getMessage();
57
                }
58
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
59
                return $all;
60
        }
61
	public function getAllAirportNames() {
62
                $query = "SELECT airport_icao, airport_name,airport_city,airport_country FROM stats_airport GROUP BY airport_icao,airport_name,airport_city,airport_country ORDER BY airport_city ASC";
63
                 try {
64
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
65
                        $sth->execute();
66
                } catch(PDOException $e) {
67
                        echo "error : ".$e->getMessage();
68
                }
69
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
70
                return $all;
71
        }
72
73
74
	public function countAllAircraftTypes($limit = true) {
75
		if ($limit) $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' ORDER BY aircraft_icao_count DESC LIMIT 10 OFFSET 0";
76
		else $query = "SELECT aircraft_icao, cnt AS aircraft_icao_count, aircraft_name FROM stats_aircraft WHERE aircraft_name <> '' AND aircraft_icao <> '' ORDER BY aircraft_icao_count DESC";
77
                 try {
78
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
79
                        $sth->execute();
80
                } catch(PDOException $e) {
81
                        echo "error : ".$e->getMessage();
82
                }
83
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
84
                if (empty($all)) {
85
            	    $Spotter = new Spotter($this->db);
86
            	    $all = $Spotter->countAllAircraftTypes($limit);
87
                }
88
                return $all;
89
	}
90
	public function countAllAirlineCountries($limit = true) {
91
		if ($limit) $query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count FROM stats_airline,airlines WHERE stats_airline.airline_icao=airlines.icao GROUP BY airline_country ORDER BY airline_country_count DESC LIMIT 10 OFFSET 0";
92
		else $query = "SELECT airlines.country AS airline_country, SUM(stats_airline.cnt) as airline_country_count FROM stats_airline,airlines WHERE stats_airline.airline_icao=airlines.icao GROUP BY airline_country ORDER BY airline_country_count DESC";
93
                 try {
94
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
95
                        $sth->execute();
96
                } catch(PDOException $e) {
97
                        echo "error : ".$e->getMessage();
98
                }
99
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
100
                if (empty($all)) {
101
            		$Spotter = new Spotter($this->db);
102
            		$all = $Spotter->countAllAirlineCountries($limit);
103
                
104
                }
105
                return $all;
106
	}
107
	public function countAllAircraftManufacturers($limit = true) {
108
		if ($limit) $query = "SELECT aircraft.manufacturer AS aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft,aircraft WHERE stats_aircraft.aircraft_icao=aircraft.icao GROUP BY aircraft.manufacturer ORDER BY aircraft_manufacturer_count DESC LIMIT 10 OFFSET 0";
109
		else $query = "SELECT aircraft.manufacturer AS aircraft_manufacturer, SUM(stats_aircraft.cnt) as aircraft_manufacturer_count FROM stats_aircraft,aircraft WHERE stats_aircraft.aircraft_icao=aircraft.icao GROUP BY aircraft.manufacturer ORDER BY aircraft_manufacturer_count DESC";
110
                 try {
111
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
112
                        $sth->execute();
113
                } catch(PDOException $e) {
114
                        echo "error : ".$e->getMessage();
115
                }
116
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
117
                if (empty($all)) {
118
            		$Spotter = new Spotter($this->db);
119
			$all = $Spotter->countAllAircraftManufacturers($limit);
0 ignored issues
show
Unused Code introduced by
The call to Spotter::countAllAircraftManufacturers() has too many arguments starting with $limit.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
120
                }
121
                return $all;
122
	}
123
124
	public function countAllArrivalCountries($limit = true) {
125
		if ($limit) $query = "SELECT airport_country AS arrival_airport_country, arrival as airport_arrival_country_count FROM stats_airport WHERE stats_type = 'yearly' LIMIT 10 OFFSET 0";
126
		else $query = "SELECT airport_country AS arrival_airport_country, arrival as airport_arrival_country_count FROM stats_airport WHERE stats_type = 'yearly'";
127
                 try {
128
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
129
                        $sth->execute();
130
                } catch(PDOException $e) {
131
                        echo "error : ".$e->getMessage();
132
                }
133
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
134
                if (empty($all)) {
135
	                $Spotter = new Spotter($this->db);
136
            		$all = $Spotter->countAllArrivalCountries($limit);
137
                }
138
                return $all;
139
	}
140
	public function countAllDepartureCountries($limit = true) {
141
		if ($limit) $query = "SELECT airport_country AS departure_airport_country, departure as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly' LIMIT 10 OFFSET 0";
142
		else $query = "SELECT airport_country AS departure_airport_country, departure as airport_departure_country_count FROM stats_airport WHERE stats_type = 'yearly'";
143
                 try {
144
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
145
                        $sth->execute();
146
                } catch(PDOException $e) {
147
                        echo "error : ".$e->getMessage();
148
                }
149
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
150
                if (empty($all)) {
151
		        $Spotter = new Spotter($this->db);
152
    	    	        $all = $Spotter->countAllDepartureCountries($limit);
0 ignored issues
show
Unused Code introduced by
The call to Spotter::countAllDepartureCountries() has too many arguments starting with $limit.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
153
                }
154
                return $all;
155
	}
156
157
	public function countAllAirlines($limit = true) {
158
		if ($limit) $query = "SELECT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = airline_icao ORDER BY airline_count DESC LIMIT 10 OFFSET 0";
159
		else $query = "SELECT stats_airline.airline_icao, stats_airline.cnt AS airline_count, stats_airline.airline_name, airlines.country as airline_country FROM stats_airline, airlines WHERE stats_airline.airline_name <> '' AND stats_airline.airline_icao <> '' AND airlines.icao = airline_icao ORDER BY airline_count DESC";
160
                 try {
161
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
162
                        $sth->execute();
163
                } catch(PDOException $e) {
164
                        echo "error : ".$e->getMessage();
165
                }
166
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
167
                if (empty($all)) {
168
	                $Spotter = new Spotter($this->db);
169
    		        $all = $Spotter->countAllAirlines($limit);
170
                }
171
                return $all;
172
	}
173
	public function countAllAircraftRegistrations($limit = true) {
174
		if ($limit) $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name, s.registration FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao ORDER BY aircraft_registration_count DESC LIMIT 10 OFFSET 0";
175
		else $query = "SELECT s.aircraft_icao, s.cnt AS aircraft_registration_count, a.type AS aircraft_name FROM stats_registration s, aircraft a WHERE s.registration <> '' AND a.icao = s.aircraft_icao ORDER BY aircraft_registration_count DESC";
176
                 try {
177
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
178
                        $sth->execute();
179
                } catch(PDOException $e) {
180
                        echo "error : ".$e->getMessage();
181
                }
182
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
183
                if (empty($all)) {
184
	                $Spotter = new Spotter($this->db);
185
    		        $all = $Spotter->countAllAircraftRegistrations($limit);
186
                }
187
                return $all;
188
	}
189
	public function countAllCallsigns($limit = true) {
190
		if ($limit) $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao ORDER BY callsign_icao_count DESC LIMIT 10 OFFSET 0";
191
		else $query = "SELECT s.callsign_icao, s.cnt AS callsign_icao_count, a.name AS airline_name, a.icao as airline_icao FROM stats_callsign s, airlines a WHERE s.callsign_icao <> '' AND a.icao = s.airline_icao ORDER BY callsign_icao_count DESC";
192
                 try {
193
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
194
                        $sth->execute();
195
                } catch(PDOException $e) {
196
                        echo "error : ".$e->getMessage();
197
                }
198
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
199
                if (empty($all)) {
200
	                $Spotter = new Spotter($this->db);
201
    		        $all = $Spotter->countAllCallsigns($limit);
202
                }
203
                return $all;
204
	}
205
	public function countAllFlightOverCountries($limit = true) {
206
		$Connection = new Connection();
207
		if ($Connection->tableExists('countries')) {
208
			if ($limit) $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 ORDER BY flight_count DESC LIMIT 20 OFFSET 0";
209
			else $query = "SELECT countries.iso3 as flight_country_iso3, countries.iso2 as flight_country_iso2, countries.name as flight_country, cnt as flight_count, lat as flight_country_latitude, lon as flight_country_longitude FROM stats_country, countries WHERE stats_country.iso2 = countries.iso2 ORDER BY flight_count DESC";
210
			 try {
211
				$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
212
				$sth->execute();
213
			} catch(PDOException $e) {
214
				echo "error : ".$e->getMessage();
215
			}
216
			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
217
                /*
218
                if (empty($all)) {
219
	                $Spotter = new Spotter($this->db);
220
    		        $all = $Spotter->countAllFlightOverCountries($limit);
221
                }
222
                */
223
			return $all;
224
		} else {
225
			return array();
226
		}
227
	}
228
	public function countAllPilots($limit = true) {
229
		if ($limit) $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name FROM stats_pilot ORDER BY pilot_count DESC LIMIT 10 OFFSET 0";
230
		else $query = "SELECT pilot_id, cnt AS pilot_count, pilot_name FROM stats_pilot ORDER BY pilot_count DESC";
231
                 try {
232
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
233
                        $sth->execute();
234
                } catch(PDOException $e) {
235
                        echo "error : ".$e->getMessage();
236
                }
237
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
238
                if (empty($all)) {
239
            		$Spotter = new Spotter($this->db);
240
            		$all = $Spotter->countAllPilots($limit);
241
                }
242
                return $all;
243
	}
244
	public function countAllOwners($limit = true) {
245
		if ($limit) $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner ORDER BY owner_count DESC LIMIT 10 OFFSET 0";
246
		else $query = "SELECT owner_name, cnt AS owner_count FROM stats_owner ORDER BY owner_count DESC";
247
                 try {
248
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
249
                        $sth->execute();
250
                } catch(PDOException $e) {
251
                        echo "error : ".$e->getMessage();
252
                }
253
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
254
                if (empty($all)) {
255
            		$Spotter = new Spotter($this->db);
256
            		$all = $Spotter->countAllOwners($limit);
257
                }
258
                return $all;
259
	}
260 View Code Duplication
	public function countAllDepartureAirports($limit = true) {
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...
261
		if ($limit) $query = "SELECT airport_icao AS airport_departure_icao,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count FROM stats_airport WHERE stats_type = 'yearly' LIMIT 10 OFFSET 0";
262
		else $query = "SELECT airport_icao AS airport_departure_icao,airport_city AS airport_departure_city,airport_country AS airport_departure_country,departure AS airport_departure_icao_count FROM stats_airport WHERE stats_type = 'yearly'";
263
                 try {
264
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
265
                        $sth->execute();
266
                } catch(PDOException $e) {
267
                        echo "error : ".$e->getMessage();
268
                }
269
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
270
                if (empty($all)) {
271
            		$Spotter = new Spotter($this->db);
272
            		$pall = $Spotter->countAllDepartureAirports($limit);
273
        		$dall = $Spotter->countAllDetectedDepartureAirports($limit);
274
        		$all = array();
275
        		foreach ($pall as $value) {
276
        			$icao = $value['airport_departure_icao'];
277
        			$all[$icao] = $value;
278
        		}
279
        		
280
        		foreach ($dall as $value) {
281
        			$icao = $value['airport_departure_icao'];
282
        			if (isset($all[$icao])) {                                                           
283
        				$all[$icao]['airport_departure_icao_count'] = $all[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
284
        			} else $all[$icao] = $value;
285
        		}
286
        		$count = array();
287
        		foreach ($all as $key => $row) {
288
        			$count[$key] = $row['airport_departure_icao_count'];
289
        		}
290
        		array_multisort($count,SORT_DESC,$all);
291
                }
292
                return $all;
293
	}
294 View Code Duplication
	public function countAllArrivalAirports($limit = true) {
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
		if ($limit) $query = "SELECT airport_icao AS airport_arrival_icao,airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count FROM stats_airport WHERE stats_type = 'yearly' LIMIT 10 OFFSET 0";
296
		else $query = "SELECT airport_icao AS airport_arrival_icao,airport_city AS airport_arrival_city,airport_country AS airport_arrival_country,arrival AS airport_arrival_icao_count FROM stats_airport WHERE stats_type = 'yearly'";
297
                 try {
298
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
299
                        $sth->execute();
300
                } catch(PDOException $e) {
301
                        echo "error : ".$e->getMessage();
302
                }
303
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
304
                if (empty($all)) {
305
            		$Spotter = new Spotter($this->db);
306
        		$pall = $Spotter->countAllArrivalAirports($limit);
307
        		$dall = $Spotter->countAllDetectedArrivalAirports($limit);
308
        		$all = array();
309
        		foreach ($pall as $value) {
310
        			$icao = $value['airport_arrival_icao'];
311
        			$all[$icao] = $value;
312
        		}
313
        		
314
        		foreach ($dall as $value) {
315
        			$icao = $value['airport_arrival_icao'];
316
        			if (isset($all[$icao])) {
317
        				$all[$icao]['airport_arrival_icao_count'] = $all[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
318
        			} else $all[$icao] = $value;
319
        		}
320
        		$count = array();
321
        		foreach ($all as $key => $row) {
322
        			$count[$key] = $row['airport_arrival_icao_count'];
323
        		}
324
        		array_multisort($count,SORT_DESC,$all);
325
                }
326
                return $all;
327
	}
328
	public function countAllMonthsLastYear($limit = true) {
329
		global $globalDBdriver;
330
		if ($globalDBdriver == 'mysql') {
331
			if ($limit) $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 12 MONTH)";
332
			else $query = "SELECT MONTH(stats_date) as month_name, YEAR(stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth'";
333
		} else {
334
			if ($limit) $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth' AND stats_date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '12 MONTHS'";
335
			else $query = "SELECT EXTRACT(MONTH FROM stats_date) as month_name, EXTRACT(YEAR FROM stats_date) as year_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth'";
336
		}
337
		$query_data = array();
338
                 try {
339
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
340
                        $sth->execute($query_data);
341
                } catch(PDOException $e) {
342
                        echo "error : ".$e->getMessage();
343
                }
344
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
345
                if (empty($all)) {
346
            		$Spotter = new Spotter($this->db);
347
            		$all = $Spotter->countAllMonthsLastYear($limit);
0 ignored issues
show
Unused Code introduced by
The call to Spotter::countAllMonthsLastYear() has too many arguments starting with $limit.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
348
                }
349
                return $all;
350
	}
351
	
352 View Code Duplication
	public function countAllDatesLastMonth() {
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...
353
		$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month'";
354
		$query_data = array();
355
                 try {
356
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
357
                        $sth->execute($query_data);
358
                } catch(PDOException $e) {
359
                        echo "error : ".$e->getMessage();
360
                }
361
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
362
                if (empty($all)) {
363
            		$Spotter = new Spotter($this->db);
364
            		$all = $Spotter->countAllDatesLastMonth();
365
                }
366
                return $all;
367
	}
368
	public function countAllDatesLast7Days() {
369
		global $globalDBdriver;
370
		if ($globalDBdriver == 'mysql') {
371
			$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND flight_date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 7 DAY)";
372
		} else {
373
			$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'month' AND flight_date::timestamp >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '7 DAYS'";
374
		}
375
		$query_data = array();
376
                 try {
377
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
378
                        $sth->execute($query_data);
379
                } catch(PDOException $e) {
380
                        echo "error : ".$e->getMessage();
381
                }
382
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
383
                if (empty($all)) {
384
            		$Spotter = new Spotter($this->db);
385
            		$all = $Spotter->countAllDatesLast7Days();
386
                }
387
                return $all;
388
	}
389 View Code Duplication
	public function countAllDates() {
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...
390
		$query = "SELECT flight_date as date_name, cnt as date_count FROM stats_flight WHERE stats_type = 'date'";
391
		$query_data = array();
392
                 try {
393
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
394
                        $sth->execute($query_data);
395
                } catch(PDOException $e) {
396
                        echo "error : ".$e->getMessage();
397
                }
398
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
399
                if (empty($all)) {
400
            		$Spotter = new Spotter($this->db);
401
            		$all = $Spotter->countAllDates();
402
                }
403
                return $all;
404
	}
405 View Code Duplication
	public function countAllMonths() {
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...
406
	    	$query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'flights_bymonth'";
407
                 try {
408
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
409
                        $sth->execute();
410
                } catch(PDOException $e) {
411
                        echo "error : ".$e->getMessage();
412
                }
413
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
414
                if (empty($all)) {
415
            		$Spotter = new Spotter($this->db);
416
            		$all = $Spotter->countAllMonths();
417
                }
418
                return $all;
419
	}
420 View Code Duplication
	public function countAllMilitaryMonths() {
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...
421
	    	$query = "SELECT YEAR(stats_date) AS year_name,MONTH(stats_date) AS month_name, cnt as date_count FROM stats WHERE stats_type = 'military_flights_bymonth'";
422
                 try {
423
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
424
                        $sth->execute();
425
                } catch(PDOException $e) {
426
                        echo "error : ".$e->getMessage();
427
                }
428
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
429
                if (empty($all)) {
430
            		$Spotter = new Spotter($this->db);
431
            		$all = $Spotter->countAllMilitaryMonths();
432
                }
433
                return $all;
434
	}
435
	public function countAllHours($orderby = 'hour',$limit = true) {
436
		global $globalTimezone, $globalDBdriver;
437
438
		if ($limit) $query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour'";
439
		else $query = "SELECT flight_date as hour_name, cnt as hour_count FROM stats_flight WHERE stats_type = 'hour'";
440
		if ($orderby == 'hour') {
441
			if ($globalDBdriver == 'mysql') {
442
				$query .= " ORDER BY flight_date ASC";
443
			} else {
444
				$query .= " ORDER BY CAST(flight_date AS integer) ASC";
445
			}
446
		}
447
		if ($orderby == 'count') $query .= " ORDER BY hour_count DESC";
448
                 try {
449
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
450
                        $sth->execute();
451
                } catch(PDOException $e) {
452
                        echo "error : ".$e->getMessage();
453
                }
454
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
455
                if (empty($all)) {
456
            		$Spotter = new Spotter($this->db);
457
            		$all = $Spotter->countAllHours($orderby,$limit);
0 ignored issues
show
Unused Code introduced by
The call to Spotter::countAllHours() has too many arguments starting with $limit.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
458
                }
459
                return $all;
460
	}
461
	
462 View Code Duplication
	public function countOverallFlights() {
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...
463
		$all = $this->getSumStats('flights_bymonth',date('Y'));
464
		if (empty($all)) {
465
			$Spotter = new Spotter($this->db);
466
			$all = $Spotter->countOverallFlights();
467
		}
468
		return $all;
469
	}
470 View Code Duplication
	public function countOverallMilitaryFlights() {
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...
471
		$all = $this->getSumStats('military_flights_bymonth',date('Y'));
472
		if (empty($all)) {
473
			$Spotter = new Spotter($this->db);
474
			$all = $Spotter->countOverallMilitaryFlights();
475
		}
476
		return $all;
477
	}
478 View Code Duplication
	public function countOverallArrival() {
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...
479
		$all = $this->getSumStats('realarrivals_bymonth',date('Y'));
480
		if (empty($all)) {
481
			$Spotter = new Spotter($this->db);
482
			$all = $Spotter->countOverallArrival();
483
		}
484
		return $all;
485
	}
486 View Code Duplication
	public function countOverallAircrafts() {
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...
487
		$all = $this->getSumStats('aircrafts_bymonth',date('Y'));
488
		if (empty($all)) {
489
			$Spotter = new Spotter($this->db);
490
			$all = $Spotter->countOverallAircrafts();
491
		}
492
		return $all;
493
	}
494 View Code Duplication
	public function countOverallAirlines() {
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...
495
		$all = $this->getSumStats('airlines_bymonth',date('Y'));
496
		if (empty($all)) {
497
			$Spotter = new Spotter($this->db);
498
			$all = $Spotter->countOverallAirlines();
499
		}
500
		return $all;
501
	}
502 View Code Duplication
	public function countOverallOwners() {
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...
503
		$all = $this->getSumStats('owners_bymonth',date('Y'));
504
		if (empty($all)) {
505
			$Spotter = new Spotter($this->db);
506
			$all = $Spotter->countOverallOwners();
507
		}
508
		return $all;
509
	}
510 View Code Duplication
	public function countOverallPilots() {
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...
511
		$all = $this->getSumStats('pilots_bymonth',date('Y'));
512
		if (empty($all)) {
513
			$Spotter = new Spotter($this->db);
514
			$all = $Spotter->countOverallPilots();
515
		}
516
		return $all;
517
	}
518
519 View Code Duplication
	public function getLast7DaysAirports($airport_icao = '') {
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...
520
		$query = "SELECT * FROM stats_airport WHERE stats_type = 'daily' AND airport_icao = :airport_icao ORDER BY date";
521
		$query_values = array(':airport_icao' => $airport_icao);
522
                 try {
523
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
524
                        $sth->execute($query_values);
525
                } catch(PDOException $e) {
526
                        echo "error : ".$e->getMessage();
527
                }
528
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
529
                return $all;
530
	}
531 View Code Duplication
	public function getStats($type) {
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...
532
                $query = "SELECT * FROM stats WHERE stats_type = :type ORDER BY stats_date";
533
                $query_values = array(':type' => $type);
534
                 try {
535
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
536
                        $sth->execute($query_values);
537
                } catch(PDOException $e) {
538
                        echo "error : ".$e->getMessage();
539
                }
540
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
541
                return $all;
542
        }
543 View Code Duplication
	public function getSumStats($type,$year) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
544
    		global $globalArchiveMonths, $globalDBdriver;
545
    		if ($globalDBdriver == 'mysql') {
546
	                $query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND YEAR(stats_date) = :year";
547
	        } else {
548
            		$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND EXTRACT(YEAR FROM stats_date) = :year";
549
                }
550
                $query_values = array(':type' => $type, ':year' => $year);
551
                 try {
552
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
553
                        $sth->execute($query_values);
554
                } catch(PDOException $e) {
555
                        echo "error : ".$e->getMessage();
556
                }
557
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
558
                return $all[0]['total'];
559
        }
560
	public function getStatsTotal($type) {
561
    		global $globalArchiveMonths, $globalDBdriver;
562
    		if ($globalDBdriver == 'mysql') {
563
			$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND stats_date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL ".$globalArchiveMonths." MONTH)";
564
		} else {
565
			$query = "SELECT SUM(cnt) as total FROM stats WHERE stats_type = :type AND stats_date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS'";
566
                }
567
                $query_values = array(':type' => $type);
568
                 try {
569
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
570
                        $sth->execute($query_values);
571
                } catch(PDOException $e) {
572
                        echo "error : ".$e->getMessage();
573
                }
574
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
575
                return $all[0]['total'];
576
        }
577 View Code Duplication
	public function getStatsAircraftTotal() {
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...
578
    		global $globalArchiveMonths, $globalDBdriver;
579
    		if ($globalDBdriver == 'mysql') {
580
			$query = "SELECT SUM(cnt) as total FROM stats_aircraft";
581
                } else {
582
			$query = "SELECT SUM(cnt) as total FROM stats_aircraft";
583
                }
584
                 try {
585
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
586
                        $sth->execute();
587
                } catch(PDOException $e) {
588
                        echo "error : ".$e->getMessage();
589
                }
590
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
591
                return $all[0]['total'];
592
        }
593 View Code Duplication
	public function getStatsAirlineTotal() {
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...
594
    		global $globalArchiveMonths, $globalDBdriver;
595
    		if ($globalDBdriver == 'mysql') {
596
			$query = "SELECT SUM(cnt) as total FROM stats_airline";
597
                } else {
598
			$query = "SELECT SUM(cnt) as total FROM stats_airline";
599
                }
600
                 try {
601
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
602
                        $sth->execute();
603
                } catch(PDOException $e) {
604
                        echo "error : ".$e->getMessage();
605
                }
606
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
607
                return $all[0]['total'];
608
        }
609 View Code Duplication
	public function getStatsOwnerTotal() {
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...
610
    		global $globalArchiveMonths, $globalDBdriver;
611
    		if ($globalDBdriver == 'mysql') {
612
			$query = "SELECT SUM(cnt) as total FROM stats_owner";
613
		} else {
614
			$query = "SELECT SUM(cnt) as total FROM stats_owner";
615
                }
616
                 try {
617
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
618
                        $sth->execute();
619
                } catch(PDOException $e) {
620
                        echo "error : ".$e->getMessage();
621
                }
622
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
623
                return $all[0]['total'];
624
        }
625 View Code Duplication
	public function getStatsPilotTotal() {
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...
626
    		global $globalArchiveMonths, $globalDBdriver;
627
    		if ($globalDBdriver == 'mysql') {
628
            		$query = "SELECT SUM(cnt) as total FROM stats_pilot";
629
            	} else {
630
            		$query = "SELECT SUM(cnt) as total FROM stats_pilot";
631
            	}
632
                 try {
633
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
634
                        $sth->execute();
635
                } catch(PDOException $e) {
636
                        echo "error : ".$e->getMessage();
637
                }
638
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
639
                return $all[0]['total'];
640
        }
641
642 View Code Duplication
	public function addStat($type,$cnt,$stats_date) {
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...
643
		global $globalDBdriver;
644
		if ($globalDBdriver == 'mysql') {
645
			$query = "INSERT INTO stats (stats_type,cnt,stats_date) VALUES (:type,:cnt,:stats_date) ON DUPLICATE KEY UPDATE cnt = :cnt";
646
                } else {
647
			$query = "UPDATE stats SET cnt = :cnt WHERE stats_type = :type AND stats_date = :stats_date; INSERT INTO stats (stats_type,cnt,stats_date) SELECT :type,:cnt,:stats_date WHERE NOT EXISTS (SELECT 1 FROM stats WHERE  stats_type = :type AND stats_date = :stats_date);"; 
648
		}
649
                $query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date);
650
                 try {
651
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
652
                        $sth->execute($query_values);
653
                } catch(PDOException $e) {
654
                        return "error : ".$e->getMessage();
655
                }
656
        }
657 View Code Duplication
	public function updateStat($type,$cnt,$stats_date) {
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...
658
		global $globalDBdriver;
659
		if ($globalDBdriver == 'mysql') {
660
			$query = "INSERT INTO stats (stats_type,cnt,stats_date) VALUES (:type,:cnt,:stats_date) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date";
661
		} else {
662
            		//$query = "INSERT INTO stats (stats_type,cnt,stats_date) VALUES (:type,:cnt,:stats_date) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt, stats_date = :date";
663
			$query = "UPDATE stats SET cnt = cnt+:cnt WHERE stats_type = :type AND stats_date = :stats_date; INSERT INTO stats (stats_type,cnt,stats_date) SELECT :type,:cnt,:stats_date WHERE NOT EXISTS (SELECT 1 FROM stats WHERE  stats_type = :type AND stats_date = :stats_date);"; 
664
                }
665
                $query_values = array(':type' => $type,':cnt' => $cnt,':stats_date' => $stats_date);
666
                 try {
667
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
668
                        $sth->execute($query_values);
669
                } catch(PDOException $e) {
670
                        return "error : ".$e->getMessage();
671
                }
672
        }
673 View Code Duplication
	public function getStatsSource($date,$stats_type = '') {
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...
674
		if ($stats_type == '') {
675
			$query = "SELECT * FROM stats_source WHERE stats_date = :date ORDER BY source_name";
676
			$query_values = array(':date' => $date);
677
		} else {
678
			$query = "SELECT * FROM stats_source WHERE stats_date = :date AND stats_type = :stats_type ORDER BY source_name";
679
			$query_values = array(':date' => $date,':stats_type' => $stats_type);
680
		}
681
                 try {
682
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
683
                        $sth->execute($query_values);
684
                } catch(PDOException $e) {
685
                        echo "error : ".$e->getMessage();
686
                }
687
                $all = $sth->fetchAll(PDO::FETCH_ASSOC);
688
                return $all;
689
        }
690
691 View Code Duplication
	public function addStatSource($data,$source_name,$stats_type,$date) {
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...
692
		global $globalDBdriver;
693
		if ($globalDBdriver == 'mysql') {
694
			$query = "INSERT INTO stats_source (source_data,source_name,stats_type,stats_date) VALUES (:data,:source_name,:stats_type,:stats_date) ON DUPLICATE KEY UPDATE source_data = :data";
695
		} else {
696
			$query = "UPDATE stats_source SET source_data = :data WHERE stats_date = :stats_date AND source_name = :source_name AND stats_type = :stats_type; INSERT INTO stats_source (source_data,source_name,stats_type,stats_date) SELECT :data,:source_name,:stats_type,:stats_date WHERE NOT EXISTS (SELECT 1 FROM stats_source WHERE stats_date = :stats_date AND source_name = :source_name AND stats_type = :stats_type);"; 
697
                }
698
                $query_values = array(':data' => $data,':stats_date' => $date,':source_name' => $source_name,':stats_type' => $stats_type);
699
                 try {
700
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
701
                        $sth->execute($query_values);
702
                } catch(PDOException $e) {
703
                        return "error : ".$e->getMessage();
704
                }
705
        }
706 View Code Duplication
	public function addStatFlight($type,$date_name,$cnt) {
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...
707
                $query = "INSERT INTO stats_flight (stats_type,flight_date,cnt) VALUES (:type,:flight_date,:cnt)";
708
                $query_values = array(':type' => $type,':flight_date' => $date_name,':cnt' => $cnt);
709
                 try {
710
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
711
                        $sth->execute($query_values);
712
                } catch(PDOException $e) {
713
                        return "error : ".$e->getMessage();
714
                }
715
        }
716 View Code Duplication
	public function addStatAircraftRegistration($registration,$cnt,$aircraft_icao = '') {
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...
717
		global $globalDBdriver;
718
		if ($globalDBdriver == 'mysql') {
719
			$query = "INSERT INTO stats_registration (aircraft_icao,registration,cnt) VALUES (:aircraft_icao,:registration,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt";
720
		} else {
721
			$query = "UPDATE stats_registration SET cnt = cnt+:cnt WHERE registration = :registration; INSERT INTO stats_registration (aircraft_icao,registration,cnt) SELECT :aircraft_icao,:registration,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_registration WHERE registration = :registration);"; 
722
		}
723
                $query_values = array(':aircraft_icao' => $aircraft_icao,':registration' => $registration,':cnt' => $cnt);
724
                 try {
725
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
726
                        $sth->execute($query_values);
727
                } catch(PDOException $e) {
728
                        return "error : ".$e->getMessage();
729
                }
730
        }
731 View Code Duplication
	public function addStatCallsign($callsign_icao,$cnt,$airline_icao = '') {
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...
732
		global $globalDBdriver;
733
		if ($globalDBdriver == 'mysql') {
734
			$query = "INSERT INTO stats_callsign (callsign_icao,airline_icao,cnt) VALUES (:callsign_icao,:airline_icao,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt";
735
		} else {
736
			$query = "UPDATE stats_callsign SET cnt = cnt+:cnt WHERE callsign_icao = :callsign_icao; INSERT INTO stats_callsign (callsign_icao,airline_icao,cnt) SELECT :callsign_icao,:airline_icao,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_callsign WHERE callsign_icao = :callsign_icao);"; 
737
		}
738
                $query_values = array(':callsign_icao' => $callsign_icao,':airline_icao' => $airline_icao,':cnt' => $cnt);
739
                 try {
740
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
741
                        $sth->execute($query_values);
742
                } catch(PDOException $e) {
743
                        return "error : ".$e->getMessage();
744
                }
745
        }
746 View Code Duplication
	public function addStatCountry($iso2,$iso3,$name,$cnt) {
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...
747
		global $globalDBdriver;
748
		if ($globalDBdriver == 'mysql') {
749
			$query = "INSERT INTO stats_country (iso2,iso3,name,cnt) VALUES (:iso2,:iso3,:name,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt";
750
		} else {
751
			$query = "UPDATE stats_country SET cnt = cnt+:cnt WHERE iso2 = :iso2; INSERT INTO stats_country (iso2,iso3,name,cnt) SELECT :iso2,:iso3,:name,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_country WHERE iso2 = :iso2);"; 
752
		}
753
                $query_values = array(':iso2' => $iso2,':iso3' => $iso3,':name' => $name,':cnt' => $cnt);
754
                 try {
755
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
756
                        $sth->execute($query_values);
757
                } catch(PDOException $e) {
758
                        return "error : ".$e->getMessage();
759
                }
760
        }
761 View Code Duplication
	public function addStatAircraft($aircraft_icao,$cnt,$aircraft_name = '') {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
762
		global $globalDBdriver;
763
		if ($globalDBdriver == 'mysql') {
764
			$query = "INSERT INTO stats_aircraft (aircraft_icao,aircraft_name,cnt) VALUES (:aircraft_icao,:aircraft_name,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt";
765
		} else {
766
			$query = "UPDATE stats_aircraft SET cnt = cnt+:cnt WHERE aircraft_icao = :aircraft_icao; INSERT INTO stats_aircraft (aircraft_icao,aircraft_name,cnt) SELECT :aircraft_icao,:aircraft_name,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_aircraft WHERE aircraft_icao = :aircraft_icao);"; 
767
		}
768
                $query_values = array(':aircraft_icao' => $aircraft_icao,':aircraft_name' => $aircraft_name,':cnt' => $cnt);
769
                 try {
770
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
771
                        $sth->execute($query_values);
772
                } catch(PDOException $e) {
773
                        return "error : ".$e->getMessage();
774
                }
775
        }
776 View Code Duplication
	public function addStatAirline($airline_icao,$cnt,$airline_name = '') {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
777
		global $globalDBdriver;
778
		if ($globalDBdriver == 'mysql') {
779
			$query = "INSERT INTO stats_airline (airline_icao,airline_name,cnt) VALUES (:airline_icao,:airline_name,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt,airline_name = :airline_name";
780
		} else {
781
			$query = "UPDATE stats_airline SET cnt = cnt+:cnt WHERE airline_icao = :airline_icao; INSERT INTO stats_airline (airline_icao,airline_name,cnt) SELECT :airline_icao,:airline_name,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_airline WHERE airline_icao = :airline_icao);"; 
782
		}
783
                $query_values = array(':airline_icao' => $airline_icao,':airline_name' => $airline_name,':cnt' => $cnt);
784
                 try {
785
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
786
                        $sth->execute($query_values);
787
                } catch(PDOException $e) {
788
                        return "error : ".$e->getMessage();
789
                }
790
        }
791 View Code Duplication
	public function addStatOwner($owner_name,$cnt) {
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...
792
		global $globalDBdriver;
793
		if ($globalDBdriver == 'mysql') {
794
			$query = "INSERT INTO stats_owner (owner_name,cnt) VALUES (:owner_name,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt";
795
		} else {
796
			$query = "UPDATE stats_owner SET cnt = cnt+:cnt WHERE owner_name = :owner_name; INSERT INTO stats_owner (owner_name,cnt) SELECT :owner_name,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_owner WHERE owner_name = :owner_name);"; 
797
		}
798
                $query_values = array(':owner_name' => $owner_name,':cnt' => $cnt);
799
                 try {
800
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
801
                        $sth->execute($query_values);
802
                } catch(PDOException $e) {
803
                        return "error : ".$e->getMessage();
804
                }
805
        }
806 View Code Duplication
	public function addStatPilot($pilot_id,$cnt) {
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...
807
		global $globalDBdriver;
808
		if ($globalDBdriver == 'mysql') {
809
			$query = "INSERT INTO stats_pilot (pilot_id,cnt) VALUES (:pilot_id,:cnt) ON DUPLICATE KEY UPDATE cnt = cnt+:cnt";
810
		} else {
811
			$query = "UPDATE stats_pilot SET cnt = cnt+:cnt WHERE pilot_id = :pilot_id; INSERT INTO stats_pilot (pilot_id,cnt) SELECT :pilot_id,:cnt WHERE NOT EXISTS (SELECT 1 FROM stats_pilot WHERE pilot_id = :pilot_id);"; 
812
		}
813
                $query_values = array(':pilot_id' => $pilot_id,':cnt' => $cnt);
814
                 try {
815
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
816
                        $sth->execute($query_values);
817
                } catch(PDOException $e) {
818
                        return "error : ".$e->getMessage();
819
                }
820
        }
821 View Code Duplication
	public function addStatDepartureAirports($airport_icao,$airport_name,$airport_city,$airport_country,$departure) {
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...
822
		global $globalDBdriver;
823
		if ($globalDBdriver == 'mysql') {
824
			$query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:departure,'yearly',:date) ON DUPLICATE KEY UPDATE departure = departure+:departure";
825
		} else {
826
			$query = "UPDATE stats_airport SET departure = departure+:departure WHERE airport_icao = :airport_icao AND stats_type = 'yearly'; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:departure,'yearly',:date WHERE NOT EXISTS (SELECT 1 FROM stats_airline WHERE airport_icao = :airport_icao AND stats_type = 'yearly');"; 
827
		}
828
                $query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':departure' => $departure,':date' => date('Y').'-01-01 00:00:00');
829
                 try {
830
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
831
                        $sth->execute($query_values);
832
                } catch(PDOException $e) {
833
                        return "error : ".$e->getMessage();
834
                }
835
        }
836 View Code Duplication
	public function addStatDepartureAirportsDaily($date,$airport_icao,$airport_name,$airport_city,$airport_country,$departure) {
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...
837
		global $globalDBdriver;
838
		if ($globalDBdriver == 'mysql') {
839
			$query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:departure,'daily',:date) ON DUPLICATE KEY UPDATE departure = :departure";
840
		} else {
841
			$query = "UPDATE stats_airport SET departure = departure+:departure WHERE airport_icao = :airport_icao AND stats_type = 'daily'; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,departure,stats_type,date) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:departure,'daily',:date WHERE NOT EXISTS (SELECT 1 FROM stats_airline WHERE airport_icao = :airport_icao AND stats_type = 'daily');"; 
842
		}
843
                $query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':departure' => $departure,':date' => $date);
844
                 try {
845
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
846
                        $sth->execute($query_values);
847
                } catch(PDOException $e) {
848
                        return "error : ".$e->getMessage();
849
                }
850
        }
851 View Code Duplication
	public function addStatArrivalAirports($airport_icao,$airport_name,$airport_city,$airport_country,$arrival) {
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...
852
		global $globalDBdriver;
853
		if ($globalDBdriver == 'mysql') {
854
			$query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'yearly',:date) ON DUPLICATE KEY UPDATE arrival = arrival+:arrival";
855
		} else {
856
			$query = "UPDATE stats_airport SET arrival = arrival+:arrival WHERE airport_icao = :airport_icao AND stats_type = 'yearly'; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'yearly',:date WHERE NOT EXISTS (SELECT 1 FROM stats_airline WHERE airport_icao = :airport_icao AND stats_type = 'yearly');"; 
857
		}
858
                $query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':arrival' => $arrival,':date' => date('Y').'-01-01 00:00:00');
859
                 try {
860
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
861
                        $sth->execute($query_values);
862
                } catch(PDOException $e) {
863
                        return "error : ".$e->getMessage();
864
                }
865
        }
866 View Code Duplication
	public function addStatArrivalAirportsDaily($date,$airport_icao,$airport_name,$airport_city,$airport_country,$arrival) {
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...
867
		global $globalDBdriver;
868
		if ($globalDBdriver == 'mysql') {
869
			$query = "INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date) VALUES (:airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'daily',:date) ON DUPLICATE KEY UPDATE arrival = :arrival";
870
		} else {
871
			$query = "UPDATE stats_airport SET arrival = arrival+:arrival WHERE airport_icao = :airport_icao AND stats_type = 'daily'; INSERT INTO stats_airport (airport_icao,airport_name,airport_city,airport_country,arrival,stats_type,date) SELECT :airport_icao,:airport_name,:airport_city,:airport_country,:arrival,'yearly',:date WHERE NOT EXISTS (SELECT 1 FROM stats_airline WHERE airport_icao = :airport_icao AND stats_type = 'daily');"; 
872
		}
873
                $query_values = array(':airport_icao' => $airport_icao,':airport_name' => $airport_name,':airport_city' => $airport_city,':airport_country' => $airport_country,':arrival' => $arrival, ':date' => $date);
874
                 try {
875
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
876
                        $sth->execute($query_values);
877
                } catch(PDOException $e) {
878
                        return "error : ".$e->getMessage();
879
                }
880
        }
881
882 View Code Duplication
	public function deleteStat($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...
883
                $query = "DELETE FROM stats WHERE stats_id = :id";
884
                $query_values = array(':id' => $id);
885
                 try {
886
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
887
                        $sth->execute($query_values);
888
                } catch(PDOException $e) {
889
                        return "error : ".$e->getMessage();
890
                }
891
        }
892
	public function deleteStatFlight($type) {
893
                $query = "DELETE FROM stats_flight WHERE stats_type = :type";
894
                $query_values = array(':type' => $type);
895
                 try {
896
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
897
                        $sth->execute($query_values);
898
                } catch(PDOException $e) {
899
                        return "error : ".$e->getMessage();
900
                }
901
        }
902
	public function deleteStatAirport($type) {
903
                $query = "DELETE FROM stats_airport WHERE stats_type = :type";
904
                $query_values = array(':type' => $type);
905
                 try {
906
                        $sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
907
                        $sth->execute($query_values);
908
                } catch(PDOException $e) {
909
                        return "error : ".$e->getMessage();
910
                }
911
        }
912
        
913
        public function addOldStats() {
914
    		global $globalArchiveMonths, $globalArchive, $globalArchiveYear, $globalDBdriver;
915
    		$Common = new Common();
916
    		$Connection = new Connection();
917
    		date_default_timezone_set('UTC');
918
    		$last_update = $this->getLastStatsUpdate('last_update_stats');
919
		//print_r($last_update);
920
		$flightsbymonth = $this->getStats('flights_by_month');
921
    		if (empty($last_update) && empty($flightsbymonth)) {
922
			// Initial update
923
			$Spotter = new Spotter($this->db);
924
			$alldata = $Spotter->countAllMonths();
925
			$lastyear = false;
0 ignored issues
show
Unused Code introduced by
$lastyear 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...
926 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
927
				if ($number['year_name'] != date('Y')) $lastyear = true;
0 ignored issues
show
Unused Code introduced by
$lastyear 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...
928
				$this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
929
			}
930
			$alldata = $Spotter->countAllMilitaryMonths();
931
			$lastyear = false;
932 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
933
				if ($number['year_name'] != date('Y')) $lastyear = true;
934
				$this->addStat('military_flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
935
			}
936
			$alldata = $Spotter->countAllMonthsOwners();
937 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
938
				$this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
939
			}
940
			$alldata = $Spotter->countAllMonthsPilots();
941 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
942
				$this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
943
			}
944
			$alldata = $Spotter->countAllMonthsAirlines();
945 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
946
				$this->addStat('airlines_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
947
			}
948
			$alldata = $Spotter->countAllMonthsAircrafts();
949 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
950
				$this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
951
			}
952
			$alldata = $Spotter->countAllMonthsRealArrivals();
953 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
954
				$this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
955
			}
956
			$this->deleteStatFlight('month');
957
			$alldata = $Spotter->countAllDatesLastMonth();
958
			foreach ($alldata as $number) {
959
				$this->addStatFlight('month',$number['date_name'],$number['date_count']);
960
			}
961
			$previousdata = $this->countAllDates();
962
			$this->deleteStatFlight('date');
963
			$alldata = $Common->array_merge_noappend($previousdata,$Spotter->countAllDates());
964
			$values = array();
965
			foreach ($alldata as $cnt) {
966
				$values[] = $cnt['date_count'];
967
			}
968
			array_multisort($values,SORT_DESC,$alldata);
969
			array_splice($alldata,11);
970
			foreach ($alldata as $number) {
971
				$this->addStatFlight('date',$number['date_name'],$number['date_count']);
972
			}
973
			$this->deleteStatFlight('hour');
974
			$alldata = $Spotter->countAllHours('hour');
975
			foreach ($alldata as $number) {
976
				$this->addStatFlight('hour',$number['hour_name'],$number['hour_count']);
977
			}
978
			if ($lastyear) {
979
				$monthsSinceLastYear = date('n');
980
				$alldata = $Spotter->countAllAircraftTypes(false,$monthsSinceLastYear);
981
				foreach ($alldata as $number) {
982
					$this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name']);
983
				}
984
				$alldata = $Spotter->countAllAirlines(false,$monthsSinceLastYear);
985
				foreach ($alldata as $number) {
986
					$this->addStatAirline($number['airline_icao'],$number['airline_count'],$number['airline_name']);
987
				}
988 View Code Duplication
				if ($Connection->tableExists('countries')) {
1 ignored issue
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...
989
					$alldata = $Spotter->countAllFlightOverCountries(false,$monthsSinceLastYear);
990
					foreach ($alldata as $number) {
991
						$this->addStatCountry($number['flight_country_iso2'],$number['flight_country_iso3'],$number['flight_country'],$number['flight_count']);
992
					}
993
				}
994
				$alldata = $Spotter->countAllOwners(false,$monthsSinceLastYear);
995
				foreach ($alldata as $number) {
996
					$this->addStatOwner($number['owner_name'],$number['owner_count']);
997
				}
998
				$alldata = $Spotter->countAllPilots(false,$monthsSinceLastYear);
999
				foreach ($alldata as $number) {
1000
					$this->addStatPilot($number['pilot_id'],$number['pilot_count']);
1001
				}
1002
				$previous_year = date('Y');
1003
				$previous_year--;
1004
				$this->addStat('aircrafts_byyear',$this->getStatsAircraftTotal(),$previous_year.'-01-01 00:00:00');
1005
				$this->addStat('airlines_byyear',$this->getStatsAirlineTotal(),$previous_year.'-01-01 00:00:00');
1006
				$this->addStat('owner_byyear',$this->getStatsOwnerTotal(),$previous_year.'-01-01 00:00:00');
1007
				$this->addStat('pilot_byyear',$this->getStatsPilotTotal(),$previous_year.'-01-01 00:00:00');
1008
				
1009 View Code Duplication
				if (isset($globalArchiveYear) && $globalArchiveYear) {
1 ignored issue
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...
1010
					if ($globalArchive) {
1011
						$query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00'";
1012
						//echo $query;
1013
						try {
1014
							$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
1015
							$sth->execute();
1016
						} catch(PDOException $e) {
1017
							return "error : ".$e->getMessage().' - query : '.$query."\n";
1018
						}
1019
					}
1020
					$query = "DELETE FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00'";
1021
					try {
1022
						$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
1023
						$sth->execute();
1024
					} catch(PDOException $e) {
1025
						return "error : ".$e->getMessage().' - query : '.$query."\n";
1026
					}
1027
				}
1028
			}
1029
			if (!isset($globalArchiveMonths) || $globalArchiveMonths == '') $globalArchiveMonths = 2;
1030
			if ($globalArchiveMonths > 0) {
1031
				$alldata = $Spotter->countAllAircraftTypes(false,$globalArchiveMonths);
1032
				foreach ($alldata as $number) {
1033
					$this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name']);
1034
				}
1035
				$alldata = $Spotter->countAllAirlines(false,$globalArchiveMonths);
1036
				foreach ($alldata as $number) {
1037
					$this->addStatAirline($number['airline_icao'],$number['airline_count'],$number['airline_name']);
1038
				}
1039
				$alldata = $Spotter->countAllAircraftRegistrations(false,$globalArchiveMonths);
1040
				foreach ($alldata as $number) {
1041
					$this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao']);
1042
				}
1043
				$alldata = $Spotter->countAllCallsigns(false,$globalArchiveMonths);
1044
				foreach ($alldata as $number) {
1045
					$this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],$number['airline_icao']);
1046
				}
1047
				$alldata = $Spotter->countAllOwners(false,$globalArchiveMonths);
1048
				foreach ($alldata as $number) {
1049
					$this->addStatOwner($number['owner_name'],$number['owner_count']);
1050
				}
1051 View Code Duplication
				if ($Connection->tableExists('countries')) {
1 ignored issue
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...
1052
					$alldata = $Spotter->countAllFlightOverCountries(false,$globalArchiveMonths);
1053
					foreach ($alldata as $number) {
1054
						$this->addStatCountry($number['flight_country_iso2'],$number['flight_country_iso3'],$number['flight_country'],$number['flight_count']);
1055
					}
1056
				}
1057
				$alldata = $Spotter->countAllPilots(false,$globalArchiveMonths);
1058
				foreach ($alldata as $number) {
1059
					$this->addStatPilot($number['pilot_id'],$number['pilot_count']);
1060
				}
1061
				$pall = $Spotter->countAllDepartureAirports(false,$globalArchiveMonths);
1062
        			$dall = $Spotter->countAllDetectedDepartureAirports(false,$globalArchiveMonths);
1063
	        		$alldata = array();
1064
    				foreach ($pall as $value) {
1065
	        			$icao = $value['airport_departure_icao'];
1066
    					$alldata[$icao] = $value;
1067
	        		}
1068
	        		foreach ($dall as $value) {
1069
    					$icao = $value['airport_departure_icao'];
1070
        				if (isset($alldata[$icao])) {                                                           
1071
        					$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1072
	        			} else $alldata[$icao] = $value;
1073
    				}
1074
        			$count = array();
1075
        			foreach ($alldata as $key => $row) {
1076
        				$count[$key] = $row['airport_departure_icao_count'];
1077
	        		}
1078
    				array_multisort($count,SORT_DESC,$alldata);
1079
1080
				//print_r($alldate);
1081 View Code Duplication
				foreach ($alldata as $number) {
1 ignored issue
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...
1082
					$this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count']);
1083
				}
1084
				$pdata = $Spotter->countAllArrivalAirports(false,$globalArchiveMonths);
1085
        			$dall = $Spotter->countAllDetectedArrivalAirports(false,$globalArchiveMonths);
1086
	        		$alldata = array();
1087
    				foreach ($pdata as $value) {
1088
	        			$icao = $value['airport_arrival_icao'];
1089
    					$alldata[$icao] = $value;
1090
	        		}
1091
	        		foreach ($dall as $value) {
1092
    					$icao = $value['airport_arrival_icao'];
1093
        				if (isset($alldata[$icao])) {                                                           
1094
        					$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1095
	        			} else $alldata[$icao] = $value;
1096
    				}
1097
        			$count = array();
1098
        			foreach ($alldata as $key => $row) {
1099
        				$count[$key] = $row['airport_arrival_icao_count'];
1100
	        		}
1101
    				array_multisort($count,SORT_DESC,$alldata);
1102 View Code Duplication
				foreach ($alldata as $number) {
1 ignored issue
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...
1103
					$this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count']);
1104
				}
1105
				$this->addStat('aircrafts_byyear',$this->getStatsAircraftTotal(),date('Y').'-01-01 00:00:00');
1106
				$this->addStat('airlines_byyear',$this->getStatsAirlineTotal(),date('Y').'-01-01 00:00:00');
1107
				$this->addStat('owner_byyear',$this->getStatsOwnerTotal(),date('Y').'-01-01 00:00:00');
1108
				$this->addStat('pilot_byyear',$this->getStatsPilotTotal(),date('Y').'-01-01 00:00:00');
1109
			
1110 View Code Duplication
				if ($globalArchive) {
1 ignored issue
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...
1111
					if ($globalDBdriver == 'mysql') {
1112
						$query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')";
1113
					} else {
1114
						$query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP)";
1115
					}
1116
					try {
1117
						$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
1118
						$sth->execute();
1119
					} catch(PDOException $e) {
1120
						return "error : ".$e->getMessage().' - query : '.$query."\n";
1121
					}
1122
				}
1123
	
1124
				//$query = 'DELETE FROM spotter_output WHERE spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$globalArchiveMonths.' MONTH)';
1125
				if ($globalDBdriver == 'mysql') {
1126
					$query = "DELETE FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')";
1127
				} else {
1128
					$query = "DELETE FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS, 'YYYY/mm/01') AS TIMESTAMP)";
1129
				}
1130
				try {
1131
					$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
1132
					$sth->execute();
1133
				} catch(PDOException $e) {
1134
					return "error : ".$e->getMessage().' - query : '.$query."\n";
1135
				}
1136
			}
1137
			$this->addLastStatsUpdate('last_update_stats',date('Y-m-d G:i:s'));
1138
		} else {
1139
			echo 'Update stats !'."\n";
1140
			if (isset($last_update[0]['value'])) {
1141
				$last_update_day = $last_update[0]['value'];
1142
			} else $last_update_day = '2012-12-12 12:12:12';
1143
			$Spotter = new Spotter($this->db);
1144
			$alldata = $Spotter->countAllAircraftTypes(false,0,$last_update_day);
1145
			foreach ($alldata as $number) {
1146
				$this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name']);
1147
			}
1148
			$alldata = $Spotter->countAllAirlines(false,0,$last_update_day);
1149
			foreach ($alldata as $number) {
1150
				$this->addStatAirline($number['airline_icao'],$number['airline_count'],$number['airline_name']);
1151
			}
1152
			$alldata = $Spotter->countAllAircraftRegistrations(false,0,$last_update_day);
1153
			foreach ($alldata as $number) {
1154
				$this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao']);
1155
			}
1156
			$alldata = $Spotter->countAllCallsigns(false,0,$last_update_day);
1157
			foreach ($alldata as $number) {
1158
				$this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],$number['airline_icao']);
1159
			}
1160
			$alldata = $Spotter->countAllOwners(false,0,$last_update_day);
1161
			foreach ($alldata as $number) {
1162
				$this->addStatOwner($number['owner_name'],$number['owner_count']);
1163
			}
1164
			$alldata = $Spotter->countAllPilots(false,0,$last_update_day);
1165
			foreach ($alldata as $number) {
1166
				$this->addStatPilot($number['pilot_id'],$number['pilot_count']);
1167
			}
1168
			$pall = $Spotter->countAllDepartureAirports(false,0,$last_update_day);
1169
        		$dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day);
1170
	        	$alldata = array();
1171
    			foreach ($pall as $value) {
1172
	        		$icao = $value['airport_departure_icao'];
1173
    				$alldata[$icao] = $value;
1174
	        	}
1175
	        	foreach ($dall as $value) {
1176
    				$icao = $value['airport_departure_icao'];
1177
        			if (isset($alldata[$icao])) {                                                           
1178
    					$alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count'];
1179
        			} else $alldata[$icao] = $value;
1180
			}
1181
    			$count = array();
1182
    			foreach ($alldata as $key => $row) {
1183
    				$count[$key] = $row['airport_departure_icao_count'];
1184
        		}
1185
			array_multisort($count,SORT_DESC,$alldata);
1186
1187 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
1188
				$this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count']);
1189
			}
1190
			$pall = $Spotter->countAllArrivalAirports(false,0,$last_update_day);
1191
        		$dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day);
1192
	        	$alldata = array();
1193
    			foreach ($pall as $value) {
1194
	        		$icao = $value['airport_arrival_icao'];
1195
    				$alldata[$icao] = $value;
1196
	        	}
1197
	        	foreach ($dall as $value) {
1198
    				$icao = $value['airport_arrival_icao'];
1199
        			if (isset($alldata[$icao])) {                                                           
1200
        				$alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count'];
1201
	        		} else $alldata[$icao] = $value;
1202
    			}
1203
        		$count = array();
1204
        		foreach ($alldata as $key => $row) {
1205
        			$count[$key] = $row['airport_arrival_icao_count'];
1206
	        	}
1207
    			array_multisort($count,SORT_DESC,$alldata);
1208 View Code Duplication
                        foreach ($alldata as $number) {
1 ignored issue
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...
1209
				$this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count']);
1210
			}
1211 View Code Duplication
			if ($Connection->tableExists('countries')) {
1 ignored issue
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...
1212
				$SpotterArchive = new SpotterArchive();
1213
				$alldata = $SpotterArchive->countAllFlightOverCountries(false,0,$last_update_day);
1214
				foreach ($alldata as $number) {
1215
					$this->addStatCountry($number['flight_country_iso2'],$number['flight_country_iso3'],$number['flight_country'],$number['flight_count']);
1216
				}
1217
			}
1218
			
1219
1220
			// Add by month using getstat if month finish...
1221
1222
			//if (date('m',strtotime($last_update_day)) != date('m')) {
1223
			$Spotter = new Spotter($this->db);
1224
			$alldata = $Spotter->countAllMonths();
1225
			$lastyear = false;
1226 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
1227
				if ($number['year_name'] != date('Y')) $lastyear = true;
1228
				$this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1229
			}
1230
			$alldata = $Spotter->countAllMilitaryMonths();
1231 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
1232
				$this->addStat('military_flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1233
			}
1234
			$alldata = $Spotter->countAllMonthsOwners();
1235 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
1236
				$this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1237
			}
1238
			$alldata = $Spotter->countAllMonthsPilots();
1239 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
1240
				$this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1241
			}
1242
			$alldata = $Spotter->countAllMonthsAirlines();
1243 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
1244
				$this->addStat('airlines_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1245
			}
1246
			$alldata = $Spotter->countAllMonthsAircrafts();
1247 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
1248
				$this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1249
			}
1250
			$alldata = $Spotter->countAllMonthsRealArrivals();
1251 View Code Duplication
			foreach ($alldata as $number) {
1 ignored issue
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...
1252
				$this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name'])));
1253
			}
1254
			echo 'Airports data...'."\n";
1255
			echo '...Departure'."\n";
1256
			$this->deleteStatAirport('daily');
1257
			$pall = $Spotter->getLast7DaysAirportsDeparture();
1258
        		$dall = $Spotter->getLast7DaysDetectedAirportsDeparture();
1259
	        	$alldata = array();
1260
    			foreach ($pall as $value) {
1261
	        		$icao = $value['departure_airport_icao'];
1262
    				$alldata[$icao] = $value;
1263
	        	}
1264
	        	foreach ($dall as $value) {
1265
    				$icao = $value['departure_airport_icao'];
1266
        			if (isset($alldata[$icao])) {                                                           
1267
        				$alldata[$icao]['departure_airport_count'] = $alldata[$icao]['departure_airport_count'] + $value['departure_airport_count'];
1268
	        		} else $alldata[$icao] = $value;
1269
    			}
1270
        		$count = array();
1271
        		foreach ($alldata as $key => $row) {
1272
        			$count[$key] = $row['departure_airport_count'];
1273
	        	}
1274
    			array_multisort($count,SORT_DESC,$alldata);
1275
			foreach ($alldata as $number) {
1276
				$this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count']);
1277
			}
1278
			echo '...Arrival'."\n";
1279
			$pall = $Spotter->getLast7DaysAirportsArrival();
1280
        		$dall = $Spotter->getLast7DaysDetectedAirportsArrival();
1281
	        	$alldata = array();
1282
    			foreach ($pall as $value) {
1283
	        		$icao = $value['arrival_airport_icao'];
1284
    				$alldata[$icao] = $value;
1285
	        	}
1286
	        	foreach ($dall as $value) {
1287
    				$icao = $value['arrival_airport_icao'];
1288
        			if (isset($alldata[$icao])) {                                                           
1289
        				$alldata[$icao]['arrival_airport_icao_count'] = $alldata[$icao]['arrival_airport_count'] + $value['arrival_airport_count'];
1290
	        		} else $alldata[$icao] = $value;
1291
    			}
1292
        		$count = array();
1293
        		foreach ($alldata as $key => $row) {
1294
        			$count[$key] = $row['arrival_airport_count'];
1295
	        	}
1296
    			array_multisort($count,SORT_DESC,$alldata);
1297
1298
			foreach ($alldata as $number) {
1299
				$this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count']);
1300
			}
1301
1302
			echo 'Flights data...'."\n";
1303
			$this->deleteStatFlight('month');
1304
			echo '-> countAllDatesLastMonth...'."\n";
1305
			$alldata = $Spotter->countAllDatesLastMonth();
1306
			foreach ($alldata as $number) {
1307
				$this->addStatFlight('month',$number['date_name'],$number['date_count']);
1308
			}
1309
			echo '-> countAllDates...'."\n";
1310
			$previousdata = $this->countAllDates();
1311
			$this->deleteStatFlight('date');
1312
			$alldata = $Common->array_merge_noappend($previousdata,$Spotter->countAllDates());
1313
			$values = array();
1314
			foreach ($alldata as $cnt) {
1315
				$values[] = $cnt['date_count'];
1316
			}
1317
			array_multisort($values,SORT_DESC,$alldata);
1318
			array_splice($alldata,11);
1319
			foreach ($alldata as $number) {
1320
				$this->addStatFlight('date',$number['date_name'],$number['date_count']);
1321
			}
1322
			
1323
			$this->deleteStatFlight('hour');
1324
			echo '-> countAllHours...'."\n";
1325
			$alldata = $Spotter->countAllHours('hour');
1326
			foreach ($alldata as $number) {
1327
				$this->addStatFlight('hour',$number['hour_name'],$number['hour_count']);
1328
			}
1329
			if ($lastyear) {
1330
				echo 'Data from last year...'."\n";
1331
				// SUM all previous month to put as year
1332
				$previous_year = date('Y');
1333
				$previous_year--;
1334
				$this->addStat('aircrafts_byyear',$this->getSumStats('aircrafts_bymonth',$previous_year),$previous_year.'-01-01 00:00:00');
1335
				$this->addStat('airlines_byyear',$this->getSumStats('airlines_bymonth',$previous_year),$previous_year.'-01-01 00:00:00');
1336
				$this->addStat('owner_byyear',$this->getSumStats('owner_bymonth',$previous_year),$previous_year.'-01-01 00:00:00');
1337
				$this->addStat('pilot_byyear',$this->getSumStats('pilot_bymonth',$previous_year),$previous_year.'-01-01 00:00:00');
1338
				
1339 View Code Duplication
				if (isset($globalArchiveYear) && $globalArchiveYear) {
1 ignored issue
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...
1340
					if ($globalArchive) {
1341
						$query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00'";
1342
						try {
1343
							$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
1344
							$sth->execute();
1345
						} catch(PDOException $e) {
1346
							return "error : ".$e->getMessage().' - query : '.$query."\n";
1347
						}
1348
					}
1349
					echo 'Delete old data'."\n";
1350
					$query = "DELETE FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00'";
1351
					try {
1352
						$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
1353
						$sth->execute();
1354
					} catch(PDOException $e) {
1355
						return "error : ".$e->getMessage().' - query : '.$query."\n";
1356
					}
1357
				}
1358
			}
1359
			if ($globalArchiveMonths > 0) {
1360 View Code Duplication
				if ($globalArchive) {
1 ignored issue
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...
1361
					echo 'Archive old data...'."\n";
1362
					if ($globalDBdriver == 'mysql') {
1363
						//$query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')";
1364
						$query = "INSERT INTO spotter_archive_output (spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,aircraft_name,aircraft_manufacturer,departure_airport_icao,departure_airport_name,departure_airport_city,departure_airport_country,departure_airport_time,arrival_airport_icao,arrival_airport_name,arrival_airport_city,arrival_airport_country,arrival_airport_time,route_stop,date,latitude,longitude,waypoints,altitude,heading,ground_speed,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time)
1365
							    SELECT spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,aircraft_name,aircraft_manufacturer,departure_airport_icao,departure_airport_name,departure_airport_city,departure_airport_country,departure_airport_time,arrival_airport_icao,arrival_airport_name,arrival_airport_city,arrival_airport_country,arrival_airport_time,route_stop,date,latitude,longitude,waypoints,altitude,heading,ground_speed,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time
1366
	    						     FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')";
1367
					} else {
1368
						$query = "INSERT INTO spotter_archive_output (spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,aircraft_name,aircraft_manufacturer,departure_airport_icao,departure_airport_name,departure_airport_city,departure_airport_country,departure_airport_time,arrival_airport_icao,arrival_airport_name,arrival_airport_city,arrival_airport_country,arrival_airport_time,route_stop,date,latitude,longitude,waypoints,altitude,heading,ground_speed,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time)
1369
							     SELECT 
1370
								spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,aircraft_name,aircraft_manufacturer,departure_airport_icao,departure_airport_name,departure_airport_city,departure_airport_country,departure_airport_time,arrival_airport_icao,arrival_airport_name,arrival_airport_city,arrival_airport_country,arrival_airport_time,route_stop,date,latitude,longitude,waypoints,altitude,heading,ground_speed,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time
1371
							    FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP)";
1372
					}
1373
					try {
1374
						$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
1375
						$sth->execute();
1376
					} catch(PDOException $e) {
1377
						return "error : ".$e->getMessage();
1378
					}
1379
				}
1380
				echo 'Deleting old data...'."\n";
1381
				//$query = 'DELETE FROM spotter_output WHERE spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$globalArchiveMonths.' MONTH)';
1382
				if ($globalDBdriver == 'mysql') {
1383
					$query = "DELETE FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')";
1384
				} else {
1385
					$query = "DELETE FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP)";
1386
				}
1387
				try {
1388
					$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
1389
					$sth->execute();
1390
				} catch(PDOException $e) {
1391
					return "error : ".$e->getMessage();
1392
				}
1393
			}
1394
			echo 'Insert last stats update date...'."\n";
1395
			date_default_timezone_set('UTC');
1396
			$this->addLastStatsUpdate('last_update_stats',date('Y-m-d G:i:s'));
1397
		}
1398
	}
1399
}
1400
1401
?>
1 ignored issue
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...