Completed
Push — master ( 53a855...571e48 )
by Yannick
09:18
created

SpotterImport::arrival()   D

Complexity

Conditions 22
Paths 26

Size

Total Lines 37
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 22
eloc 30
nc 26
nop 1
dl 0
loc 37
rs 4.8197
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
require_once(dirname(__FILE__).'/class.Connection.php');
3
require_once(dirname(__FILE__).'/class.Spotter.php');
4
require_once(dirname(__FILE__).'/class.SpotterLive.php');
5
require_once(dirname(__FILE__).'/class.SpotterArchive.php');
6
require_once(dirname(__FILE__).'/class.Scheduler.php');
7
require_once(dirname(__FILE__).'/class.Translation.php');
8
require_once(dirname(__FILE__).'/class.Stats.php');
9
require_once(dirname(__FILE__).'/class.Source.php');
10
11
class SpotterImport {
12
    private $all_flights = array();
13
    private $last_delete_hourly = '';
14
    private $last_delete = '';
15
    private $stats = array();
16
    private $tmd = 0;
17
    private $source_location = array();
18
    public $db = null;
19
    public $nb = 0;
20
21
    public function __construct($dbc = null) {
22
	global $globalBeta;
23
	$Connection = new Connection($dbc);
24
	$this->db = $Connection->db();
25
	date_default_timezone_set('UTC');
26
27
	// Get previous source stats
28
	$Stats = new Stats($dbc);
29
	$currentdate = date('Y-m-d');
30
	$sourcestat = $Stats->getStatsSource($currentdate);
31
	if (!empty($sourcestat)) {
32
	    foreach($sourcestat as $srcst) {
33
	    	$type = $srcst['stats_type'];
34
		if ($type == 'polar' || $type == 'hist') {
35
		    $source = $srcst['source_name'];
36
		    $data = $srcst['source_data'];
37
		    $this->stats[$currentdate][$source][$type] = json_decode($data,true);
38
	        }
39
	    }
40
	}
41
    }
42
43
    public function get_Schedule($id,$ident) {
44
	global $globalDebug, $globalFork, $globalSchedulesFetch;
45
	// Get schedule here, so it's done only one time
46
	
47
	/*
48
	if ($globalFork) {
49
		$Connection = new Connection();
50
		$dbc = $Connection->db;
51
	} else $dbc = $this->db;
52
	*/
53
	$dbc = $this->db;
54
	
55
	if ($globalSchedulesFetch) {
56
	$Spotter = new Spotter($dbc);
57
	$Schedule = new Schedule($dbc);
58
	$Translation = new Translation($dbc);
59
	$operator = $Spotter->getOperator($ident);
60
	if ($Schedule->checkSchedule($operator) == 0) {
61
	    $operator = $Translation->checkTranslation($ident);
62
	    if ($Schedule->checkSchedule($operator) == 0) {
63
		$schedule = $Schedule->fetchSchedule($operator);
64
		if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) {
65
		    if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n";
66
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime']));
67
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime']));
68
		    // Should also check if route schedule = route from DB
69
		    if ($schedule['DepartureAirportIATA'] != '') {
70
			if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) {
71
			    $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']);
72
			    if ($airport_icao != '') {
73
				$this->all_flights[$id]['departure_airport'] = $airport_icao;
74
				if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n";
75
			    }
76
			}
77
		    }
78
		    if ($schedule['ArrivalAirportIATA'] != '') {
79
			if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) {
80
			    $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']);
81
			    if ($airport_icao != '') {
82
				$this->all_flights[$id]['arrival_airport'] = $airport_icao;
83
				if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n";
84
			    }
85
			}
86
		    }
87
		    $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']);
88
		}
89
	    }
90
	}
91
	// close connection, at least one way will work ?
92
       
93
	$Spotter->db = null;
94
	$Schedule->db = null;
95
	$Translation->db = null;
96
	unset($Spotter->db);
97
	unset($Schedule->db);
98
	unset($Translation->db);
99
100
	/*
101
	if ($globalFork) {
102
	    $Connection->db = null;
103
	    unset($Connection->db);
104
	}
105
	  */
106
	}
107
    }
108
109
    public function checkAll() {
110
	global $globalDebug;
111
	if ($globalDebug) echo "Update last seen flights data...\n";
112
	foreach ($this->all_flights as $key => $flight) {
113
	    if (isset($this->all_flights[$key]['id'])) {
114
		//echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].'  '.$this->all_flights[$key]['longitude']."\n";
115
    		$Spotter = new Spotter($this->db);
116
        	$real_arrival = $this->arrival($key);
117
        	$Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
118
            }
119
	}
120
    }
121
122
    public function arrival($key) {
123
	global $globalClosestMinDist, $globalDebug;
124
	$Spotter = new Spotter($this->db);
125
        $airport_icao = '';
126
        $airport_time = '';
127
        if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50;
128
	if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
129
	    $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist);
130
    	    if (isset($closestAirports[0])) {
131
        	if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) {
132
        	    $airport_icao = $closestAirports[0]['icao'];
133
        	    $airport_time = $this->all_flights[$key]['datetime'];
134
        	    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
135
        	} elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') {
136
        	    foreach ($closestAirports as $airport) {
137
        		if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) {
138
        		    $airport_icao = $airport['icao'];
139
        		    $airport_time = $this->all_flights[$key]['datetime'];
140
        		    if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n";
141
        		    break;
142
        		}
143
        	    }
144
        	} elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) {
145
        		$airport_icao = $closestAirports[0]['icao'];
146
        		$airport_time = $this->all_flights[$key]['datetime'];
147
        	} else {
148
        		if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n";
149
        	}
150
    	    } else {
151
    		    if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n";
152
    	    }
153
154
        } else {
155
        	if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n";
156
        }
157
        return array('airport_icao' => $airport_icao,'airport_time' => $airport_time);
158
    }
159
160
161
162
    public function del() {
163
	global $globalDebug;
164
	// Delete old infos
165
	foreach ($this->all_flights as $key => $flight) {
166
    	    if (isset($flight['lastupdate'])) {
167
        	if ($flight['lastupdate'] < (time()-3000)) {
168
            	    if (isset($this->all_flights[$key]['id'])) {
169
            		if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n";
170
			/*
171
			$SpotterLive = new SpotterLive();
172
            		$SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']);
173
			$SpotterLive->db = null;
174
			*/
175
            		$real_arrival = $this->arrival($key);
176
            		$Spotter = new Spotter($this->db);
177
            		if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') {
178
				$result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']);
179
				if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
180
			}
181
			// Put in archive
182
//			$Spotter->db = null;
183
            	    }
184
            	    unset($this->all_flights[$key]);
185
    	        }
186
	    }
187
        }
188
    }
189
190
    public function add($line) {
191
	global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate;
192
	//if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE;
193
	if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02';
194
/*
195
	$Spotter = new Spotter();
196
	$dbc = $Spotter->db;
197
	$SpotterLive = new SpotterLive($dbc);
198
	$Common = new Common();
199
	$Schedule = new Schedule($dbc);
200
*/
201
	date_default_timezone_set('UTC');
202
	// signal handler - playing nice with sockets and dump1090
203
	// pcntl_signal_dispatch();
204
205
	// get the time (so we can figure the timeout)
206
	$time = time();
0 ignored issues
show
Unused Code introduced by
$time 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...
207
208
	//pcntl_signal_dispatch();
209
	$dataFound = false;
210
	$putinarchive = false;
0 ignored issues
show
Unused Code introduced by
$putinarchive 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...
211
	$send = false;
212
	
213
	// SBS format is CSV format
214
	if(is_array($line) && isset($line['hex'])) {
215
	    //print_r($line);
216
  	    if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) {
217
218
		// Increment message number
219
		if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) {
220
		    $current_date = date('Y-m-d');
221
		    $source = $line['source_name'];
222
		    if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source'];
223
		    if (!isset($this->stats[$current_date][$source]['msg'])) {
224
		    	$this->stats[$current_date][$source]['msg']['date'] = time();
225
		    	$this->stats[$current_date][$source]['msg']['nb'] = 1;
226
		    } else $this->stats[$current_date][$source]['msg']['nb'] += 1;
227
		}
228
		
229
		/*
230
		$dbc = $this->db;
231
		$Connection = new Connection($dbc);
232
		$Connection->connectionExists();
233
		$dbc = $Connection->db;
234
		*/
235
		//$Spotter = new Spotter($dbc);
236
		//$SpotterLive = new SpotterLive($dbc);
237
		$Common = new Common();
238
//		echo $this->nb++."\n";
239
		//$this->db = $dbc;
240
241
		$hex = trim($line['hex']);
242
	        if (!isset($line['id'])) $id = trim($line['hex']);
243
	        else $id = trim($line['id']);
244
		
245
		//print_r($this->all_flights);
246
		if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) {
247
		    $this->all_flights[$id] = array('hex' => $hex);
248
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
249
		    //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
250
			//$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
251
		    //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
252
		    if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????')) {
253
254
			$timeelapsed = microtime(true);
255
			$Spotter = new Spotter($this->db);
256
			$aircraft_icao = $Spotter->getAllAircraftType($hex);
257
			$Spotter->db = null;
258
			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
259
260
			if ($aircraft_icao == '' && isset($line['aircraft_type'])) {
261
			    if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID';
262
			    elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL';
263
			    elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE';
264
			    elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC';
265
			}
266
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
267
		    } else if (isset($line['aircraft_name'])) {
268
			// Get aircraft ICAO from aircraft name
269
			$Spotter = new Spotter($this->db);
270
			$aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']);
271
			$Spotter->db = null;
272
			if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao));
273
			else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA'));
274
		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao']));
275
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => false));
276
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time()));
277
		    if (!isset($line['id'])) {
278
			if (!isset($globalDaemon)) $globalDaemon = TRUE;
279
//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
280
//			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
281
			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
282
		        //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
283
		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
284
285
		    if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n";
286
		}
287
		
288
		if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) {
289
		    if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) {
290
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime']));
291
		    } else {
292
				if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
293
				elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n";
294
				/*
295
				echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']);
296
				print_r($this->all_flights[$id]);
297
				print_r($line);
298
				*/
299
				return '';
300
		    }
301
		} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s')));
302
303
		if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') {
304
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration']));
305
		}
306
		if (isset($line['waypoints']) && $line['waypoints'] != '') {
307
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints']));
308
		}
309
		if (isset($line['pilot_id']) && $line['pilot_id'] != '') {
310
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id']));
311
		}
312
		if (isset($line['pilot_name']) && $line['pilot_name'] != '') {
313
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name']));
314
		}
315
 
316
		if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) {
317
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident'])));
318
		    if ($this->all_flights[$id]['addedSpotter'] == 1) {
319
			$timeelapsed = microtime(true);
320
            		$Spotter = new Spotter($this->db);
321
            		$result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident']);
322
			if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n";
323
			$Spotter->db = null;
324
			if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
325
		    }
326
327
/*
328
		    if (!isset($line['id'])) {
329
			if (!isset($globalDaemon)) $globalDaemon = TRUE;
330
//			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi')));
331
			if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
332
		        else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
333
		     } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
334
  */
335
		    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
336
337
		    //$putinarchive = true;
338
		    if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) {
339
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time']));
340
		    }
341
		    if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) {
342
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time']));
343
		    }
344
		    if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) {
345
		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
346
		    } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) {
347
				$timeelapsed = microtime(true);
348
				$Spotter = new Spotter($this->db);
349
				$line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']);
350
				$line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']);
351
		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => ''));
352
				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
353
354
		    } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') {
355
			$timeelapsed = microtime(true);
356
			$Spotter = new Spotter($this->db);
357
			$route = $Spotter->getRouteInfo(trim($line['ident']));
358
			if (!isset($route['fromairport_icao']) && !isset($route['toairport_icao'])) {
359
				$Translation = new Translation($this->db);
360
				$ident = $Translation->checkTranslation(trim($line['ident']));
361
				$route = $Spotter->getRouteInfo($ident);
362
				$Translation->db = null;
363
			}
364
			$Spotter->db = null;
365
			if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
366
367
			if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) {
368
			    //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) {
369
			    if ($route['fromairport_icao'] != $route['toairport_icao']) {
370
				//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop']));
371
		    		$this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop']));
372
		    	    }
373
			}
374
			if (!isset($globalFork)) $globalFork = TRUE;
375
			if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) {
376
			  /*
377
			    if (function_exists('pcntl_fork') && $globalFork) {
378
				$this->nb++;
379
				$pids[$id] = pcntl_fork();
380
				if (!$pids[$id]) {
381
				    $sid = posix_setsid();
382
				    $this->get_Schedule($id,trim($line['ident']));
383
		    		    exit(0);
384
				}
385
			    } else {
386
			    */
387
				$this->get_Schedule($id,trim($line['ident']));
388
			//    }
389
			}
390
		    }
391
		}
392
393
		if (isset($line['speed']) && $line['speed'] != '') {
394
		//    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12]));
395
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed'])));
396
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true));
397
		    //$dataFound = true;
398
		} else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) {
399
		    $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m');
400
		    if ($distance > 1000 && $distance < 10000) {
401
		    // use datetime
402
			$speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']);
403
			$speed = $speed*3.6;
404
			if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed)));
405
  			if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n";
406
		    }
407
		}
408
409
410
411
	        if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) {
412
	    	    if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']);
413
	    	    else unset($timediff);
414
	    	    if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || !isset($timediff) || $timediff > 800 || ($timediff > 10 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) {
415
			if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) {
416
			    if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) {
417
				$this->all_flights[$id]['archive_latitude'] = $line['latitude'];
418
				$this->all_flights[$id]['archive_longitude'] = $line['longitude'];
419
				$this->all_flights[$id]['putinarchive'] = true;
420
				
421
				
422
				//echo "\n".' ------- Check Country.... ';
423
				$timeelapsed = microtime(true);
424
				$Spotter = new Spotter($this->db);
425
				$all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']);
426
				if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2'];
427
				$Spotter->db = null;
428
				if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
429
				$this->tmd = 0;
430
				//echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n";
431
				//$putinarchive = true;
432
			    } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
433
			    /*
434
				echo '//////// checkLine FALSE'."\n";
435
				echo 'Check DATA : '.$this->all_flights[$id]['archive_latitude'].' '.$this->all_flights[$id]['archive_longitude'].' '.$this->all_flights[$id]['livedb_latitude'].' '.$this->all_flights[$id]['livedb_longitude'].' '.$line['latitude'].' '.$line['longitude']."\n";
436
			    */
437
			    }
438
			}
439
440
			if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) {
441
			    //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
442
				if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
443
				if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
444
				    $this->all_flights[$id]['livedb_latitude'] = $line['latitude'];
445
				    $dataFound = true;
446
				    $this->all_flights[$id]['time_last_coord'] = time();
447
				}
448
				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
449
				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude']));
450
				/*
451
				if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) {
452
				    $this->all_flights[$id]['archive_latitude'] = $line['latitude'];
453
				    $this->all_flights[$id]['putinarchive'] = true;
454
				    //$putinarchive = true;
455
				}
456
				*/
457
			    /*
458
			    } elseif (isset($this->all_flights[$id]['latitude'])) {
459
				if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n";
460
			    }
461
			    */
462
			}
463
			if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) {
464
			    if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360;
465
			    //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == ''  || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) {
466
				if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
467
				if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') {
468
				    $this->all_flights[$id]['livedb_longitude'] = $line['longitude'];
469
				    $dataFound = true;
470
				    $this->all_flights[$id]['time_last_coord'] = time();
471
				}
472
				// elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n";
473
				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude']));
474
				/*
475
				if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) {
476
				    $this->all_flights[$id]['archive_longitude'] = $line['longitude'];
477
				    $this->all_flights[$id]['putinarchive'] = true;
478
				    //$putinarchive = true;
479
				}
480
				*/
481
			/*
482
			    } elseif (isset($this->all_flights[$id]['longitude'])) {
483
				if ($globalDebug) echo '!!! Strange longitude value - diff : '.abs($this->all_flights[$id]['longitude']-$line['longitude']).'- previous lat : '.$this->all_flights[$id]['longitude'].'- new lat : '.$line['longitude']."\n";
484
			    }
485
			    */
486
			}
487
488
		    } else if ($globalDebug && $timediff > 20) {
489
			$this->tmd = $this->tmd + 1;
490
			echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n";
491
			echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -";
492
			echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - ";
493
			echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n";
494
		    }
495
		}
496
		if (isset($line['verticalrate']) && $line['verticalrate'] != '') {
497
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate']));
498
		    //$dataFound = true;
499
		}
500
		if (isset($line['format_source']) && $line['format_source'] != '') {
501
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source']));
502
		}
503
		if (isset($line['source_name']) && $line['source_name'] != '') {
504
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name']));
505
		}
506
		if (isset($line['emergency']) && $line['emergency'] != '') {
507
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency']));
508
		    //$dataFound = true;
509
		}
510
		if (isset($line['ground']) && $line['ground'] != '') {
511
		    if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) {
512
			// Here we force archive of flight because after ground it's a new one (or should be)
513
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0));
514
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1));
515
			if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi')));
516
		        elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id']));
517
			elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident']));
518
		    }
519
		    if ($line['ground'] != 1) $line['ground'] = 0;
520
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground']));
521
		    //$dataFound = true;
522
		}
523
		if (isset($line['squawk']) && $line['squawk'] != '') {
524
		    if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) {
525
			    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
526
			    $highlight = '';
527
			    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC';
528
			    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC';
529
			    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC';
530
			    if ($highlight != '') {
531
				$timeelapsed = microtime(true);
532
				$Spotter = new Spotter($this->db);
533
				$Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight);
534
				$Spotter->db = null;
535
				if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
536
537
				$this->all_flights[$id]['putinarchive'] = true;
538
				//$putinarchive = true;
539
				$highlight = '';
0 ignored issues
show
Unused Code introduced by
$highlight 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...
540
			    }
541
			    
542
		    } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk']));
543
		    //$dataFound = true;
544
		}
545
546
		if (isset($line['altitude']) && $line['altitude'] != '') {
547
		    //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) {
548
			if (abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 2) $this->all_flights[$id]['putinarchive'] = true;
549
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100)));
550
			$this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude']));
551
			//$dataFound = true;
552
		    //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n";
553
  		}
554
555
		if (isset($line['noarchive']) && $line['noarchive'] === true) {
556
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true));
557
		}
558
		
559
		if (isset($line['heading']) && $line['heading'] != '') {
560
		    if (abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true;
561
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading'])));
562
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true));
563
		    //$dataFound = true;
564
  		} elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) {
565
  		    $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
566
		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading)));
567
		    if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true;
568
  		    if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n";
569
  		} elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') {
570
  		    // If not enough messages and ACARS set heading to 0
571
  		    $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0));
572
  		}
573
		if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false;
574
		elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false;
575
576
//		print_r($this->all_flights[$id]);
577
		//gets the callsign from the last hour
578
		//if (time()-$this->all_flights[$id]['lastupdate'] > 30 && $dataFound == true && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
579
		//if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
580
		if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') {
581
		    $this->all_flights[$id]['lastupdate'] = time();
582
		    if ($this->all_flights[$id]['addedSpotter'] == 0) {
583
		        if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
584
			    //print_r($this->all_flights);
585
			    //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n";
586
			    //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']);
587
			    if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) {
588
				if ($globalDebug) echo "Check if aircraft is already in DB...";
589
				$timeelapsed = microtime(true);
590
				$SpotterLive = new SpotterLive($this->db);
591
				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) {
592
				    $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']);
593
				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
594
				} elseif (isset($line['id'])) {
595
				    $recent_ident = $SpotterLive->checkIdRecent($line['id']);
596
				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
597
				} elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') {
598
				    $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']);
599
				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
600
				} else $recent_ident = '';
601
				$SpotterLive->db=null;
602
603
				if ($globalDebug && $recent_ident == '') echo " Not in DB.\n";
604
				elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n";
605
			    } else {
606
				$recent_ident = '';
607
				$this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0));
608
			    }
609
			    //if there was no aircraft with the same callsign within the last hour and go post it into the archive
610
			    if($recent_ident == "")
611
			    {
612
				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : ";
613
				if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
614
				if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
615
				//adds the spotter data for the archive
616
				$ignoreImport = false;
617
				foreach($globalAirportIgnore as $airportIgnore) {
618
				    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
619
					$ignoreImport = true;
620
				    }
621
				}
622
				if (count($globalAirportAccept) > 0) {
623
				    $ignoreImport = true;
624
				    foreach($globalAirportIgnore as $airportIgnore) {
625
					if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
626
					    $ignoreImport = false;
627
					}
628
				    }
629
				}
630
				if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
631
				    foreach($globalAirlineIgnore as $airlineIgnore) {
632
					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
633
					    $ignoreImport = true;
634
					}
635
				    }
636
				}
637
				if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
638
				    $ignoreImport = true;
639
				    foreach($globalAirlineAccept as $airlineAccept) {
640
					if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
641
					    $ignoreImport = false;
642
					}
643
				    }
644
				}
645
				if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
646
				    $ignoreImport = true;
647
				    foreach($globalPilotIdAccept as $pilotIdAccept) {
648
					if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
649
					    $ignoreImport = false;
650
					}
651
				    }
652
				}
653
				
654
				if (!$ignoreImport) {
655
				    $highlight = '';
656
				    if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack';
657
				    if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)';
658
				    if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency';
659
				    if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi')));
660
				    $timeelapsed = microtime(true);
661
				    $Spotter = new Spotter($this->db);
662
				    $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name']);
663
				    $Spotter->db = null;
664
				    if ($globalDebug && isset($result)) echo $result."\n";
665
				    if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
666
				    
667
				    // Add source stat in DB
668
				    $Stats = new Stats($this->db);
669
				    if (!empty($this->stats)) {
670
					if ($globalDebug) echo 'Add source stats : ';
671
				        foreach($this->stats as $date => $data) {
672
					    foreach($data as $source => $sourced) {
673
					        //print_r($sourced);
674
				    	        if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date);
675
				    	        if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date);
676
				    		if (isset($sourced['msg'])) {
677
				    		    if (time() - $sourced['msg']['date'] > 10) {
678
				    		        $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date']));
679
				    		        echo $Stats->addStatSource($nbmsg,$source,'msg',$date);
680
			    			        unset($this->stats[$date][$source]['msg']);
681
			    			    }
682
			    			}
683
			    		    }
684
			    		    if ($date != date('Y-m-d')) {
685
			    			unset($this->stats[$date]);
686
			    		    }
687
				    	}
688
				    	if ($globalDebug) echo 'Done'."\n";
689
690
				    }
691
				    $Stats->db = null;
692
				    
693
				    $this->del();
694
				} elseif ($globalDebug) echo 'Ignore data'."\n";
695
				$ignoreImport = false;
0 ignored issues
show
Unused Code introduced by
$ignoreImport 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...
696
				$this->all_flights[$id]['addedSpotter'] = 1;
697
				//print_r($this->all_flights[$id]);
698
			/*
699
			if (isset($globalArchive) && $globalArchive) {
700
			    $archives_ident = SpotterLive->getAllLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
701
			    foreach ($archives_ident as $archive) {
702
				SpotterArchive->addSpotterArchiveData($archive['flightaware_id'], $archive['ident'], $archive['registration'],$archive['airline_name'],$archive['airline_icao'],$archive['airline_country'],$archive['airline_type'],$archive['aircraft_icao'],$archive['aircraft_shadow'],$archive['aircraft_name'],$archive['aircraft_manufacturer'], $archive['departure_airport_icao'],$archive['departure_airport_name'],$archive['departure_airport_city'],$archive['departure_airport_country'],$archive['departure_airport_time'],
703
				$archive['arrival_airport_icao'],$archive['arrival_airport_name'],$archive['arrival_airport_city'],$archive['arrival_airport_country'],$archive['arrival_airport_time'],
704
				$archive['route_stop'],$archive['date'],$archive['latitude'], $archive['longitude'], $archive['waypoints'], $archive['altitude'], $archive['heading'], $archive['ground_speed'],
705
				$archive['squawk'],$archive['ModeS']);
706
			    }
707
			}
708
			*/
709
			//SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']);
710
				if ($this->last_delete == '' || time() - $this->last_delete > 1800) {
711
				    if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours...";
712
				    //SpotterLive->deleteLiveSpotterDataNotUpdated();
713
				    $SpotterLive = new SpotterLive($this->db);
714
				    $SpotterLive->deleteLiveSpotterData();
715
				    $SpotterLive->db=null;
716
				    if ($globalDebug) echo " Done\n";
717
				    $this->last_delete = time();
0 ignored issues
show
Documentation Bug introduced by
The property $last_delete was declared of type string, but time() is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
718
				}
719
			    } else {
720
				if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa'  || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) {
721
				    $this->all_flights[$id]['id'] = $recent_ident;
722
				    $this->all_flights[$id]['addedSpotter'] = 1;
723
				}
724
				if (isset($globalDaemon) && !$globalDaemon) {
725
					$Spotter = new Spotter($this->db);
726
					$Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']);
727
					$Spotter->db = null;
728
				}
729
				
730
			    }
731
			}
732
		    }
733
		    //adds the spotter LIVE data
734
		    //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed);
735
		    //echo "\nAdd in Live !! \n";
736
		    //echo "{$line[8]} {$line[7]} - MODES:{$line[4]}  CALLSIGN:{$line[10]}   ALT:{$line[11]}   VEL:{$line[12]}   HDG:{$line[13]}   LAT:{$line[14]}   LON:{$line[15]}   VR:{$line[16]}   SQUAWK:{$line[17]}\n";
737
		    if ($globalDebug) {
738
			if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS)) {
739
				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n";
740
				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n";
741
			} else {
742
				if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n";
743
				else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n";
744
			}
745
		    }
746
		    $ignoreImport = false;
747
		    if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; }
748
		    if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; }
749
750
		    foreach($globalAirportIgnore as $airportIgnore) {
751
		        if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
752
			    $ignoreImport = true;
753
			}
754
		    }
755
		    if (count($globalAirportAccept) > 0) {
756
		        $ignoreImport = true;
757
		        foreach($globalAirportIgnore as $airportIgnore) {
758
			    if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) {
759
				$ignoreImport = false;
760
			    }
761
			}
762
		    }
763
		    if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) {
764
			foreach($globalAirlineIgnore as $airlineIgnore) {
765
			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) {
766
				$ignoreImport = true;
767
			    }
768
			}
769
		    }
770
		    if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) {
771
			$ignoreImport = true;
772
			foreach($globalAirlineAccept as $airlineAccept) {
773
			    if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) {
774
				$ignoreImport = false;
775
			    }
776
			}
777
		    }
778
		    if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) {
779
			$ignoreImport = true;
780
			foreach($globalPilotIdAccept as $pilotIdAccept) {
781
			    if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) {
782
			        $ignoreImport = false;
783
			    }
784
			}
785
		    }
786
787
		    if (!$ignoreImport) {
788
			if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) {
789
				if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : ";
790
				$timeelapsed = microtime(true);
791
				$SpotterLive = new SpotterLive($this->db);
792
				$result = $SpotterLive->addLiveSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'], $this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'], $this->all_flights[$id]['verticalrate'], $this->all_flights[$id]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']);
793
				$SpotterLive->db = null;
794
				if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n";
795
796
				// Put statistics in $this->stats variable
797
				//if ($line['format_source'] != 'aprs') {
798
				//if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) {
799
				if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs') {
800
					$source = $this->all_flights[$id]['source_name'];
801
					if ($source == '') $source = $this->all_flights[$id]['format_source'];
802
					if (!isset($this->source_location[$source])) {
803
						$Location = new Source();
804
						$coord = $Location->getLocationInfobySourceName($source);
805
						if (count($coord) > 0) {
806
							$latitude = $coord[0]['latitude'];
807
							$longitude = $coord[0]['longitude'];
808
						} else {
809
							$latitude = $globalCenterLatitude;
810
							$longitude = $globalCenterLongitude;
811
						}
812
						$this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude);
813
					} else {
814
						$latitude = $this->source_location[$source]['latitude'];
815
						$longitude = $this->source_location[$source]['longitude'];
816
					}
817
					$stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
818
					//$stats_heading = $stats_heading%22.5;
819
					$stats_heading = round($stats_heading/22.5);
820
					$stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']);
821
					$current_date = date('Y-m-d');
822
					if ($stats_heading == 16) $stats_heading = 0;
823
					if (!isset($this->stats[$current_date][$source]['polar'][1])) {
824
						for ($i=0;$i<=15;$i++) {
825
						    $this->stats[$current_date][$source]['polar'][$i] = 0;
826
						}
827
						$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
828
					} else {
829
						if ($this->stats[$current_date][$source]['polar'][$stats_heading] < $stats_distance) {
830
							$this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance;
831
						}
832
					}
833
					$distance = (round($stats_distance/10)*10);
834
					//echo '$$$$$$$$$$ DISTANCE : '.$distance.' - '.$source."\n";
835
					//var_dump($this->stats);
836
					if (!isset($this->stats[$current_date][$source]['hist'][$distance])) {
837
						if (isset($this->stats[$current_date][$source]['hist'][0])) {
838
						    end($this->stats[$current_date][$source]['hist']);
839
						    $mini = key($this->stats[$current_date][$source]['hist'])+10;
840
						} else $mini = 0;
841
						for ($i=$mini;$i<=$distance;$i+=10) {
842
						    $this->stats[$current_date][$source]['hist'][$i] = 0;
843
						}
844
						$this->stats[$current_date][$source]['hist'][$distance] = 1;
845
					} else {
846
						$this->stats[$current_date][$source]['hist'][$distance] += 1;
847
					}
848
				}
849
850
				$this->all_flights[$id]['lastupdate'] = time();
851
				if ($this->all_flights[$id]['putinarchive']) $send = true;
852
				//if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
853
				if ($globalDebug) echo $result."\n";
854
			} elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n";
855
			//$this->del();
856
			
857
			
858
			if ($this->last_delete_hourly == '' || time() - $this->last_delete_hourly > 900) {
859
			    if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour...";
860
			    $SpotterLive = new SpotterLive($this->db);
861
			    $SpotterLive->deleteLiveSpotterDataNotUpdated();
862
			    $SpotterLive->db = null;
863
			    //SpotterLive->deleteLiveSpotterData();
864
			    if ($globalDebug) echo " Done\n";
865
			    $this->last_delete_hourly = time();
0 ignored issues
show
Documentation Bug introduced by
The property $last_delete_hourly was declared of type string, but time() is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
866
			}
867
			
868
		    }
869
		    $ignoreImport = false;
0 ignored issues
show
Unused Code introduced by
$ignoreImport 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...
870
		}
871
		//if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN);
872
		if ($send) return $this->all_flights[$id];
873
	    }
874
	}
875
    }
876
}
877
?>
878