Completed
Push — master ( 912bf6...fe6015 )
by Yannick
05:58
created

Schedule::getFlightMapper()   D

Complexity

Conditions 9
Paths 24

Size

Total Lines 37
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 29
nc 24
nop 2
dl 0
loc 37
rs 4.909
c 0
b 0
f 0
1
<?php
2
require_once(dirname(__FILE__).'/libs/simple_html_dom.php');
3
require_once(dirname(__FILE__).'/settings.php');
4
require_once(dirname(__FILE__).'/class.Connection.php');
5
require_once(dirname(__FILE__).'/class.Translation.php');
6
require_once(dirname(__FILE__).'/class.Common.php');
7
require_once(dirname(__FILE__).'/libs/uagent/uagent.php');
8
9
class Schedule {
10
	protected $cookies = array();
11
        public $db;
12
	public function __construct($dbc = null) {
13
		$Connection = new Connection($dbc);
14
		$this->db = $Connection->db();
15
        }
16
	
17
	/**
18
	* Add schedule data to database
19
	* @param String $ident aircraft ident
20
	* @param String $departure_airport_icao departure airport icao
21
	* @param String $departure_airport_time departure airport time
22
	* @param String $arrival_airport_icao arrival airport icao
23
	* @param String $arrival_airport_time arrival airport time
24
	/ @param String $source source of data
25
	*/
26
	
27
	public function addSchedule($ident,$departure_airport_icao,$departure_airport_time,$arrival_airport_icao,$arrival_airport_time,$source = 'website') {
28
		date_default_timezone_set('UTC');
29
		$date = date("Y-m-d H:i:s",time());
30
	        //if ($departure_airport_time == '' && $arrival_airport_time == '') exit;
31
	        //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident";
32
	        $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident";
33
	        $query_values = array(':ident' => $ident);
34
		 try {
35
			$sth = $this->db->prepare($query);
36
			$sth->execute($query_values);
37
		} catch(PDOException $e) {
38
			return "error : ".$e->getMessage();
39
		}
40
		if ($sth->fetchColumn() > 0) {
41
			if ($departure_airport_time == '' && $arrival_airport_time == '') {
42
			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao";
43
			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao);
44
			} elseif ($arrival_airport_time == '') {
45
			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao";
46
			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao);
47
			} elseif ($departure_airport_time == '') {
48
			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
49
			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
50
			} else {
51
			    //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time";
52
			    $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time";
53
			    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time);
54
			}
55
			try {
56
				$sth = $this->db->prepare($query);
57
				$sth->execute($query_values);
58
			} catch(PDOException $e) {
59
				return "error : ".$e->getMessage();
60
			}
61
			if ($sth->fetchColumn() == 0) {
62
				//$query = 'UPDATE schedule SET departure_airport_icao = :departure_airport_icao, departure_airport_time = :departure_airport_time, arrival_airport_icao = :arrival_airport_icao, arrival_airport_time = :arrival_airport_time, date_modified = :date, source = :source WHERE ident = :ident';
63
				if ($departure_airport_time == '' && $arrival_airport_time == '') {
64
                            	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
65
				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
66
				} elseif ($arrival_airport_time == '') {
67
                            	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident';
68
				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source);
69
				} elseif ($departure_airport_time == '') {
70
                            	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
71
				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
72
				} else {
73
                            	    $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident';
74
				    $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
75
				}
76
				 try {
77
					$sth = $this->db->prepare($query);
78
					$sth->execute($query_values);
79
				} catch(PDOException $e) {
80
					return "error : ".$e->getMessage();
81
				}
82
			} else {
83
				//$query = 'UPDATE schedule SET date_lastseen = :date WHERE ident = :ident';
84
				$query = 'UPDATE routes SET date_lastseen = :date WHERE CallSign = :ident';
85
				$query_values = array(':ident' => $ident,':date' => $date);
86
				 try {
87
					$sth = $this->db->prepare($query);
88
					$sth->execute($query_values);
89
				} catch(PDOException $e) {
90
					return "error : ".$e->getMessage();
91
				}
92
			}
93
		} else {
94
			$query = 'INSERT INTO  routes (CallSign,FromAirport_ICAO, FromAirport_Time, ToAirport_ICAO, ToAirport_Time,date_added,source)  VALUES (:ident,:departure_airport_icao,:departure_airport_time,:arrival_airport_icao,:arrival_airport_time,:date,:source)';
95
			$query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source);
96
			 try {
97
				$sth = $this->db->prepare($query);
98
				$sth->execute($query_values);
99
			} catch(PDOException $e) {
100
				return "error : ".$e->getMessage();
101
			}
102
		}
103
        
104
	}
105
106
	public function getSchedule($ident) {
107
	        $Translation = new Translation($this->db);
108
	        $operator = $Translation->checkTranslation($ident,false);
109
	        if ($ident != $operator) {
110
	    		$query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :operator OR CallSign = :ident LIMIT 1";
111
	    		$query_values = array(':ident' => $ident,'operator' => $operator);
112
	    	} else {
113
		        $query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :ident LIMIT 1";
114
	    		$query_values = array(':ident' => $ident);
115
	    	}
116
		 try {
117
			$sth = $this->db->prepare($query);
118
			$sth->execute($query_values);
119
		} catch(PDOException $e) {
120
			return "error : ".$e->getMessage();
121
		}
122
		$row = $sth->fetch(PDO::FETCH_ASSOC);
123
		if (count($row) > 0) {
124
			return $row;
125
		} else return array();
126
	}
127
128
	public function checkSchedule($ident) {
129
		global $globalDBdriver;
130
	        //$query = "SELECT COUNT(*) as nb FROM schedule WHERE ident = :ident AND date_added > DATE_SUB(CURDATE(), INTERVAL 8 DAY) - 8 LIMIT 1";
131
	        if ($globalDBdriver == 'mysql') {
132
			$query = "SELECT COUNT(*) as nb FROM routes WHERE CallSign = :ident AND ((date_added BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)) AND DATE(NOW()) and date_modified IS NULL) OR (date_modified BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 15 DAY)) AND DATE(NOW()))) LIMIT 1";
133
		} else {
134
			$query = "SELECT COUNT(*) as nb FROM routes WHERE CallSign = :ident 
135
			AND ((date_added::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '1 MONTH' AND CURRENT_TIMESTAMP) and date_modified::timestamp IS NULL)
136
			     OR (date_modified::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '1 MONTH' AND CURRENT_TIMESTAMP) LIMIT 1";
137
		}
138
	        $query_values = array(':ident' => $ident);
139
		 try {
140
			$sth = $this->db->prepare($query);
141
			$sth->execute($query_values);
142
		} catch(PDOException $e) {
143
			return "error : ".$e->getMessage();
144
		}
145
		$row = $sth->fetch(PDO::FETCH_ASSOC);
146
		return $row['nb'];
147
	}
148
149
	/**
150
	* Get flight info from Air France
151
	* @param String $callsign The callsign
152
	* @param String $date date we want flight number info
153
	* @param String $carrier IATA code
154
	* @return Flight departure and arrival airports and time
155
	*/
156
	private function getAirFrance($callsign, $date = 'NOW',$carrier = 'AF') {
157
		$Common = new Common();
158
		$check_date = new Datetime($date);
159
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
160
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
161
		$url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym');
162
		$json = $Common->getData($url);
163
	
164
		$parsed_json = json_decode($json);
165
		if (property_exists($parsed_json,'errors') === false) {
166
			//$originLong = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originLong'};
167
			$originShort = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originShort'};
168
			//$departureDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'departureDateMedium'};
169
			$departureTime = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'departureTime'};
170
			//$destinationLong = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'destinationLong'};
171
			$destinationShort = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'destinationShort'};
172
			//$arrivalDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalDateMedium'};
173
			$arrivalTime = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalTime'};
174
175
			preg_match('/\((.*?)\)/',$originShort,$originiata);
176
			$DepartureAirportIata = $originiata[1];
177
			preg_match('/\((.*?)\)/',$destinationShort,$destinationiata);
178
			$ArrivalAirportIata = $destinationiata[1];
179
180
			/*
181
			date_default_timezone_set('Europe/Paris');
182
			$departureTime = gmdate('H:i',strtotime($departureTime));
183
			$arrivalTime = gmdate('H:i',strtotime($arrivalTime));
184
			*/
185
		
186
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance');
187
		} else return array();
188
	}
189
190
	/**
191
	* Get flight info from EasyJet
192
	* @param String $callsign The callsign
193
	* @param String $date date we want flight number info
194
	* @return Flight departure and arrival airports and time
195
	*/
196
	private function getEasyJet($callsign, $date = 'NOW') {
197
		global $globalTimezone;
198
		$Common = new Common();
199
		date_default_timezone_set($globalTimezone);
200
		$check_date = new Datetime($date);
201
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
202
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
203
		$url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign;
204
		$json = $Common->getData($url);
205
		$parsed_json = json_decode($json);
206
207
		$flights = $parsed_json->{'flights'};
208
		if (count($flights) > 0) {
209
			$DepartureAirportIata = $parsed_json->{'flights'}[0]->{'airports'}->{'pda'}->{'iata'}; //name
210
			$ArrivalAirportIata = $parsed_json->{'flights'}[0]->{'airports'}->{'paa'}->{'iata'}; //name
211
			$departureTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fstd'};
212
			$arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'};
213
214
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet');
215
		} else return array();
216
	}
217
218
	/**
219
	* Get flight info from Ryanair
220
	* @param String $callsign The callsign
221
	* @return Flight departure and arrival airports and time
222
	*/
223
	private function getRyanair($callsign) {
224
		$Common = new Common();
225
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
226
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
227
		$url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/";
228
		$post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}';
229
		$headers = array('Content-Type: application/json','Content-Length: ' . strlen($post));
230
		$json = $Common->getData($url,'post',$post,$headers);
231
		$parsed_json = json_decode($json);
232
		if (isset($parsed_json->{'flightInfo'})) {
233
			$flights = $parsed_json->{'flightInfo'};
234
			if (count($flights) > 0) {
235
				$DepartureAirportIata = $parsed_json->{'flightInfo'}[0]->{'departureAirport'}->{'iata'}; //name
236
				$ArrivalAirportIata = $parsed_json->{'flightInfo'}[0]->{'arrivalAirport'}->{'iata'}; //name
237
				$departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'};
238
				$arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'};
239
				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair');
240
			} else return array();
241
		} else return array();
242
	}
243
244
	/**
245
	* Get flight info from Swiss
246
	* @param String $callsign The callsign
247
	* @return Flight departure and arrival airports and time
248
	*/
249
	private function getSwiss($callsign) {
250
		$Common = new Common();
251
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
252
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
253
		$url = "http://www.world-of-swiss.com/fr/routenetwork.json";
254
		$json = $Common->getData($url);
255
		$parsed_json = json_decode($json);
256
257
258
		$flights = $parsed_json->{'flights'};
259
		if (count($flights) > 0) {
260
			$departureTIme = '';
0 ignored issues
show
Unused Code introduced by
$departureTIme 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...
261
			$arrivalTime = '';
262
			foreach ($flights as $flight) {
263
				if ($flight->{'no'} == "Vol LX ".$numvol) {
264
					$DepartureAirportIata = $flight->{'from'}->{'code'}; //city
265
					$ArrivalAirportIata = $flight->{'to'}->{'code'}; //city
266
					$departureTime = substr($flight->{'from'}->{'hour'},0,5);
267
					$arrivalTime = substr($flight->{'to'}->{'hour'},0,5);
268
				}
269
			}
270
			if (isset($DepartureAirportIata) && isset($ArrivalAirportIata)) {
271
				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss');
0 ignored issues
show
Bug introduced by
The variable $departureTime does not seem to be defined for all execution paths leading up to this point.

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
272
			} else return array();
273
		} else return array();
274
	}
275
	
276
	/**
277
	* Get flight info from British Airways API
278
	* @param String $callsign The callsign
279
	* @param String $date date we want flight number info
280
	* @return Flight departure and arrival airports and time
281
	*/
282
	public function getBritishAirways($callsign, $date = 'NOW') {
283
		global $globalBritishAirwaysKey;
284
		$Common = new Common();
285
		$check_date = new Datetime($date);
286
		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
287
		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
288
		if ($globalBritishAirwaysKey == '') return array();
289
		$url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json";
290
		$headers = array('Client-Key: '.$globalBritishAirwaysKey);
291
		$json = $Common->getData($url,'get','',$headers);
292
		if ($json == '') return array();
293
		$parsed_json = json_decode($json);
294
		$flights = $parsed_json->{'FlightsResponse'};
295
		if (count($flights) > 0) {
296
			$DepartureAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'DepartureAirport'};
297
			$ArrivalAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ArrivalAirport'};
298
			$departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
299
			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
300
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways');
301
		} else return array();
302
	}
303
304
	/**
305
	* Get flight info from Lutfhansa API
306
	* @param String $callsign The callsign
307
	* @param String $date date we want flight number info
308
	* @return Flight departure and arrival airports and time
309
	*/
310
	public function getLufthansa($callsign, $date = 'NOW') {
311
		global $globalLufthansaKey;
312
		$Common = new Common();
313
		$check_date = new Datetime($date);
314
		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
315
		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
316
		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array();
317
		$url = "https://api.lufthansa.com/v1/oauth/token";
318
		$post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials');
319
		$data = $Common->getData($url,'post',$post);
1 ignored issue
show
Documentation introduced by
$post is of type array<string,?,{"client_..."grant_type":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
320
		$parsed_data = json_decode($data);
321
		if (!isset($parsed_data->{'access_token'})) return array();
322
		$token = $parsed_data->{'access_token'};
323
		
324
		$url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d');
325
		$headers = array('Authorization: Bearer '.$token,'Accept: application/json');
326
		$json = $Common->getData($url,'get','',$headers);
327
		if ($json == '') return array();
328
		$parsed_json = json_decode($json);
329
		if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) {
330
			$DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'};
331
			$departureTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'}));
332
			$ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'};
333
			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
334
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa');
335
		} else return array();
336
	}
337
338
	/**
339
	* Get flight info from Transavia API
340
	* @param String $callsign The callsign
341
	* @param String $date date we want flight number info
342
	* @return Flight departure and arrival airports and time
343
	*/
344
	public function getTransavia($callsign, $date = 'NOW') {
345
		global $globalTransaviaKey;
346
		$Common = new Common();
347
		$check_date = new Datetime($date);
348
		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
349
		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
350
		if ($globalTransaviaKey == '') return array();
351
		$url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
352
		//$url = "https://api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
353
		$headers = array('apikey: '.$globalTransaviaKey);
354
		$json = $Common->getData($url,'get','',$headers);
355
		//echo 'result : '.$json;
356
		if ($json == '') return array();
357
		$parsed_json = json_decode($json);
358
		
359
		if (isset($parsed_json->{'data'}[0])) {
360
			$DepartureAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'departureAirport'}->{'locationCode'};
361
			$departureTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'}));
362
			$ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'};
363
			$arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
364
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia');
365
		} else return array();
366
	}
367
368
	/**
369
	* Get flight info from Tunisair
370
	* @param String $callsign The callsign
371
	* @return Flight departure and arrival airports and time
372
	*/
373
	public function getTunisair($callsign) {
374
		$Common = new Common();
375
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
376
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
377
		$url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp";
378
		$data = $Common->getData($url);
379
		$table = $Common->table2array($data);
380
		foreach ($table as $flight) {
381
			if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d',$numvol)) {
382
				return array('DepartureAirportIATA' => $flight[2],'DepartureTime' => str_replace('.',':',$flight[5]),'ArrivalAirportIATA' => $flight[3],'ArrivalTime' => str_replace('.',':',$flight[6]),'Source' => 'website_tunisair');
383
			}
384
		}
385
		return array();
386
	}
387
388
	/**
389
	* Get flight info from Vueling
390
	* @param String $callsign The callsign
391
	* @return Flight departure and arrival airports and time
392
	*/
393
	public function getVueling($callsign,$date = 'NOW') {
394
		$Common = new Common();
395
		$check_date = new Datetime($date);
396
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
397
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
398
		$final_date = str_replace('/','%2F',$check_date->format('d/m/Y'));
399
		$url = "http://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=FlightStatusResult&searchBy=bycode&date=".$final_date."&flightNumber=".$numvol."&idioma=en-GB";
400
		$data = $Common->getData($url);
401
		$data=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$data));
402
		if ($data != '') {
403
			preg_match('/flightOri=[A-Z]{3}/',$data,$result);
404
			$DepartureAirportIata = str_replace('flightOri=','',$result[0]);
405
			preg_match('/flightDest=[A-Z]{3}/',$data,$result);
406
			$ArrivalAirportIata = str_replace('flightDest=','',$result[0]);
407
			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
408
			else return array();
409
		}
410
		return array();
411
	}
412
413
	/**
414
	* Get flight info from Iberia
415
	* @param String $callsign The callsign
416
	* @param String $date date we want flight number info
417
	* @return Flight departure and arrival airports and time
418
	*/
419
	public function getIberia($callsign, $date = 'NOW') {
420
		$Common = new Common();
421
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
422
		$check_date = new Datetime($date);
423
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
424
		$url = "https://www.iberia.com/web/flightDetail.do";
425
		$post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB');
426
		$data = $Common->getData($url,'post',$post);
1 ignored issue
show
Documentation introduced by
$post is of type array<string,string,{"nu...,"airlineID":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
427
		if ($data != '') {
428
			$table = $Common->table2array($data);
429
			//print_r($table);
430
			if (count($table) > 0) {
431
				$flight = $table;
432
				preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
433
				preg_match('/([A-Z]{3})/',$flight[5][0],$ArrivalAirportIataMatch);
434
				$DepartureAirportIata = $DepartureAirportIataMatch[0];
435
				$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
436
				$departureTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[3][2]))),0,5);
437
				$arrivalTime = trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][1])));
438
				if ($arrivalTime == 'Hora estimada de llegada') {
439
					$arrivalTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][2]))),0,5);
440
				} else $arrivalTime = substr($arrivalTime,0,5);
441
				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia');
442
			}
443
		}
444
		return array();
445
	}
446
447
	/**
448
	* Get flight info from Star Alliance
449
	* @param String $callsign The callsign
450
	* @param String $date date we want flight number info
451
	* @return Flight departure and arrival airports and time
452
	*/
453
454
	private function getStarAlliance($callsign, $date = 'NOW',$carrier = '') {
1 ignored issue
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
455
		$Common = new Common();
456
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
457
		$check_date = new Datetime($date);
458
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
459
		$url = "http://www.staralliance.com/flifoQueryAction.do?myAirline=&airlineCode=".$carrier."&flightNo=".$numvol."&day=".$check_date->format('d')."&month=".$check_date->format('m')."&year=".$check_date->format('Y')."&departuredate=".$check_date->format('d-M-Y');
460
		$data = $Common->getData($url);
461
		if ($data != '') {
462
			$table = $Common->table2array($data);
463
			if (count($table) > 0) {
464
				$flight = $table;
465
				//print_r($table);
466
				if (isset($flight[25]) && isset($flight[29])) {
467
					preg_match('/([A-Z]{3})/',$flight[25][1],$DepartureAirportIataMatch);
468
					preg_match('/([A-Z]{3})/',$flight[25][3],$ArrivalAirportIataMatch);
469
					$DepartureAirportIata = $DepartureAirportIataMatch[0];
470
					$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
471
					$departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5);
472
					$arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5);
473
					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance');
474
				} else return array();
475
			}
476
			
477
478
		}
479
		return array();
480
	}
481
482
483
	/**
484
	* Get flight info from Alitalia
485
	* @param String $callsign The callsign
486
	* @param String $date date we want flight number info
487
	* @return Flight departure and arrival airports and time
488
	*/
489
	private function getAlitalia($callsign, $date = 'NOW') {
490
		$Common = new Common();
491
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
492
		$check_date = new Datetime($date);
493
		$url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
494
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
495
		$data = $Common->getData($url);
496
		if ($data != '') {
497
			$table = $Common->text2array($data);
498
			$DepartureAirportIata = '';
499
			$ArrivalAirportIata = '';
500
			$departureTime = $table[4];
501
			$arrivalTime = $table[5];
502
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_alitalia');
503
		}
504
	}
505
506
	/**
507
	* Get flight info from Brussels airlines
508
	* @param String $callsign The callsign
509
	* @param String $date date we want flight number info
510
	* @return Flight departure and arrival airports and time
511
	*/
512
	private function getBrussels($callsign, $date = 'NOW') {
513
		$Common = new Common();
514
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
515
		$check_date = new Datetime($date);
516
		$url= "http://www.brusselsairlines.com/api/flightstatus/getresults?from=NA&to=NA&date=".$check_date->format('d/m/Y')."&hour=NA&lookup=flightnumber&flightnumber=".$numvol."&publicationID=302";
517
		//http://www.brusselsairlines.com/fr-fr/informations-pratiques/statut-de-votre-vol/resultat.aspx?flightnumber=".$numvol."&date=".$check_date->format('d/m/Y')."&lookup=flightnumber";
518
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
519
		$data = $Common->getData($url);
520
		if ($data != '') {
521
		    //echo $data;
522
		    $parsed_json = json_decode($data);
523
		    if (isset($parsed_json[0]->FromAirportCode)) {
524
			$DepartureAirportIata = $parsed_json[0]->FromAirportCode;
525
			$ArrivalAirportIata = $parsed_json[0]->ToAirportCode;
526
			$departureTime = date('H:i',strtotime($parsed_json[0]->ScheduledDepatureDate));
527
			$arrivalTime = date('H:i',strtotime($parsed_json[0]->ScheduledArrivalDate));
528
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_brussels');
529
		    }
530
		}
531
	}
532
533
	/**
534
	* Get flight info from FlightRadar24
535
	* @param String $callsign The callsign
536
	* @param String $date date we want flight number info
537
	* @return Flight departure and arrival airports and time
538
	*/
539
/*
540
	public function getFlightRadar24($callsign, $date = 'NOW') {
541
		$Common = new Common();
542
		$url= "http://arn.data.fr24.com/zones/fcgi/feed.js?flight=".$callsign;
543
		$data = $Common->getData($url);
544
		if ($data != '') {
545
			$parsed_json = get_object_vars(json_decode($data));
546
			if (count($parsed_json) > 2) {
547
				$info = array_splice($parsed_json,2,1);
548
				$fr24id = current(array_keys($info));
549
				$urldata = "http://krk.data.fr24.com/_external/planedata_json.1.4.php?f=".$fr24id;
550
				$datapl = $Common->getData($urldata);
551
				if ($datapl != '') {
552
					$parsed_jsonpl = json_decode($datapl);
553
					if (isset($parsed_jsonpl->from_iata)) {
554
						$DepartureAirportIata = $parsed_jsonpl->from_iata;
555
						$ArrivalAirportIata = $parsed_jsonpl->to_iata;
556
						$departureTime = date('H:i',$parsed_jsonpl->dep_schd);
557
						$arrivalTime = date('H:i',$parsed_jsonpl->arr_schd);
558
						return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightradar24');
559
					}
560
				}
561
			}
562
		}
563
		return array();
564
	}
565
  */
566
	/**
567
	* Get flight info from Lufthansa
568
	* @param String $callsign The callsign
569
	* @param String $date date we want flight number info
570
	* @return Flight departure and arrival airports and time
571
	*/
572
573
/*	private function getLufthansa($callsign, $date = 'NOW') {
574
		$Common = new Common();
575
		*/
576
		//$numvol = preg_replace('/^[A-Z]*/','',$callsign);
577
/*
578
		$url= "http://www.lufthansa.com/fr/fr/Arrivees-Departs-fonction";
579
		$check_date = new Datetime($date);
580
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
581
582
		$post = array('flightNumber' => $numvol, 'date' => $check_date->format('Y-m-d'),'time' => '12:00','timezoneOffset' => '0','selection' => '0','arrivalDeparture' => 'D');
583
		$data = $Common->getData($url,'post',$post);
584
		if ($data != '') {
585
			$table = $Common->table2array($data);
586
			$departureTime = trim(str_replace($check_date->format('d.m.Y'),'',$table[25][3]));
587
		}
588
589
		$post = array('flightNumber' => $numvol, 'date' => $check_date->format('Y-m-d'),'time' => '12:00','timezoneOffset' => '0','selection' => '0','arrivalDeparture' => 'A');
590
		$data = $Common->getData($url,'post',$post);
591
		if ($data != '') {
592
			$table = $Common->table2array($data);
593
			$arrivalTime = trim(str_replace($check_date->format('d.m.Y'),'',$table[25][3]));
594
		}
595
		return array('DepartureAirportIATA' => '','DepartureTime' => $departureTime,'ArrivalAirportIATA' => '','ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa');
596
	}
597
  */
598
	/**
599
	* Get flight info from flytap
600
	* @param String $callsign The callsign
601
	* @param String $date date we want flight number info
602
	* @return Flight departure and arrival airports and time
603
	*/
604
	private function getFlyTap($callsign, $date = 'NOW') {
1 ignored issue
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
Unused Code introduced by
The parameter $date 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...
605
		$Common = new Common();
606
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
607
		$url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
608
		//$check_date = new Datetime($date);
609
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
610
		$post = array('arrivalsdepartures_content' => 'number','arrivalsdepartures_tp' => $numvol,'arrivalsdepartures_trk' => 'ARR','arrivalsdepartures_date_trk' => '1','aptCode' => '','arrivalsdepartures' => 'DEP','arrivalsdepartures_date' => '1','aptCodeFrom' => '','aptCodeTo' => '','arrivalsdepartures2' => 'DEP','arrivalsdepartures_date2' => '1');
611
		$data = $Common->getData($url,'post',$post);
0 ignored issues
show
Documentation introduced by
$post is of type array<string,string,{"ar...tures_date2":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
612
		if ($data != '') {
613
			$table = $Common->table2array($data);
614
			$departureTime = trim(substr($table[15][0],0,5));
615
			$arrivalTime = trim(substr($table[35][0],0,5));
616
			preg_match('/([A-Z]{3})/',$table[11][0],$DepartureAirportIataMatch);
617
			preg_match('/([A-Z]{3})/',$table[31][0],$ArrivalAirportIataMatch);
618
			$DepartureAirportIata = $DepartureAirportIataMatch[0];
619
			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
620
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flytap');
621
		}
622
		return array();
623
	}
624
625
	/**
626
	* Get flight info from flightmapper
627
	* @param String $callsign The callsign
628
	* @param String $date date we want flight number info
629
	* @return Flight departure and arrival airports and time
630
	*/
631
	public function getFlightMapper($callsign, $date = 'NOW') {
0 ignored issues
show
Unused Code introduced by
The parameter $date 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...
632
		$Common = new Common();
633
		$airline_icao = '';
634
		if (!is_numeric(substr($callsign, 0, 3)))
635
		{
636
			if (is_numeric(substr(substr($callsign, 0, 3), -1, 1))) {
637
				$airline_icao = substr($callsign, 0, 2);
638
			} elseif (is_numeric(substr(substr($callsign, 0, 4), -1, 1))) {
639
				$airline_icao = substr($callsign, 0, 3);
640
			} 
641
		}
642
		if ($airline_icao == '') return array();
643
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
644
		$url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
645
		//$check_date = new Datetime($date);
646
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
647
		$data = $Common->getData($url);
648
		if ($data != '') {
649
			$table = $Common->table2array($data);
650
			if (isset($table[5][0])) {
651
				$sched = $table[5][0];
652
				$dhour = '';
653
				$darr = '';
654
				$ahour = '';
655
				$aarr = '';
656
				$n = sscanf($sched,'%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])',$dhour,$darr,$ahour,$aarr);
657
				if ($n == 7) {
658
				    $departureTime = $dhour;
659
				    $arrivalTime = $ahour;
660
				    $DepartureAirportIata = str_replace(array('(',')'),'',$darr);
661
				    $ArrivalAirportIata = str_replace(array('(',')'),'',$aarr);
662
				    return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper');
663
				}
664
			}
665
		}
666
		return array();
667
	}
668
669
	/**
670
	* Get flight info from flightaware
671
	* @param String $callsign The callsign
672
	* @param String $date date we want flight number info
673
	* @return Flight departure and arrival airports and time
674
	*/
675
	public function getFlightAware($callsign, $date = 'NOW') {
0 ignored issues
show
Unused Code introduced by
The parameter $date 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...
676
		$Common = new Common();
677
		/*
678
		if (!is_numeric(substr($callsign, 0, 3)))
679
		{
680
			if (is_numeric(substr(substr($callsign, 0, 3), -1, 1))) {
681
				$airline_icao = substr($callsign, 0, 2);
682
			} elseif (is_numeric(substr(substr($callsign, 0, 4), -1, 1))) {
683
				$airline_icao = substr($callsign, 0, 3);
684
			} 
685
		}
686
		*/
687
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
688
		$url= "http://fr.flightaware.com/live/flight/".$callsign;
689
		//$check_date = new Datetime($date);
690
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
691
		$data = $Common->getData($url);
692
		if ($data != '') {
693
			$table = $Common->table2array($data);
694
			if (isset($table[11][0])) {
695
				$departureTime = str_replace('h',':',substr($table[5][0],0,5));
696
				$arrivalTime = str_replace('h',':',substr($table[5][1],0,5));
697
				echo $table[3][0];
698
				sscanf($table[3][0],'%*[^(] (%3[A-Z] / %*4[A-Z])',$DepartureAirportIata);
699
				sscanf($table[3][1],'%*[^(] (%3[A-Z] / %*4[A-Z])',$ArrivalAirportIata);
700
				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightaware');
701
			}
702
		}
703
		return array();
704
	}
705
706
	/**
707
	* Get flight info from CostToTravel
708
	* @param String $callsign The callsign
709
	* @param String $date date we want flight number info
710
	* @return Flight departure and arrival airports and time
711
	*/
712
	public function getCostToTravel($callsign, $date = 'NOW') {
0 ignored issues
show
Unused Code introduced by
The parameter $date 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...
713
		$Common = new Common();
714
		$url= "http://www.costtotravel.com/flight-number/".$callsign;
715
		//$check_date = new Datetime($date);
716
		//if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
717
		$data = $Common->getData($url);
718
		if ($data != '') {
719
			$table = $Common->table2array($data);
720
			//print_r($table);
721
			if (isset($table[11][1])) {
722
				$departureTime = substr($table[11][1],0,5);
723
				$arrivalTime = substr($table[17][1],0,5);
724
				$DepartureAirportIata = substr($table[13][1],0,3);
725
				$ArrivalAirportIata = substr($table[15][1],0,3);
726
				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_costtotravel');
727
			}
728
		}
729
		return array();
730
	}
731
732
	/**
733
	* Get flight info from Air Canada
734
	* @param String $callsign The callsign
735
	* @param String $date date we want flight number info
736
	* @return Flight departure and arrival airports and time
737
	*/
738
	private function getAirCanada($callsign,$date = 'NOW') {
739
		$Common = new Common();
740
		date_default_timezone_set('UTC');
741
		$check_date = new Datetime($date);
742
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
743
		$url= "http://services.aircanada.com/portal/rest/getFlightsByFlightNumber?forceTimetable=true&flightNumber=".$numvol."&carrierCode=AC&date=".$check_date->format('m-d-Y')."&app_key=AE919FDCC80311DF9BABC975DFD72085&cache=74249";
744
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
745
		$data = $Common->getData($url);
746
		$dom = new DomDocument();
747
		$dom->loadXML($data);
748
		if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) return array();
749
		$departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0);
750
		if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) {
751
			$DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
752
			$departureTime = date('H:i',strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
753
			$arrival = $dom->getElementsByTagName('ArrivalStationInfo')->item(0);
754
			$ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
755
			$arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
756
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada');
757
		} else return array();
758
	}
759
760
	/**
761
	* Get flight info from Vietnam Airlines
762
	* @param String $callsign The callsign
763
	* @param String $date date we want flight number info
764
	* @return Flight departure and arrival airports and time
765
	*/
766
	private function getVietnamAirlines($callsign, $date = 'NOW') {
767
		$Common = new Common();
768
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
769
		$check_date = new Datetime($date);
770
		$url= "https://cat.sabresonicweb.com/SSWVN/meridia?posid=VNVN&page=flifoFlightInfoDetailsMessage_learn&action=flightInfoDetails&airline=VN&language=fr&depDay=".$check_date->format('j')."&depMonth=".strtoupper($check_date->format('M'))."&=&flight=".$numvol."&";
771
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
772
		$data = $Common->getData($url);
773
		if ($data != '') {
774
			$table = $Common->table2array($data);
775
			$flight = $table;
776
			preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
777
			preg_match('/([A-Z]{3})/',$flight[21][0],$ArrivalAirportIataMatch);
778
			$DepartureAirportIata = $DepartureAirportIataMatch[0];
779
			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
780
			$departureTime = $flight[5][1];
781
			$arrivalTime = $flight[23][1];
782
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_vietnamairlines');
783
		}
784
	}
785
786
	/**
787
	* Get flight info from Air Berlin
788
	* @param String $callsign The callsign
789
	* @param String $date date we want flight number info
790
	* @param String $carrier IATA code
0 ignored issues
show
Bug introduced by
There is no parameter named $carrier. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
791
	* @return Flight departure and arrival airports and time
792
	*/
793
	private function getAirBerlin($callsign, $date = 'NOW') {
794
		$Common = new Common();
795
		date_default_timezone_set('UTC');
796
		//AB = airberlin, HG/NLY = NIKI, 4T/BHP = Belair 
797
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
798
		$check_date = new Datetime($date);
799
		$url= "http://www.airberlin.com/en-US/site/aims.php";
800
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
801
		$post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
802
		$data = $Common->getData($url,'post',$post);
1 ignored issue
show
Documentation introduced by
$post is of type array<string,string,{"ty...g","carrier":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
803
		//echo $data;
804
		$DepartureAirportIata = '';
805
		$ArrivalAirportIata = '';
806
		
807
		if ($data != '') {
808
			$table = $Common->table2array($data);
809
			$flight = $table;
810
			if (isset($flight[5][4])) $departureTime = $flight[5][4];
811
			else $departureTime = '';
812
			if (isset($flight[5][2])) $departureAirport = $flight[5][2];
813
			else $departureAirport = '';
814
		} else return array();
815
		$post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
816
		$data = $Common->getData($url,'post',$post);
1 ignored issue
show
Documentation introduced by
$post is of type array<string,string,{"ty...g","carrier":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
817
		if ($data != '') {
818
			$table = $Common->table2array($data);
819
			$flight = $table;
820
			if (isset($flight[5][4])) {
821
			    $arrivalTime = $flight[5][4];
822
			    $arrivalAirport = $flight[5][3];
823
			} else {
824
			    $arrivalTime = '';
825
			    $arrivalAirport = '';
826
			}
827
		} else return array();
828
		$url = 'http://www.airberlin.com/en-US/site/json/suggestAirport.php?searchfor=departures&searchflightid=0&departures%5B%5D=&suggestsource%5B0%5D=activeairports&withcountries=0&withoutroutings=0&promotion%5Bid%5D=&promotion%5Btype%5D=&routesource%5B0%5D=airberlin&routesource%5B1%5D=partner';
829
		$json = $Common->getData($url);
830
		if ($json == '') return array();
831
		$parsed_json = json_decode($json);
832
		$airports = $parsed_json->{'suggestList'};
833
		if (count($airports) > 0) {
834
			foreach ($airports as $airinfo) {
835
				if ($airinfo->{'name'} == $departureAirport) {
836
					$DepartureAirportIata = $airinfo->{'code'};
837
				}
838
				if ($airinfo->{'name'} == $arrivalAirport) {
839
					$ArrivalAirportIata = $airinfo->{'code'};
840
				}
841
			}
842
		}
843
		if (isset($DepartureAirportIata)) {
844
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin');
845
		} else return array();
846
	}
847
848
849
	
850
	public function fetchSchedule($ident,$date = 'NOW') {
851
		global $globalSchedulesSources, $globalSchedulesFetch;
852
		//$Common = new Common();
853
		if (!$globalSchedulesFetch) return array();
854
		$airline_icao = '';
855
		if (!is_numeric(substr($ident, 0, 3)))
856
		{
857
			if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) {
858
				$airline_icao = substr($ident, 0, 2);
859
			} elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) {
860
				$airline_icao = substr($ident, 0, 3);
861
			} 
862
		}
863
		if ($airline_icao != '') {
864
			switch ($airline_icao) {
865
/*
866
				// Adria Airways
867
				case "ADR":
868
				case "JP":
869
					return Schedule->getStarAlliance($ident,$date,'JP');
870
					break;
871
				// Aegean Airlines
872
				case "AEE":
873
				case "A3":
874
					return Schedule->getStarAlliance($ident,$date,'A3');
875
					break;
876
				// Air Canada
877
				case "ACA":
878
				case "AC":
879
					return Schedule->getStarAlliance($ident,$date,'AC');
880
					break;
881
				// Air China
882
				case "CCA":
883
				case "CA":
884
					return Schedule->getStarAlliance($ident,$date,'CA');
885
					break;
886
				// Air India
887
				case "AIC":
888
				case "AI":
889
					return Schedule->getStarAlliance($ident,$date,'AI');
890
					break;
891
				// Air New Zealand
892
				case "ANZ":
893
				case "NZ":
894
					return Schedule->getStarAlliance($ident,$date,'NZ');
895
					break;
896
				// All Nippon Airways
897
				case "ANA":
898
				case "NH":
899
					return Schedule->getStarAlliance($ident,$date,'NH');
900
					break;
901
				// Asiana Airlines
902
				case "AAR":
903
				case "OZ":
904
					return Schedule->getStarAlliance($ident,$date,'OZ');
905
					break;
906
				// Austrian
907
				case "AUA":
908
				case "OS":
909
					return Schedule->getStarAlliance($ident,$date,'OS');
910
					break;
911
				// Avianca
912
				case "AVA":
913
				case "AV":
914
					return Schedule->getStarAlliance($ident,$date,'AV');
915
					break;
916
*/
917
				// Brussels Airlines
918
				case "BEL":
919
				case "SN":
920
					return $this->getBrussels($ident,$date);
921
/*
922
				// Copa Airlines
923
				case "CMP":
924
				case "CM":
925
					return Schedule->getStarAlliance($ident,$date,'CM');
926
					break;
927
				// Croatia Airlines
928
				case "CTN":
929
				case "OU":
930
					return Schedule->getStarAlliance($ident,$date,'OU');
931
					break;
932
				// Egyptair
933
				case "MSR":
934
				case "MS":
935
					return Schedule->getStarAlliance($ident,$date,'MS');
936
					break;
937
				// Ethiopian Airlines
938
				case "ETH":
939
				case "ET":
940
					return Schedule->getStarAlliance($ident,$date,'ET');
941
					break;
942
				// Eva Air
943
				case "EVA":
944
				case "BR":
945
					return Schedule->getStarAlliance($ident,$date,'BR');
946
					break;
947
				// LOT Polish Airlines
948
				case "LOT":
949
				case "LO":
950
					return Schedule->getStarAlliance($ident,$date,'LO');
951
					break;
952
				// Scandinavian Airlines
953
				case "SAS":
954
				case "SK":
955
					return Schedule->getStarAlliance($ident,$date,'SK');
956
					break;
957
				// Shenzhen Airlines
958
				case "CSZ":
959
				case "ZH":
960
					return Schedule->getStarAlliance($ident,$date,'ZH');
961
					break;
962
				// Singapore Airlines
963
				case "SIA":
964
				case "SQ":
965
					return Schedule->getStarAlliance($ident,$date,'SQ');
966
					break;
967
				// South African Airways
968
				case "SAA":
969
				case "SA":
970
					return Schedule->getStarAlliance($ident,$date,'SA');
971
					break;
972
*/
973
				// SWISS
974
				case "SWR":
975
				case "LX":
976
					return $this->getSwiss($ident);
977
978
				/*
979
				// TAP Portugal
980
				case "TAP":
981
				case "TP":
982
					return $this->getFlyTap($ident,$date);
983
					break;
984
				*/
985
/*
986
				// Thai Airways International
987
				case "THA":
988
				case "TG":
989
					return Schedule->getStarAlliance($ident,$date,'TG');
990
					break;
991
				// Turkish Airlines
992
				case "THY":
993
				case "TK":
994
					return Schedule->getStarAlliance($ident,$date,'TK');
995
					break;
996
				// United
997
				case "UAL":
998
				case "UA":
999
					return Schedule->getStarAlliance($ident,$date,'UA');
1000
					break;
1001
*/
1002
				// Air France
1003
				case "AF":
1004
				case "AFR":
1005
					return $this->getAirFrance($ident,$date,'AF');
1006
				// HOP
1007
				case "A5":
1008
				case "HOP":
1009
					return $this->getAirFrance($ident,$date,'A5');
1010
				// EasyJet
1011
				case "U2":
1012
				case "DS":
1013
				case "EZY":
1014
				case "EZS":
1015
					return $this->getEasyJet($ident,$date);
1016
				// Ryanair
1017
				case "FR":
1018
				case "RYR":
1019
					return $this->getRyanair($ident);
1020
				// British Airways
1021
				case "BA":
1022
				case "SHT":
1023
				case "BAW":
1024
					return $this->getBritishAirways($ident);
1025
				// Tunisair
1026
				case "TUI":
1027
				case "TAR":
1028
				case "TU":
1029
					return $this->getTunisair($ident);
1030
				// Vueling
1031
				case "VLG":
1032
				case "VY":
1033
					return $this->getVueling($ident);
1034
				// Alitalia
1035
				case "AZ":
1036
				case "AZA":
1037
					return $this->getAlitalia($ident);
1038
				// Air Canada
1039
				case "ACA":
1040
				case "AC":
1041
					return $this->getAirCanada($ident);
1042
				// Lufthansa
1043
				case "DLH":
1044
				case "LH":
1045
					return $this->getLufthansa($ident);
1046
				/*
1047
				// Transavia
1048
				case "TRA":
1049
				case "HV":
1050
					return $this->getTransavia($ident);
1051
					break;
1052
				*/
1053
/*
1054
				case "DLH":
1055
				case "LH":
1056
					return $this->getStarAlliance($ident,$date,'LH');
1057
					break;
1058
*/
1059
				// Iberia
1060
				case "IBE":
1061
				case "IB":
1062
					return $this->getIberia($ident);
1063
				// Vietnam Airlines
1064
				case "HVN":
1065
					return $this->getVietnamAirlines($ident,$date);
1066
				// Air Berlin
1067
				case "AB":
1068
				case "BER":
1069
					return $this->getAirBerlin($ident,$date,'AB');
0 ignored issues
show
Unused Code introduced by
The call to Schedule::getAirBerlin() has too many arguments starting with 'AB'.

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...
1070
				// NIKI
1071
				case "HG":
1072
				case "NLY":
1073
					return $this->getAirBerlin($ident,$date,'HG');
0 ignored issues
show
Unused Code introduced by
The call to Schedule::getAirBerlin() has too many arguments starting with 'HG'.

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...
1074
				// BelAir
1075
				case "4T":
1076
				case "BHP":
1077
					return $this->getAirBerlin($ident,$date,'4T');
0 ignored issues
show
Unused Code introduced by
The call to Schedule::getAirBerlin() has too many arguments starting with '4T'.

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...
1078
				default:
1079
					// Randomly use a generic function to get hours
1080
					if (strlen($airline_icao) == 2) {
1081
						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware');
1082
						if (count($globalSchedulesSources) > 0) {
1083
							$rand = mt_rand(0,count($globalSchedulesSources)-1);
1084
							$source = $globalSchedulesSources[$rand];
1085
							if ($source == 'flightmapper') return $this->getFlightMapper($ident,$date);
1086
							elseif ($source == 'costtotravel') return $this->getCostToTravel($ident,$date);
1087
							//elseif ($source == 'flightradar24') return $this->getFlightRadar24($ident,$date);
1088
							elseif ($source == 'flightaware') return $this->getFlightAware($ident,$date);
1089
						}
1090
					}
1091
			}
1092
		}
1093
	        return array();
1094
	}
1095
}
1096
1097
1098
//$Schedule = new Schedule();
1099
1100
//print_r($Schedule->fetchSchedule('HV5661'));
1101
//print_r($Schedule->getFlightAware('AF1179'));
1102
//print_r($Schedule->getBritishAirways('BAW551'));
1103
//print_r($Schedule->getLufthansa('LH551'));
1104
//print_r($Schedule->getTunisair('TU203'));
1105
//print_r($Schedule->getTransavia('TRA598'));
1106
1107
?>
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...