Completed
Push — master ( 3f174d...72d96f )
by Yannick
12:45
created

Schedule::getSchedule()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 21
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 18
c 1
b 0
f 0
nc 8
nop 1
dl 0
loc 21
rs 9.0534
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;
1 ignored issue
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
	        //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident";
1 ignored issue
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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";
1 ignored issue
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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';
1 ignored issue
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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';
1 ignored issue
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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";
1 ignored issue
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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
			/*
1 ignored issue
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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
	private 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
		$headers = array('apikey: '.$globalTransaviaKey);
351
		$json = $Common->getData($url,'get','',$headers);
352
		if ($json == '') return array();
353
		$parsed_json = json_decode($json);
354
		
355
		if (isset($parsed_json->{'data'}[0])) {
356
			$DepartureAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'departureAirport'}->{'locationCode'};
357
			$departureTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'}));
358
			$ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'};
359
			$arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'}));
360
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia');
361
		} else return array();
362
	}
363
364
	/**
365
	* Get flight info from Tunisair
366
	* @param String $callsign The callsign
367
	* @return Flight departure and arrival airports and time
368
	*/
369
	private function getTunisair($callsign) {
370
		$Common = new Common();
371
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
372
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
373
		$url = "http://www.tunisair.com/site/publish/module/Volj/fr/Flight_List.asp";
374
		$data = $Common->getData($url);
375
		$table = $Common->table2array($data);
376
		foreach ($table as $flight) {
377
			if (isset($flight[1]) && $flight[1] == "TU ".sprintf('%04d',$numvol)) {
378
				return array('DepartureAirportIATA' => $flight[2],'DepartureTime' => str_replace('.',':',$flight[5]),'ArrivalAirportIATA' => $flight[3],'ArrivalTime' => str_replace('.',':',$flight[6]),'Source' => 'website_tunisair');
379
			}
380
		}
381
		return array();
382
	}
383
384
	/**
385
	* Get flight info from Vueling
386
	* @param String $callsign The callsign
387
	* @return Flight departure and arrival airports and time
388
	*/
389
	private function getVueling($callsign) {
390
		$Common = new Common();
391
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
392
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
393
		$url = "https://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=DailyFlights&OriginSelected=&DestinationSelected=&idioma=en-GB&pageid=30694&ItemsByPage=50&FlightNumberFilter=".$numvol;
394
		$data = $Common->getData($url);
395
		if ($data != '') {
396
			$table = $Common->table2array($data);
397
			foreach ($table as $flight) {
398
				if (count($flight) > 0 && $flight[0] == "VY".$numvol && isset($flight[13])) {
399
					preg_match('/flightOri=[A-Z]{3}/',$flight[13],$result);
400
					$DepartureAirportIata = str_replace('flightOri=','',$result[0]);
401
					preg_match('/flightDest=[A-Z]{3}/',$flight[13],$result);
402
					$ArrivalAirportIata = str_replace('flightDest=','',$result[0]);
403
					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $flight[3],'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $flight[4],'Source' => 'website_vueling');
404
				}
405
			}
406
		}
407
		return array();
408
	}
409
410
	/**
411
	* Get flight info from Iberia
412
	* @param String $callsign The callsign
413
	* @param String $date date we want flight number info
414
	* @return Flight departure and arrival airports and time
415
	*/
416
	private function getIberia($callsign, $date = 'NOW') {
417
		$Common = new Common();
418
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
419
		$check_date = new Datetime($date);
420
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
421
		$url = "https://www.iberia.com/web/flightDetail.do";
422
		$post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB');
423
		$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...
424
		if ($data != '') {
425
			$table = $Common->table2array($data);
426
			//print_r($table);
427
			if (count($table) > 0) {
428
				$flight = $table;
429
				preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
430
				preg_match('/([A-Z]{3})/',$flight[5][0],$ArrivalAirportIataMatch);
431
				$DepartureAirportIata = $DepartureAirportIataMatch[0];
432
				$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
433
				$departureTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[3][2]))),0,5);
434
				$arrivalTime = trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][1])));
435
				if ($arrivalTime == 'Hora estimada de llegada') {
436
					$arrivalTime = substr(trim(str_replace(' lunes','',str_replace('&nbsp;','',$flight[5][2]))),0,5);
437
				} else $arrivalTime = substr($arrivalTime,0,5);
438
				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia');
439
			}
440
		}
441
		return array();
442
	}
443
444
	/**
445
	* Get flight info from Star Alliance
446
	* @param String $callsign The callsign
447
	* @param String $date date we want flight number info
448
	* @return Flight departure and arrival airports and time
449
	*/
450
	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...
451
		$Common = new Common();
452
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
453
		$check_date = new Datetime($date);
454
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
455
		$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');
456
		$data = $Common->getData($url);
457
		if ($data != '') {
458
			$table = $Common->table2array($data);
459
			if (count($table) > 0) {
460
				$flight = $table;
461
				//print_r($table);
462
				if (isset($flight[25]) && isset($flight[29])) {
463
					preg_match('/([A-Z]{3})/',$flight[25][1],$DepartureAirportIataMatch);
464
					preg_match('/([A-Z]{3})/',$flight[25][3],$ArrivalAirportIataMatch);
465
					$DepartureAirportIata = $DepartureAirportIataMatch[0];
466
					$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
467
					$departureTime = substr(trim(str_replace('Scheduled: ','',$flight[29][0])),0,5);
468
					$arrivalTime = substr(trim(str_replace('Scheduled: ','',$flight[29][1])),0,5);
469
					return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_staralliance');
470
				} else return array();
471
			}
472
			
473
474
		}
475
		return array();
476
	}
477
478
	/**
479
	* Get flight info from Alitalia
480
	* @param String $callsign The callsign
481
	* @param String $date date we want flight number info
482
	* @return Flight departure and arrival airports and time
483
	*/
484
	private function getAlitalia($callsign, $date = 'NOW') {
485
		$Common = new Common();
486
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
487
		$check_date = new Datetime($date);
488
		$url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y');
489
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
490
		$data = $Common->getData($url);
491
		if ($data != '') {
492
			$table = $Common->text2array($data);
493
			$DepartureAirportIata = '';
494
			$ArrivalAirportIata = '';
495
			$departureTime = $table[4];
496
			$arrivalTime = $table[5];
497
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_alitalia');
498
		}
499
	}
500
501
	/**
502
	* Get flight info from Brussels airlines
503
	* @param String $callsign The callsign
504
	* @param String $date date we want flight number info
505
	* @return Flight departure and arrival airports and time
506
	*/
507
	private function getBrussels($callsign, $date = 'NOW') {
508
		$Common = new Common();
509
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
510
		$check_date = new Datetime($date);
511
		$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";
512
		//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";
513
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
514
		$data = $Common->getData($url);
515
		if ($data != '') {
516
		    //echo $data;
517
		    $parsed_json = json_decode($data);
518
		    if (isset($parsed_json[0]->FromAirportCode)) {
519
			$DepartureAirportIata = $parsed_json[0]->FromAirportCode;
520
			$ArrivalAirportIata = $parsed_json[0]->ToAirportCode;
521
			$departureTime = date('H:i',strtotime($parsed_json[0]->ScheduledDepatureDate));
522
			$arrivalTime = date('H:i',strtotime($parsed_json[0]->ScheduledArrivalDate));
523
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_brussels');
524
		    }
525
		}
526
	}
527
528
	/**
529
	* Get flight info from FlightRadar24
530
	* @param String $callsign The callsign
531
	* @param String $date date we want flight number info
532
	* @return Flight departure and arrival airports and time
533
	*/
534
/*
1 ignored issue
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
535
	public function getFlightRadar24($callsign, $date = 'NOW') {
536
		$Common = new Common();
537
		$url= "http://arn.data.fr24.com/zones/fcgi/feed.js?flight=".$callsign;
538
		$data = $Common->getData($url);
539
		if ($data != '') {
540
			$parsed_json = get_object_vars(json_decode($data));
541
			if (count($parsed_json) > 2) {
542
				$info = array_splice($parsed_json,2,1);
543
				$fr24id = current(array_keys($info));
544
				$urldata = "http://krk.data.fr24.com/_external/planedata_json.1.4.php?f=".$fr24id;
545
				$datapl = $Common->getData($urldata);
546
				if ($datapl != '') {
547
					$parsed_jsonpl = json_decode($datapl);
548
					if (isset($parsed_jsonpl->from_iata)) {
549
						$DepartureAirportIata = $parsed_jsonpl->from_iata;
550
						$ArrivalAirportIata = $parsed_jsonpl->to_iata;
551
						$departureTime = date('H:i',$parsed_jsonpl->dep_schd);
552
						$arrivalTime = date('H:i',$parsed_jsonpl->arr_schd);
553
						return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightradar24');
554
					}
555
				}
556
			}
557
		}
558
		return array();
559
	}
560
  */
561
	/**
562
	* Get flight info from Lufthansa
563
	* @param String $callsign The callsign
564
	* @param String $date date we want flight number info
565
	* @return Flight departure and arrival airports and time
566
	*/
567
568
/*	private function getLufthansa($callsign, $date = 'NOW') {
1 ignored issue
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
569
		$Common = new Common();
570
		*/
571
		//$numvol = preg_replace('/^[A-Z]*/','',$callsign);
1 ignored issue
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
572
/*
573
		$url= "http://www.lufthansa.com/fr/fr/Arrivees-Departs-fonction";
574
		$check_date = new Datetime($date);
575
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
576
577
		$post = array('flightNumber' => $numvol, 'date' => $check_date->format('Y-m-d'),'time' => '12:00','timezoneOffset' => '0','selection' => '0','arrivalDeparture' => 'D');
578
		$data = $Common->getData($url,'post',$post);
579
		if ($data != '') {
580
			$table = $Common->table2array($data);
581
			$departureTime = trim(str_replace($check_date->format('d.m.Y'),'',$table[25][3]));
582
		}
583
584
		$post = array('flightNumber' => $numvol, 'date' => $check_date->format('Y-m-d'),'time' => '12:00','timezoneOffset' => '0','selection' => '0','arrivalDeparture' => 'A');
585
		$data = $Common->getData($url,'post',$post);
586
		if ($data != '') {
587
			$table = $Common->table2array($data);
588
			$arrivalTime = trim(str_replace($check_date->format('d.m.Y'),'',$table[25][3]));
589
		}
590
		return array('DepartureAirportIATA' => '','DepartureTime' => $departureTime,'ArrivalAirportIATA' => '','ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa');
591
	}
592
  */
593
	/**
594
	* Get flight info from flytap
595
	* @param String $callsign The callsign
596
	* @param String $date date we want flight number info
597
	* @return Flight departure and arrival airports and time
598
	*/
599
	private function getFlyTap($callsign, $date = 'NOW') {
600
		$Common = new Common();
601
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
602
		$url= "http://www.flytap.com/France/fr/PlanifierEtReserver/Outils/DepartsEtArrivees";
603
		$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...
604
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
605
		$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');
606
		$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...
607
		if ($data != '') {
608
			$table = $Common->table2array($data);
609
			$departureTime = trim(substr($table[15][0],0,5));
610
			$arrivalTime = trim(substr($table[35][0],0,5));
611
			preg_match('/([A-Z]{3})/',$table[11][0],$DepartureAirportIataMatch);
612
			preg_match('/([A-Z]{3})/',$table[31][0],$ArrivalAirportIataMatch);
613
			$DepartureAirportIata = $DepartureAirportIataMatch[0];
614
			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
615
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flytap');
616
		}
617
		return array();
618
	}
619
620
	/**
621
	* Get flight info from flightmapper
622
	* @param String $callsign The callsign
623
	* @param String $date date we want flight number info
624
	* @return Flight departure and arrival airports and time
625
	*/
626
	public function getFlightMapper($callsign, $date = 'NOW') {
627
		$Common = new Common();
628 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...
629
		{
630
			if (is_numeric(substr(substr($callsign, 0, 3), -1, 1))) {
631
				$airline_icao = substr($callsign, 0, 2);
632
			} elseif (is_numeric(substr(substr($callsign, 0, 4), -1, 1))) {
633
				$airline_icao = substr($callsign, 0, 3);
634
			} 
635
		}
636
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
637
		$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...
638
		$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...
639
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
640
		$data = $Common->getData($url);
641
		if ($data != '') {
642
			$table = $Common->table2array($data);
643
			if (isset($table[5][0])) {
644
				$sched = $table[5][0];
645
				$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...
646
				if ($n == 7) {
647
				    $departureTime = $dhour;
648
				    $arrivalTime = $ahour;
649
				    $DepartureAirportIata = str_replace(array('(',')'),'',$darr);
650
				    $ArrivalAirportIata = str_replace(array('(',')'),'',$aarr);
651
				    return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightmapper');
652
				}
653
			}
654
		}
655
		return array();
656
	}
657
658
	/**
659
	* Get flight info from flightaware
660
	* @param String $callsign The callsign
661
	* @param String $date date we want flight number info
662
	* @return Flight departure and arrival airports and time
663
	*/
664
	public function getFlightAware($callsign, $date = 'NOW') {
665
		$Common = new Common();
666 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...
667
		{
668
			if (is_numeric(substr(substr($callsign, 0, 3), -1, 1))) {
669
				$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...
670
			} elseif (is_numeric(substr(substr($callsign, 0, 4), -1, 1))) {
671
				$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...
672
			} 
673
		}
674
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
675
		$url= "http://fr.flightaware.com/live/flight/".$callsign;
676
		$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...
677
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
678
		$data = $Common->getData($url);
679
		if ($data != '') {
680
			$table = $Common->table2array($data);
681
			if (isset($table[11][0])) {
682
				$departureTime = str_replace('h',':',substr($table[5][0],0,5));
683
				$arrivalTime = str_replace('h',':',substr($table[5][1],0,5));
684
				echo $table[3][0];
685
				sscanf($table[3][0],'%*[^(] (%3[A-Z] / %*4[A-Z])',$DepartureAirportIata);
686
				sscanf($table[3][1],'%*[^(] (%3[A-Z] / %*4[A-Z])',$ArrivalAirportIata);
687
				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightaware');
688
			}
689
		}
690
		return array();
691
	}
692
693
	/**
694
	* Get flight info from CostToTravel
695
	* @param String $callsign The callsign
696
	* @param String $date date we want flight number info
697
	* @return Flight departure and arrival airports and time
698
	*/
699
	public function getCostToTravel($callsign, $date = 'NOW') {
700
		$Common = new Common();
701
		$url= "http://www.costtotravel.com/flight-number/".$callsign;
702
		$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...
703
		//if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
1 ignored issue
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
704
		$data = $Common->getData($url);
705
		if ($data != '') {
706
			$table = $Common->table2array($data);
707
			//print_r($table);
708
			if (isset($table[11][1])) {
709
				$departureTime = substr($table[11][1],0,5);
710
				$arrivalTime = substr($table[17][1],0,5);
711
				$DepartureAirportIata = substr($table[13][1],0,3);
712
				$ArrivalAirportIata = substr($table[15][1],0,3);
713
				return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_costtotravel');
714
			}
715
		}
716
		return array();
717
	}
718
719
	/**
720
	* Get flight info from Air Canada
721
	* @param String $callsign The callsign
722
	* @param String $date date we want flight number info
723
	* @return Flight departure and arrival airports and time
724
	*/
725
	private function getAirCanada($callsign,$date = 'NOW') {
726
		$Common = new Common();
727
		date_default_timezone_set('UTC');
728
		$check_date = new Datetime($date);
729
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
730
		$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";
731
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
732
		$data = $Common->getData($url);
733
		$dom = new DomDocument();
734
		$dom->loadXML($data);
735
		if ($dom->getElementsByTagName('DepartureStationInfo')->length == 0) return array();
736
		$departure = $dom->getElementsByTagName('DepartureStationInfo')->item(0);
737
		if (isset($departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue)) {
738
			$DepartureAirportIata = $departure->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
739
			$departureTime = date('H:i',strtotime($departure->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
740
			$arrival = $dom->getElementsByTagName('ArrivalStationInfo')->item(0);
741
			$ArrivalAirportIata = $arrival->getElementsByTagName('Airport')->item(0)->firstChild->nodeValue;
742
			$arrivalTime = date('H:i',strtotime($arrival->getElementsByTagName('ScheduledTime')->item(0)->firstChild->nodeValue));
743
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_aircanada');
744
		} else return array();
745
	}
746
747
	/**
748
	* Get flight info from Vietnam Airlines
749
	* @param String $callsign The callsign
750
	* @param String $date date we want flight number info
751
	* @return Flight departure and arrival airports and time
752
	*/
753
	private function getVietnamAirlines($callsign, $date = 'NOW') {
754
		$Common = new Common();
755
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
756
		$check_date = new Datetime($date);
757
		$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."&";
758
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
759
		$data = $Common->getData($url);
760
		if ($data != '') {
761
			$table = $Common->table2array($data);
762
			$flight = $table;
763
			preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch);
764
			preg_match('/([A-Z]{3})/',$flight[21][0],$ArrivalAirportIataMatch);
765
			$DepartureAirportIata = $DepartureAirportIataMatch[0];
766
			$ArrivalAirportIata = $ArrivalAirportIataMatch[0];
767
			$departureTime = $flight[5][1];
768
			$arrivalTime = $flight[23][1];
769
			return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_vietnamairlines');
770
		}
771
	}
772
773
	/**
774
	* Get flight info from Air Berlin
775
	* @param String $callsign The callsign
776
	* @param String $date date we want flight number info
777
	* @param String $carrier IATA code
778
	* @return Flight departure and arrival airports and time
779
	*/
780
	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...
781
		$Common = new Common();
782
		date_default_timezone_set('UTC');
783
		//AB = airberlin, HG/NLY = NIKI, 4T/BHP = Belair 
784
		$numvol = preg_replace('/^[A-Z]*/','',$callsign);
785
		$check_date = new Datetime($date);
786
		$url= "http://www.airberlin.com/en-US/site/aims.php";
787
		if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array();
788
		$post = array('type' => 'departure','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
789
		$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...
790
		//echo $data;
791
		$DepartureAirportIata = '';
792
		$ArrivalAirportIata = '';
793
		
794
		if ($data != '') {
795
			$table = $Common->table2array($data);
796
			$flight = $table;
797
			if (isset($flight[5][4])) $departureTime = $flight[5][4];
798
			else $departureTime = '';
799
			if (isset($flight[5][2])) $departureAirport = $flight[5][2];
800
			else $departureAirport = '';
801
		}
802
		$post = array('type' => 'arrival','searchFlightNo' => '1','requestsent' => 'true', 'flightno' => $numvol,'date' => $check_date->format('Y-m-d'),'carrier' => 'AB');
803
		$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...
804
		if ($data != '') {
805
			$table = $Common->table2array($data);
806
			$flight = $table;
807
			if (isset($flight[5][4])) {
808
			    $arrivalTime = $flight[5][4];
809
			    $arrivalAirport = $flight[5][3];
810
			} else {
811
			    $arrivalTime = '';
812
			    $arrivalAirport = '';
813
			}
814
		}
815
		$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';
816
		$json = $Common->getData($url);
817
		if ($json == '') return array();
818
		$parsed_json = json_decode($json);
819
		$airports = $parsed_json->{'suggestList'};
820
		if (count($airports) > 0) {
821
			foreach ($airports as $airinfo) {
822
				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...
823
					$DepartureAirportIata = $airinfo->{'code'};
824
				}
825
				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...
826
					$ArrivalAirportIata = $airinfo->{'code'};
827
				}
828
			}
829
		}
830 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...
831
			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...
832
		} else return array();
833
	}
834
835
836
	
837
	public function fetchSchedule($ident,$date = 'NOW') {
838
		global $globalSchedulesSources, $globalSchedulesFetch;
839
		$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...
840
		if (!$globalSchedulesFetch) return array();
841
		$airline_icao = '';
842 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...
843
		{
844
			if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) {
845
				$airline_icao = substr($ident, 0, 2);
846
			} elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) {
847
				$airline_icao = substr($ident, 0, 3);
848
			} 
849
		}
850
		if ($airline_icao != '') {
851
			switch ($airline_icao) {
852
/*
1 ignored issue
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
853
				// Adria Airways
854
				case "ADR":
855
				case "JP":
856
					return Schedule->getStarAlliance($ident,$date,'JP');
857
					break;
858
				// Aegean Airlines
859
				case "AEE":
860
				case "A3":
861
					return Schedule->getStarAlliance($ident,$date,'A3');
862
					break;
863
				// Air Canada
864
				case "ACA":
865
				case "AC":
866
					return Schedule->getStarAlliance($ident,$date,'AC');
867
					break;
868
				// Air China
869
				case "CCA":
870
				case "CA":
871
					return Schedule->getStarAlliance($ident,$date,'CA');
872
					break;
873
				// Air India
874
				case "AIC":
875
				case "AI":
876
					return Schedule->getStarAlliance($ident,$date,'AI');
877
					break;
878
				// Air New Zealand
879
				case "ANZ":
880
				case "NZ":
881
					return Schedule->getStarAlliance($ident,$date,'NZ');
882
					break;
883
				// All Nippon Airways
884
				case "ANA":
885
				case "NH":
886
					return Schedule->getStarAlliance($ident,$date,'NH');
887
					break;
888
				// Asiana Airlines
889
				case "AAR":
890
				case "OZ":
891
					return Schedule->getStarAlliance($ident,$date,'OZ');
892
					break;
893
				// Austrian
894
				case "AUA":
895
				case "OS":
896
					return Schedule->getStarAlliance($ident,$date,'OS');
897
					break;
898
				// Avianca
899
				case "AVA":
900
				case "AV":
901
					return Schedule->getStarAlliance($ident,$date,'AV');
902
					break;
903
*/
904
				// Brussels Airlines
905
				case "BEL":
906
				case "SN":
907
					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...
908
					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...
909
/*
1 ignored issue
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
910
				// Copa Airlines
911
				case "CMP":
912
				case "CM":
913
					return Schedule->getStarAlliance($ident,$date,'CM');
914
					break;
915
				// Croatia Airlines
916
				case "CTN":
917
				case "OU":
918
					return Schedule->getStarAlliance($ident,$date,'OU');
919
					break;
920
				// Egyptair
921
				case "MSR":
922
				case "MS":
923
					return Schedule->getStarAlliance($ident,$date,'MS');
924
					break;
925
				// Ethiopian Airlines
926
				case "ETH":
927
				case "ET":
928
					return Schedule->getStarAlliance($ident,$date,'ET');
929
					break;
930
				// Eva Air
931
				case "EVA":
932
				case "BR":
933
					return Schedule->getStarAlliance($ident,$date,'BR');
934
					break;
935
				// LOT Polish Airlines
936
				case "LOT":
937
				case "LO":
938
					return Schedule->getStarAlliance($ident,$date,'LO');
939
					break;
940
				// Scandinavian Airlines
941
				case "SAS":
942
				case "SK":
943
					return Schedule->getStarAlliance($ident,$date,'SK');
944
					break;
945
				// Shenzhen Airlines
946
				case "CSZ":
947
				case "ZH":
948
					return Schedule->getStarAlliance($ident,$date,'ZH');
949
					break;
950
				// Singapore Airlines
951
				case "SIA":
952
				case "SQ":
953
					return Schedule->getStarAlliance($ident,$date,'SQ');
954
					break;
955
				// South African Airways
956
				case "SAA":
957
				case "SA":
958
					return Schedule->getStarAlliance($ident,$date,'SA');
959
					break;
960
*/
961
				// SWISS
962
				case "SWR":
963
				case "LX":
964
					return $this->getSwiss($ident);
965
					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...
966
967
				// TAP Portugal
968
				case "TAP":
969
				case "TP":
970
					return $this->getFlyTap($ident,$date);
971
					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...
972
/*
1 ignored issue
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
973
				// Thai Airways International
974
				case "THA":
975
				case "TG":
976
					return Schedule->getStarAlliance($ident,$date,'TG');
977
					break;
978
				// Turkish Airlines
979
				case "THY":
980
				case "TK":
981
					return Schedule->getStarAlliance($ident,$date,'TK');
982
					break;
983
				// United
984
				case "UAL":
985
				case "UA":
986
					return Schedule->getStarAlliance($ident,$date,'UA');
987
					break;
988
*/
989
				// Air France
990
				case "AF":
991
				case "AFR":
992
					return $this->getAirFrance($ident,$date,'AF');
993
					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...
994
				// HOP
995
				case "A5":
996
				case "HOP":
997
					return $this->getAirFrance($ident,$date,'A5');
998
					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...
999
				// EasyJet
1000
				case "U2":
1001
				case "DS":
1002
				case "EZY":
1003
				case "EZS":
1004
					return $this->getEasyJet($ident,$date);
1005
					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...
1006
				// Ryanair
1007
				case "FR":
1008
				case "RYR":
1009
					return $this->getRyanair($ident);
1010
					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...
1011
				// British Airways
1012
				case "BA":
1013
				case "SHT":
1014
				case "BAW":
1015
					return $this->getBritishAirways($ident);
1016
					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...
1017
				// Tunisair
1018
				case "TUI":
1019
				case "TAR":
1020
				case "TU":
1021
					return $this->getTunisair($ident);
1022
					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...
1023
				// Vueling
1024
				case "VLG":
1025
				case "VY":
1026
					return $this->getVueling($ident);
1027
					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...
1028
				// Alitalia
1029
				case "AZ":
1030
				case "AZA":
1031
					return $this->getAlitalia($ident);
1032
					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...
1033
				// Air Canada
1034
				case "ACA":
1035
				case "AC":
1036
					return $this->getAirCanada($ident);
1037
					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...
1038
				// Lufthansa
1039
				case "DLH":
1040
				case "LH":
1041
					return $this->getLufthansa($ident);
1042
					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...
1043
				// Transavia
1044
				case "TRA":
1045
				case "HV":
1046
					return $this->getTransavia($ident);
1047
					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...
1048
					
1049
/*
1 ignored issue
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1050
				case "DLH":
1051
				case "LH":
1052
					return $this->getStarAlliance($ident,$date,'LH');
1053
					break;
1054
*/
1055
				// Iberia
1056
				case "IBE":
1057
				case "IB":
1058
					return $this->getIberia($ident);
1059
					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...
1060
				// Vietnam Airlines
1061
				case "HVN":
1062
					return $this->getVietnamAirlines($ident,$date);
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
				// Air Berlin
1065
				case "AB":
1066
				case "BER":
1067
					return $this->getAirBerlin($ident,$date,'AB');
1068
					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...
1069
				// NIKI
1070
				case "HG":
1071
				case "NLY":
1072
					return $this->getAirBerlin($ident,$date,'HG');
1073
					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...
1074
				// BelAir
1075
				case "4T":
1076
				case "BHP":
1077
					return $this->getAirBerlin($ident,$date,'4T');
1078
					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...
1079
				default:
1080
					// Randomly use a generic function to get hours
1081
					if (strlen($airline_icao) == 2) {
1082
						if (!isset($globalSchedulesSources)) $globalSchedulesSources = array('flightmapper','costtotravel','flightradar24','flightaware');
1083
						if (count($globalSchedulesSources) > 0) {
1084
							$rand = mt_rand(0,count($globalSchedulesSources)-1);
1085
							$source = $globalSchedulesSources[$rand];
1086
							if ($source == 'flightmapper') return $this->getFlightMapper($ident,$date);
1087
							elseif ($source == 'costtotravel') return $this->getCostToTravel($ident,$date);
1088
							//elseif ($source == 'flightradar24') return $this->getFlightRadar24($ident,$date);
1 ignored issue
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1089
							elseif ($source == 'flightaware') return $this->getFlightAware($ident,$date);
1090
						}
1091
					}
1092
			}
1093
		}
1094
	        return array();
1095
	}
1096
}
1097
1098
  /*
1 ignored issue
show
Unused Code Comprehensibility introduced by
68% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1099
$Schedule = new Schedule();
1100
//print_r($Schedule->fetchSchedule('HV5661'));
1101
//print_r($Schedule->getFlightAware('AF1179'));
1102
//print_r($Schedule->getBritishAirways('BAW551'));
1103
print_r($Schedule->getLufthansa('LH551'));
1104
*/
1105
?>
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...