Completed
Push — master ( b3cf23...9c1d49 )
by Yannick
07:20
created

Schedule::getAlitalia()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 14
nc 3
nop 2
dl 0
loc 16
rs 9.4285
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
	function __construct($dbc = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
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);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

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

Loading history...
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);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

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

Loading history...
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 View Code Duplication
				} elseif ($arrival_airport_time == '') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
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 View Code Duplication
				} else {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
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);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

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

Loading history...
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);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

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

Loading history...
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);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

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

Loading history...
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);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

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

Loading history...
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 View Code Duplication
	public function checkSchedule($ident) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
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 15 DAY)) 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 '15 DAYS' AND CURRENT_TIMESTAMP) and date_modified::timestamp IS NULL)
136
			     OR (date_modified::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '15 DAYS' AND CURRENT_TIMESTAMP) LIMIT 1";
137
		}
138
	        $query_values = array(':ident' => $ident);
139
		 try {
140
			$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

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

Loading history...
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'};
0 ignored issues
show
Unused Code introduced by
$originLong 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...
167
			$originShort = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originShort'};
168
			$departureDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'departureDateMedium'};
0 ignored issues
show
Unused Code introduced by
$departureDateMedium 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...
169
			$departureTime = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'departureTime'};
170
			$destinationLong = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'destinationLong'};
0 ignored issues
show
Unused Code introduced by
$destinationLong 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...
171
			$destinationShort = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'destinationShort'};
172
			$arrivalDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalDateMedium'};
0 ignored issues
show
Unused Code introduced by
$arrivalDateMedium 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...
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
			foreach ($flights as $flight) {
261
				if ($flight->{'no'} == "Vol LX ".$numvol) {
262
					$DepartureAirportIata = $flight->{'from'}->{'code'}; //city
263
					$ArrivalAirportIata = $flight->{'to'}->{'code'}; //city
264
					$departureTime = substr($flight->{'from'}->{'hour'},0,5);
265
					$arrivalTime = substr($flight->{'to'}->{'hour'},0,5);
266
				}
267
			}
268 View Code Duplication
			if (isset($DepartureAirportIata)) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
269
				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...
Bug introduced by
The variable $ArrivalAirportIata 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...
Bug introduced by
The variable $arrivalTime does not seem to be defined for all execution paths leading up to this point.

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
270
			} else return array();
271
		} else return array();
272
	}
273
	
274
	/**
275
	* Get flight info from British Airways API
276
	* @param String $callsign The callsign
277
	* @param String $date date we want flight number info
278
	* @return Flight departure and arrival airports and time
279
	*/
280
	public function getBritishAirways($callsign, $date = 'NOW') {
281
		global $globalBritishAirwaysKey;
282
		$Common = new Common();
283
		$check_date = new Datetime($date);
284
		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
285
		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
286
		if ($globalBritishAirwaysKey == '') return array();
287
		$url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json";
288
		$headers = array('Client-Key: '.$globalBritishAirwaysKey);
289
		$json = $Common->getData($url,'get','',$headers);
290
		if ($json == '') return array();
291
		$parsed_json = json_decode($json);
292
		$flights = $parsed_json->{'FlightsResponse'};
293
		if (count($flights) > 0) {
294
			$DepartureAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'DepartureAirport'};
295
			$ArrivalAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ArrivalAirport'};
296
			$departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'}));
297
			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'}));
298
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways');
299
		} else return array();
300
	}
301
302
	/**
303
	* Get flight info from Lutfhansa API
304
	* @param String $callsign The callsign
305
	* @param String $date date we want flight number info
306
	* @return Flight departure and arrival airports and time
307
	*/
308
	public function getLufthansa($callsign, $date = 'NOW') {
309
		global $globalLufthansaKey;
310
		$Common = new Common();
311
		$check_date = new Datetime($date);
312
		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
313
		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
314
		if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array();
315
		$url = "https://api.lufthansa.com/v1/oauth/token";
316
		$post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials');
317
		$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...
318
		$parsed_data = json_decode($data);
319
		if (!isset($parsed_data->{'access_token'})) return array();
320
		$token = $parsed_data->{'access_token'};
321
		
322
		$url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d');
323
		$headers = array('Authorization: Bearer '.$token,'Accept: application/json');
324
		$json = $Common->getData($url,'get','',$headers);
325
		if ($json == '') return array();
326
		$parsed_json = json_decode($json);
327
		if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) {
328
			$DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'};
329
			$departureTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'}));
330
			$ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'};
331
			$arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'}));
332
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa');
333
		} else return array();
334
	}
335
336
	/**
337
	* Get flight info from Transavia API
338
	* @param String $callsign The callsign
339
	* @param String $date date we want flight number info
340
	* @return Flight departure and arrival airports and time
341
	*/
342
	public function getTransavia($callsign, $date = 'NOW') {
343
		global $globalTransaviaKey;
344
		$Common = new Common();
345
		$check_date = new Datetime($date);
346
		$numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign));
347
		if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array();
348
		if ($globalTransaviaKey == '') return array();
349
		$url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
350
		//$url = "https://api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol;
351
		$headers = array('apikey: '.$globalTransaviaKey);
352
		$json = $Common->getData($url,'get','',$headers);
353
		//echo 'result : '.$json;
354
		if ($json == '') return array();
355
		$parsed_json = json_decode($json);
356
		
357
		if (isset($parsed_json->{'data'}[0])) {
358
			$DepartureAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'departureAirport'}->{'locationCode'};
359
			$departureTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'}));
360
			$ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'};
361
			$arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
362
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia');
363
		} else return array();
364
	}
365
366
	/**
367
	* Get flight info from Tunisair
368
	* @param String $callsign The callsign
369
	* @return Flight departure and arrival airports and time
370
	*/
371
	public function getTunisair($callsign) {
372
		$Common = new Common();
373
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
374
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
375
		$url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp";
376
		$data = $Common->getData($url);
377
		$table = $Common->table2array($data);
378
		foreach ($table as $flight) {
379
			if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d',$numvol)) {
380
				return array('DepartureAirportIATA' => $flight[2],'DepartureTime' => str_replace('.',':',$flight[5]),'ArrivalAirportIATA' => $flight[3],'ArrivalTime' => str_replace('.',':',$flight[6]),'Source' => 'website_tunisair');
381
			}
382
		}
383
		return array();
384
	}
385
386
	/**
387
	* Get flight info from Vueling
388
	* @param String $callsign The callsign
389
	* @return Flight departure and arrival airports and time
390
	*/
391
	public function getVueling($callsign,$date = 'NOW') {
392
		$Common = new Common();
393
		$check_date = new Datetime($date);
394
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
395
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
396
		$final_date = str_replace('/','%2F',$check_date->format('d/m/Y'));
397
		$url = "http://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=FlightStatusResult&searchBy=bycode&date=".$final_date."&flightNumber=".$numvol."&idioma=en-GB";
398
		$data = $Common->getData($url);
399
		$data=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$data));
400
		if ($data != '') {
401
			preg_match('/flightOri=[A-Z]{3}/',$data,$result);
402
			$DepartureAirportIata = str_replace('flightOri=','',$result[0]);
403
			preg_match('/flightDest=[A-Z]{3}/',$data,$result);
404
			$ArrivalAirportIata = str_replace('flightDest=','',$result[0]);
405
			if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling');
406
			else return array();
407
		}
408
		return array();
409
	}
410
411
	/**
412
	* Get flight info from Iberia
413
	* @param String $callsign The callsign
414
	* @param String $date date we want flight number info
415
	* @return Flight departure and arrival airports and time
416
	*/
417
	public function getIberia($callsign, $date = 'NOW') {
418
		$Common = new Common();
419
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
420
		$check_date = new Datetime($date);
421
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
422
		$url = "https://www.iberia.com/web/flightDetail.do";
423
		$post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB');
424
		$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...
425
		if ($data != '') {
426
			$table = $Common->table2array($data);
427
			//print_r($table);
428
			if (count($table) > 0) {
429
				$flight = $table;
430
				preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
431
				preg_match('/([A-Z]{3})/',$flight[5][0],$ArrivalAirportIataMatch);
432
				$DepartureAirportIata = $DepartureAirportIataMatch[0];
433
				$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
434
				$departureTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[3][2]))),0,5);
435
				$arrivalTime = trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][1])));
436
				if ($arrivalTime == 'Hora estimada de llegada') {
437
					$arrivalTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][2]))),0,5);
438
				} else $arrivalTime = substr($arrivalTime,0,5);
439
				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia');
440
			}
441
		}
442
		return array();
443
	}
444
445
	/**
446
	* Get flight info from Star Alliance
447
	* @param String $callsign The callsign
448
	* @param String $date date we want flight number info
449
	* @return Flight departure and arrival airports and time
450
	*/
451
	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...
452
		$Common = new Common();
453
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
454
		$check_date = new Datetime($date);
455
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
456
		$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');
457
		$data = $Common->getData($url);
458
		if ($data != '') {
459
			$table = $Common->table2array($data);
460
			if (count($table) > 0) {
461
				$flight = $table;
462
				//print_r($table);
463
				if (isset($flight[25]) && isset($flight[29])) {
464
					preg_match('/([A-Z]{3})/',$flight[25][1],$DepartureAirportIataMatch);
465
					preg_match('/([A-Z]{3})/',$flight[25][3],$ArrivalAirportIataMatch);
466
					$DepartureAirportIata = $DepartureAirportIataMatch[0];
467
					$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
468
					$departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5);
469
					$arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5);
470
					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance');
471
				} else return array();
472
			}
473
			
474
475
		}
476
		return array();
477
	}
478
479
	/**
480
	* Get flight info from Alitalia
481
	* @param String $callsign The callsign
482
	* @param String $date date we want flight number info
483
	* @return Flight departure and arrival airports and time
484
	*/
485
	private function getAlitalia($callsign, $date = 'NOW') {
486
		$Common = new Common();
487
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
488
		$check_date = new Datetime($date);
489
		$url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
490
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
491
		$data = $Common->getData($url);
492
		if ($data != '') {
493
			$table = $Common->text2array($data);
494
			$DepartureAirportIata = '';
495
			$ArrivalAirportIata = '';
496
			$departureTime = $table[4];
497
			$arrivalTime = $table[5];
498
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_alitalia');
499
		}
500
	}
501
502
	/**
503
	* Get flight info from Brussels airlines
504
	* @param String $callsign The callsign
505
	* @param String $date date we want flight number info
506
	* @return Flight departure and arrival airports and time
507
	*/
508
	private function getBrussels($callsign, $date = 'NOW') {
509
		$Common = new Common();
510
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
511
		$check_date = new Datetime($date);
512
		$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";
513
		//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";
514
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
515
		$data = $Common->getData($url);
516
		if ($data != '') {
517
		    //echo $data;
518
		    $parsed_json = json_decode($data);
519
		    if (isset($parsed_json[0]->FromAirportCode)) {
520
			$DepartureAirportIata = $parsed_json[0]->FromAirportCode;
521
			$ArrivalAirportIata = $parsed_json[0]->ToAirportCode;
522
			$departureTime = date('H:i',strtotime($parsed_json[0]->ScheduledDepatureDate));
523
			$arrivalTime = date('H:i',strtotime($parsed_json[0]->ScheduledArrivalDate));
524
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_brussels');
525
		    }
526
		}
527
	}
528
529
	/**
530
	* Get flight info from FlightRadar24
531
	* @param String $callsign The callsign
532
	* @param String $date date we want flight number info
533
	* @return Flight departure and arrival airports and time
534
	*/
535
/*
536
	public function getFlightRadar24($callsign, $date = 'NOW') {
537
		$Common = new Common();
538
		$url= "http://arn.data.fr24.com/zones/fcgi/feed.js?flight=".$callsign;
539
		$data = $Common->getData($url);
540
		if ($data != '') {
541
			$parsed_json = get_object_vars(json_decode($data));
542
			if (count($parsed_json) > 2) {
543
				$info = array_splice($parsed_json,2,1);
544
				$fr24id = current(array_keys($info));
545
				$urldata = "http://krk.data.fr24.com/_external/planedata_json.1.4.php?f=".$fr24id;
546
				$datapl = $Common->getData($urldata);
547
				if ($datapl != '') {
548
					$parsed_jsonpl = json_decode($datapl);
549
					if (isset($parsed_jsonpl->from_iata)) {
550
						$DepartureAirportIata = $parsed_jsonpl->from_iata;
551
						$ArrivalAirportIata = $parsed_jsonpl->to_iata;
552
						$departureTime = date('H:i',$parsed_jsonpl->dep_schd);
553
						$arrivalTime = date('H:i',$parsed_jsonpl->arr_schd);
554
						return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightradar24');
555
					}
556
				}
557
			}
558
		}
559
		return array();
560
	}
561
  */
562
	/**
563
	* Get flight info from Lufthansa
564
	* @param String $callsign The callsign
565
	* @param String $date date we want flight number info
566
	* @return Flight departure and arrival airports and time
567
	*/
568
569
/*	private function getLufthansa($callsign, $date = 'NOW') {
570
		$Common = new Common();
571
		*/
572
		//$numvol = preg_replace('/^[A-Z]*/','',$callsign);
573
/*
574
		$url= "http://www.lufthansa.com/fr/fr/Arrivees-Departs-fonction";
575
		$check_date = new Datetime($date);
576
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
577
578
		$post = array('flightNumber' => $numvol, 'date' => $check_date->format('Y-m-d'),'time' => '12:00','timezoneOffset' => '0','selection' => '0','arrivalDeparture' => 'D');
579
		$data = $Common->getData($url,'post',$post);
580
		if ($data != '') {
581
			$table = $Common->table2array($data);
582
			$departureTime = trim(str_replace($check_date->format('d.m.Y'),'',$table[25][3]));
583
		}
584
585
		$post = array('flightNumber' => $numvol, 'date' => $check_date->format('Y-m-d'),'time' => '12:00','timezoneOffset' => '0','selection' => '0','arrivalDeparture' => 'A');
586
		$data = $Common->getData($url,'post',$post);
587
		if ($data != '') {
588
			$table = $Common->table2array($data);
589
			$arrivalTime = trim(str_replace($check_date->format('d.m.Y'),'',$table[25][3]));
590
		}
591
		return array('DepartureAirportIATA' => '','DepartureTime' => $departureTime,'ArrivalAirportIATA' => '','ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa');
592
	}
593
  */
594
	/**
595
	* Get flight info from flytap
596
	* @param String $callsign The callsign
597
	* @param String $date date we want flight number info
598
	* @return Flight departure and arrival airports and time
599
	*/
600
	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...
601
		$Common = new Common();
602
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
603
		$url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
604
		$check_date = new Datetime($date);
0 ignored issues
show
Unused Code introduced by
$check_date 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...
605
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
606
		$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');
607
		$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...
608
		if ($data != '') {
609
			$table = $Common->table2array($data);
610
			$departureTime = trim(substr($table[15][0],0,5));
611
			$arrivalTime = trim(substr($table[35][0],0,5));
612
			preg_match('/([A-Z]{3})/',$table[11][0],$DepartureAirportIataMatch);
613
			preg_match('/([A-Z]{3})/',$table[31][0],$ArrivalAirportIataMatch);
614
			$DepartureAirportIata = $DepartureAirportIataMatch[0];
615
			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
616
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flytap');
617
		}
618
		return array();
619
	}
620
621
	/**
622
	* Get flight info from flightmapper
623
	* @param String $callsign The callsign
624
	* @param String $date date we want flight number info
625
	* @return Flight departure and arrival airports and time
626
	*/
627
	public function getFlightMapper($callsign, $date = 'NOW') {
628
		$Common = new Common();
629 View Code Duplication
		if (!is_numeric(substr($callsign, 0, 3)))
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
630
		{
631
			if (is_numeric(substr(substr($callsign, 0, 3), -1, 1))) {
632
				$airline_icao = substr($callsign, 0, 2);
633
			} elseif (is_numeric(substr(substr($callsign, 0, 4), -1, 1))) {
634
				$airline_icao = substr($callsign, 0, 3);
635
			} 
636
		}
637
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
638
		$url= "http://info.flightmapper.net/flight/".$airline_icao.'_'.$numvol;
0 ignored issues
show
Bug introduced by
The variable $airline_icao 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...
639
		$check_date = new Datetime($date);
0 ignored issues
show
Unused Code introduced by
$check_date 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...
640
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
641
		$data = $Common->getData($url);
642
		if ($data != '') {
643
			$table = $Common->table2array($data);
644
			if (isset($table[5][0])) {
645
				$sched = $table[5][0];
646
				$n = sscanf($sched,'%*s %5[0-9:] %*[^()] (%3[A-Z]) %5[0-9:] %*[^()] (%3[A-Z])',$dhour,$darr,$ahour,$aarr);
0 ignored issues
show
Bug introduced by
The variable $darr does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $ahour does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $aarr does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
647
				if ($n == 7) {
648
				    $departureTime = $dhour;
649
				    $arrivalTime = $ahour;
650
				    $DepartureAirportIata = str_replace(array('(',')'),'',$darr);
651
				    $ArrivalAirportIata = str_replace(array('(',')'),'',$aarr);
652
				    return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper');
653
				}
654
			}
655
		}
656
		return array();
657
	}
658
659
	/**
660
	* Get flight info from flightaware
661
	* @param String $callsign The callsign
662
	* @param String $date date we want flight number info
663
	* @return Flight departure and arrival airports and time
664
	*/
665
	public function getFlightAware($callsign, $date = 'NOW') {
666
		$Common = new Common();
667 View Code Duplication
		if (!is_numeric(substr($callsign, 0, 3)))
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
668
		{
669
			if (is_numeric(substr(substr($callsign, 0, 3), -1, 1))) {
670
				$airline_icao = substr($callsign, 0, 2);
0 ignored issues
show
Unused Code introduced by
$airline_icao 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...
671
			} elseif (is_numeric(substr(substr($callsign, 0, 4), -1, 1))) {
672
				$airline_icao = substr($callsign, 0, 3);
0 ignored issues
show
Unused Code introduced by
$airline_icao 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...
673
			} 
674
		}
675
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
676
		$url= "http://fr.flightaware.com/live/flight/".$callsign;
677
		$check_date = new Datetime($date);
0 ignored issues
show
Unused Code introduced by
$check_date 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...
678
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
679
		$data = $Common->getData($url);
680
		if ($data != '') {
681
			$table = $Common->table2array($data);
682
			if (isset($table[11][0])) {
683
				$departureTime = str_replace('h',':',substr($table[5][0],0,5));
684
				$arrivalTime = str_replace('h',':',substr($table[5][1],0,5));
685
				echo $table[3][0];
686
				sscanf($table[3][0],'%*[^(] (%3[A-Z] / %*4[A-Z])',$DepartureAirportIata);
687
				sscanf($table[3][1],'%*[^(] (%3[A-Z] / %*4[A-Z])',$ArrivalAirportIata);
688
				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightaware');
689
			}
690
		}
691
		return array();
692
	}
693
694
	/**
695
	* Get flight info from CostToTravel
696
	* @param String $callsign The callsign
697
	* @param String $date date we want flight number info
698
	* @return Flight departure and arrival airports and time
699
	*/
700
	public function getCostToTravel($callsign, $date = 'NOW') {
701
		$Common = new Common();
702
		$url= "http://www.costtotravel.com/flight-number/".$callsign;
703
		$check_date = new Datetime($date);
0 ignored issues
show
Unused Code introduced by
$check_date 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...
704
		//if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
705
		$data = $Common->getData($url);
706
		if ($data != '') {
707
			$table = $Common->table2array($data);
708
			//print_r($table);
709
			if (isset($table[11][1])) {
710
				$departureTime = substr($table[11][1],0,5);
711
				$arrivalTime = substr($table[17][1],0,5);
712
				$DepartureAirportIata = substr($table[13][1],0,3);
713
				$ArrivalAirportIata = substr($table[15][1],0,3);
714
				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_costtotravel');
715
			}
716
		}
717
		return array();
718
	}
719
720
	/**
721
	* Get flight info from Air Canada
722
	* @param String $callsign The callsign
723
	* @param String $date date we want flight number info
724
	* @return Flight departure and arrival airports and time
725
	*/
726
	private function getAirCanada($callsign,$date = 'NOW') {
727
		$Common = new Common();
728
		date_default_timezone_set('UTC');
729
		$check_date = new Datetime($date);
730
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
731
		$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";
732
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
733
		$data = $Common->getData($url);
734
		$dom = new DomDocument();
735
		$dom->loadXML($data);
736
		if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) return array();
737
		$departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0);
738
		if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) {
739
			$DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
740
			$departureTime = date('H:i',strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
741
			$arrival = $dom->getElementsByTagName('ArrivalStationInfo')->item(0);
742
			$ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
743
			$arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
744
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada');
745
		} else return array();
746
	}
747
748
	/**
749
	* Get flight info from Vietnam Airlines
750
	* @param String $callsign The callsign
751
	* @param String $date date we want flight number info
752
	* @return Flight departure and arrival airports and time
753
	*/
754
	private function getVietnamAirlines($callsign, $date = 'NOW') {
755
		$Common = new Common();
756
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
757
		$check_date = new Datetime($date);
758
		$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."&";
759
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
760
		$data = $Common->getData($url);
761
		if ($data != '') {
762
			$table = $Common->table2array($data);
763
			$flight = $table;
764
			preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
765
			preg_match('/([A-Z]{3})/',$flight[21][0],$ArrivalAirportIataMatch);
766
			$DepartureAirportIata = $DepartureAirportIataMatch[0];
767
			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
768
			$departureTime = $flight[5][1];
769
			$arrivalTime = $flight[23][1];
770
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_vietnamairlines');
771
		}
772
	}
773
774
	/**
775
	* Get flight info from Air Berlin
776
	* @param String $callsign The callsign
777
	* @param String $date date we want flight number info
778
	* @param String $carrier IATA code
779
	* @return Flight departure and arrival airports and time
780
	*/
781
	private function getAirBerlin($callsign, $date = 'NOW', $carrier = 'AB') {
0 ignored issues
show
Unused Code introduced by
The parameter $carrier 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...
782
		$Common = new Common();
783
		date_default_timezone_set('UTC');
784
		//AB = airberlin, HG/NLY = NIKI, 4T/BHP = Belair 
785
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
786
		$check_date = new Datetime($date);
787
		$url= "http://www.airberlin.com/en-US/site/aims.php";
788
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
789
		$post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
790
		$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...
791
		//echo $data;
792
		$DepartureAirportIata = '';
793
		$ArrivalAirportIata = '';
794
		
795
		if ($data != '') {
796
			$table = $Common->table2array($data);
797
			$flight = $table;
798
			if (isset($flight[5][4])) $departureTime = $flight[5][4];
799
			else $departureTime = '';
800
			if (isset($flight[5][2])) $departureAirport = $flight[5][2];
801
			else $departureAirport = '';
802
		}
803
		$post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
804
		$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...
805
		if ($data != '') {
806
			$table = $Common->table2array($data);
807
			$flight = $table;
808
			if (isset($flight[5][4])) {
809
			    $arrivalTime = $flight[5][4];
810
			    $arrivalAirport = $flight[5][3];
811
			} else {
812
			    $arrivalTime = '';
813
			    $arrivalAirport = '';
814
			}
815
		}
816
		$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';
817
		$json = $Common->getData($url);
818
		if ($json == '') return array();
819
		$parsed_json = json_decode($json);
820
		$airports = $parsed_json->{'suggestList'};
821
		if (count($airports) > 0) {
822
			foreach ($airports as $airinfo) {
823
				if ($airinfo->{'name'} == $departureAirport) {
0 ignored issues
show
Bug introduced by
The variable $departureAirport 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...
824
					$DepartureAirportIata = $airinfo->{'code'};
825
				}
826
				if ($airinfo->{'name'} == $arrivalAirport) {
0 ignored issues
show
Bug introduced by
The variable $arrivalAirport 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...
827
					$ArrivalAirportIata = $airinfo->{'code'};
828
				}
829
			}
830
		}
831 View Code Duplication
		if (isset($DepartureAirportIata)) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
832
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airberlin');
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...
Bug introduced by
The variable $arrivalTime 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...
833
		} else return array();
834
	}
835
836
837
	
838
	public function fetchSchedule($ident,$date = 'NOW') {
839
		global $globalSchedulesSources, $globalSchedulesFetch;
840
		$Common = new Common();
0 ignored issues
show
Unused Code introduced by
$Common 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...
841
		if (!$globalSchedulesFetch) return array();
842
		$airline_icao = '';
843 View Code Duplication
		if (!is_numeric(substr($ident, 0, 3)))
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
844
		{
845
			if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) {
846
				$airline_icao = substr($ident, 0, 2);
847
			} elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) {
848
				$airline_icao = substr($ident, 0, 3);
849
			} 
850
		}
851
		if ($airline_icao != '') {
852
			switch ($airline_icao) {
853
/*
854
				// Adria Airways
855
				case "ADR":
856
				case "JP":
857
					return Schedule->getStarAlliance($ident,$date,'JP');
858
					break;
859
				// Aegean Airlines
860
				case "AEE":
861
				case "A3":
862
					return Schedule->getStarAlliance($ident,$date,'A3');
863
					break;
864
				// Air Canada
865
				case "ACA":
866
				case "AC":
867
					return Schedule->getStarAlliance($ident,$date,'AC');
868
					break;
869
				// Air China
870
				case "CCA":
871
				case "CA":
872
					return Schedule->getStarAlliance($ident,$date,'CA');
873
					break;
874
				// Air India
875
				case "AIC":
876
				case "AI":
877
					return Schedule->getStarAlliance($ident,$date,'AI');
878
					break;
879
				// Air New Zealand
880
				case "ANZ":
881
				case "NZ":
882
					return Schedule->getStarAlliance($ident,$date,'NZ');
883
					break;
884
				// All Nippon Airways
885
				case "ANA":
886
				case "NH":
887
					return Schedule->getStarAlliance($ident,$date,'NH');
888
					break;
889
				// Asiana Airlines
890
				case "AAR":
891
				case "OZ":
892
					return Schedule->getStarAlliance($ident,$date,'OZ');
893
					break;
894
				// Austrian
895
				case "AUA":
896
				case "OS":
897
					return Schedule->getStarAlliance($ident,$date,'OS');
898
					break;
899
				// Avianca
900
				case "AVA":
901
				case "AV":
902
					return Schedule->getStarAlliance($ident,$date,'AV');
903
					break;
904
*/
905
				// Brussels Airlines
906
				case "BEL":
907
				case "SN":
908
					return $this->getBrussels($ident,$date,'SN');
0 ignored issues
show
Unused Code introduced by
The call to Schedule::getBrussels() has too many arguments starting with 'SN'.

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...
909
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
910
/*
911
				// Copa Airlines
912
				case "CMP":
913
				case "CM":
914
					return Schedule->getStarAlliance($ident,$date,'CM');
915
					break;
916
				// Croatia Airlines
917
				case "CTN":
918
				case "OU":
919
					return Schedule->getStarAlliance($ident,$date,'OU');
920
					break;
921
				// Egyptair
922
				case "MSR":
923
				case "MS":
924
					return Schedule->getStarAlliance($ident,$date,'MS');
925
					break;
926
				// Ethiopian Airlines
927
				case "ETH":
928
				case "ET":
929
					return Schedule->getStarAlliance($ident,$date,'ET');
930
					break;
931
				// Eva Air
932
				case "EVA":
933
				case "BR":
934
					return Schedule->getStarAlliance($ident,$date,'BR');
935
					break;
936
				// LOT Polish Airlines
937
				case "LOT":
938
				case "LO":
939
					return Schedule->getStarAlliance($ident,$date,'LO');
940
					break;
941
				// Scandinavian Airlines
942
				case "SAS":
943
				case "SK":
944
					return Schedule->getStarAlliance($ident,$date,'SK');
945
					break;
946
				// Shenzhen Airlines
947
				case "CSZ":
948
				case "ZH":
949
					return Schedule->getStarAlliance($ident,$date,'ZH');
950
					break;
951
				// Singapore Airlines
952
				case "SIA":
953
				case "SQ":
954
					return Schedule->getStarAlliance($ident,$date,'SQ');
955
					break;
956
				// South African Airways
957
				case "SAA":
958
				case "SA":
959
					return Schedule->getStarAlliance($ident,$date,'SA');
960
					break;
961
*/
962
				// SWISS
963
				case "SWR":
964
				case "LX":
965
					return $this->getSwiss($ident);
966
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
967
968
				/*
969
				// TAP Portugal
970
				case "TAP":
971
				case "TP":
972
					return $this->getFlyTap($ident,$date);
973
					break;
974
				*/
975
/*
976
				// Thai Airways International
977
				case "THA":
978
				case "TG":
979
					return Schedule->getStarAlliance($ident,$date,'TG');
980
					break;
981
				// Turkish Airlines
982
				case "THY":
983
				case "TK":
984
					return Schedule->getStarAlliance($ident,$date,'TK');
985
					break;
986
				// United
987
				case "UAL":
988
				case "UA":
989
					return Schedule->getStarAlliance($ident,$date,'UA');
990
					break;
991
*/
992
				// Air France
993
				case "AF":
994
				case "AFR":
995
					return $this->getAirFrance($ident,$date,'AF');
996
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
997
				// HOP
998
				case "A5":
999
				case "HOP":
1000
					return $this->getAirFrance($ident,$date,'A5');
1001
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1002
				// EasyJet
1003
				case "U2":
1004
				case "DS":
1005
				case "EZY":
1006
				case "EZS":
1007
					return $this->getEasyJet($ident,$date);
1008
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1009
				// Ryanair
1010
				case "FR":
1011
				case "RYR":
1012
					return $this->getRyanair($ident);
1013
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1014
				// British Airways
1015
				case "BA":
1016
				case "SHT":
1017
				case "BAW":
1018
					return $this->getBritishAirways($ident);
1019
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1020
				// Tunisair
1021
				case "TUI":
1022
				case "TAR":
1023
				case "TU":
1024
					return $this->getTunisair($ident);
1025
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1026
				// Vueling
1027
				case "VLG":
1028
				case "VY":
1029
					return $this->getVueling($ident);
1030
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1031
				// Alitalia
1032
				case "AZ":
1033
				case "AZA":
1034
					return $this->getAlitalia($ident);
1035
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1036
				// Air Canada
1037
				case "ACA":
1038
				case "AC":
1039
					return $this->getAirCanada($ident);
1040
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1041
				// Lufthansa
1042
				case "DLH":
1043
				case "LH":
1044
					return $this->getLufthansa($ident);
1045
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
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
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1064
				// Vietnam Airlines
1065
				case "HVN":
1066
					return $this->getVietnamAirlines($ident,$date);
1067
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1068
				// Air Berlin
1069
				case "AB":
1070
				case "BER":
1071
					return $this->getAirBerlin($ident,$date,'AB');
1072
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1073
				// NIKI
1074
				case "HG":
1075
				case "NLY":
1076
					return $this->getAirBerlin($ident,$date,'HG');
1077
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1078
				// BelAir
1079
				case "4T":
1080
				case "BHP":
1081
					return $this->getAirBerlin($ident,$date,'4T');
1082
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

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