Complex classes like Schedule often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Schedule, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class Schedule { |
||
| 10 | protected $cookies = array(); |
||
| 11 | public $db; |
||
| 12 | public function __construct($dbc = null) { |
||
| 13 | $Connection = new Connection($dbc); |
||
| 14 | $this->db = $Connection->db(); |
||
| 15 | } |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Add schedule data to database |
||
| 19 | * @param String $ident aircraft ident |
||
| 20 | * @param String $departure_airport_icao departure airport icao |
||
| 21 | * @param String $departure_airport_time departure airport time |
||
| 22 | * @param String $arrival_airport_icao arrival airport icao |
||
| 23 | * @param String $arrival_airport_time arrival airport time |
||
| 24 | / @param String $source source of data |
||
| 25 | */ |
||
| 26 | |||
| 27 | public function addSchedule($ident,$departure_airport_icao,$departure_airport_time,$arrival_airport_icao,$arrival_airport_time,$source = 'website') { |
||
| 28 | date_default_timezone_set('UTC'); |
||
| 29 | $date = date("Y-m-d H:i:s",time()); |
||
| 30 | //if ($departure_airport_time == '' && $arrival_airport_time == '') exit; |
||
| 31 | //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident"; |
||
| 32 | $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident"; |
||
| 33 | $query_values = array(':ident' => $ident); |
||
| 34 | try { |
||
| 35 | $sth = $this->db->prepare($query); |
||
| 36 | $sth->execute($query_values); |
||
| 37 | } catch(PDOException $e) { |
||
| 38 | return "error : ".$e->getMessage(); |
||
| 39 | } |
||
| 40 | if ($sth->fetchColumn() > 0) { |
||
| 41 | if ($departure_airport_time == '' && $arrival_airport_time == '') { |
||
| 42 | $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao"; |
||
| 43 | $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao); |
||
| 44 | } elseif ($arrival_airport_time == '') { |
||
| 45 | $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao"; |
||
| 46 | $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao); |
||
| 47 | } elseif ($departure_airport_time == '') { |
||
| 48 | $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time"; |
||
| 49 | $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time); |
||
| 50 | } else { |
||
| 51 | //$query = "SELECT COUNT(*) FROM schedule WHERE ident = :ident AND departure_airport_icao = :departure_airport_icao AND departure_airport_time = :departure_airport_time AND arrival_airport_icao = :arrival_airport_icao AND arrival_airport_time = :arrival_airport_time"; |
||
| 52 | $query = "SELECT COUNT(*) FROM routes WHERE CallSign = :ident AND FromAirport_ICAO = :departure_airport_icao AND FromAirport_Time = :departure_airport_time AND ToAirport_ICAO = :arrival_airport_icao AND ToAirport_Time = :arrival_airport_time"; |
||
| 53 | $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time); |
||
| 54 | } |
||
| 55 | try { |
||
| 56 | $sth = $this->db->prepare($query); |
||
| 57 | $sth->execute($query_values); |
||
| 58 | } catch(PDOException $e) { |
||
| 59 | return "error : ".$e->getMessage(); |
||
| 60 | } |
||
| 61 | if ($sth->fetchColumn() == 0) { |
||
| 62 | //$query = 'UPDATE schedule SET departure_airport_icao = :departure_airport_icao, departure_airport_time = :departure_airport_time, arrival_airport_icao = :arrival_airport_icao, arrival_airport_time = :arrival_airport_time, date_modified = :date, source = :source WHERE ident = :ident'; |
||
| 63 | if ($departure_airport_time == '' && $arrival_airport_time == '') { |
||
| 64 | $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
||
| 65 | $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source); |
||
| 66 | } elseif ($arrival_airport_time == '') { |
||
| 67 | $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
||
| 68 | $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao, ':date' => $date, ':source' => $source); |
||
| 69 | } elseif ($departure_airport_time == '') { |
||
| 70 | $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
||
| 71 | $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
||
| 72 | } else { |
||
| 73 | $query = 'UPDATE routes SET FromAirport_ICAO = :departure_airport_icao, FromAiport_Time = :departure_airport_time, ToAirport_ICAO = :arrival_airport_icao, ToAirport_Time = :arrival_airport_time, date_modified = :date, Source = :source WHERE CallSign = :ident'; |
||
| 74 | $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
||
| 75 | } |
||
| 76 | try { |
||
| 77 | $sth = $this->db->prepare($query); |
||
| 78 | $sth->execute($query_values); |
||
| 79 | } catch(PDOException $e) { |
||
| 80 | return "error : ".$e->getMessage(); |
||
| 81 | } |
||
| 82 | } else { |
||
| 83 | //$query = 'UPDATE schedule SET date_lastseen = :date WHERE ident = :ident'; |
||
| 84 | $query = 'UPDATE routes SET date_lastseen = :date WHERE CallSign = :ident'; |
||
| 85 | $query_values = array(':ident' => $ident,':date' => $date); |
||
| 86 | try { |
||
| 87 | $sth = $this->db->prepare($query); |
||
| 88 | $sth->execute($query_values); |
||
| 89 | } catch(PDOException $e) { |
||
| 90 | return "error : ".$e->getMessage(); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } else { |
||
| 94 | $query = 'INSERT INTO routes (CallSign,FromAirport_ICAO, FromAirport_Time, ToAirport_ICAO, ToAirport_Time,date_added,source) VALUES (:ident,:departure_airport_icao,:departure_airport_time,:arrival_airport_icao,:arrival_airport_time,:date,:source)'; |
||
| 95 | $query_values = array(':ident' => $ident,':departure_airport_icao' => $departure_airport_icao,':departure_airport_time' => $departure_airport_time,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_time' => $arrival_airport_time, ':date' => $date, ':source' => $source); |
||
| 96 | try { |
||
| 97 | $sth = $this->db->prepare($query); |
||
| 98 | $sth->execute($query_values); |
||
| 99 | } catch(PDOException $e) { |
||
| 100 | return "error : ".$e->getMessage(); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | } |
||
| 105 | |||
| 106 | public function getSchedule($ident) { |
||
| 107 | $Translation = new Translation($this->db); |
||
| 108 | $operator = $Translation->checkTranslation($ident,false); |
||
| 109 | if ($ident != $operator) { |
||
| 110 | $query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :operator OR CallSign = :ident LIMIT 1"; |
||
| 111 | $query_values = array(':ident' => $ident,'operator' => $operator); |
||
| 112 | } else { |
||
| 113 | $query = "SELECT FromAirport_ICAO as departure_airport_icao, ToAirport_ICAO as arrival_airport_icao, FromAirport_Time as departure_airport_time, ToAirport_Time as arrival_airport_time FROM routes WHERE CallSign = :ident LIMIT 1"; |
||
| 114 | $query_values = array(':ident' => $ident); |
||
| 115 | } |
||
| 116 | try { |
||
| 117 | $sth = $this->db->prepare($query); |
||
| 118 | $sth->execute($query_values); |
||
| 119 | } catch(PDOException $e) { |
||
| 120 | return "error : ".$e->getMessage(); |
||
| 121 | } |
||
| 122 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 123 | if (count($row) > 0) { |
||
| 124 | return $row; |
||
| 125 | } else return array(); |
||
| 126 | } |
||
| 127 | |||
| 128 | public function checkSchedule($ident) { |
||
| 129 | global $globalDBdriver; |
||
| 130 | //$query = "SELECT COUNT(*) as nb FROM schedule WHERE ident = :ident AND date_added > DATE_SUB(CURDATE(), INTERVAL 8 DAY) - 8 LIMIT 1"; |
||
| 131 | if ($globalDBdriver == 'mysql') { |
||
| 132 | $query = "SELECT COUNT(*) as nb FROM routes WHERE CallSign = :ident AND ((date_added BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)) AND DATE(NOW()) and date_modified IS NULL) OR (date_modified BETWEEN DATE(DATE_SUB(CURDATE(), INTERVAL 15 DAY)) AND DATE(NOW()))) LIMIT 1"; |
||
| 133 | } else { |
||
| 134 | $query = "SELECT COUNT(*) as nb FROM routes WHERE CallSign = :ident |
||
| 135 | AND ((date_added::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '1 MONTH' AND CURRENT_TIMESTAMP) and date_modified::timestamp IS NULL) |
||
| 136 | OR (date_modified::timestamp BETWEEN CURRENT_TIMESTAMP - INTERVAL '1 MONTH' AND CURRENT_TIMESTAMP) LIMIT 1"; |
||
| 137 | } |
||
| 138 | $query_values = array(':ident' => $ident); |
||
| 139 | try { |
||
| 140 | $sth = $this->db->prepare($query); |
||
| 141 | $sth->execute($query_values); |
||
| 142 | } catch(PDOException $e) { |
||
| 143 | return "error : ".$e->getMessage(); |
||
| 144 | } |
||
| 145 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
||
| 146 | return $row['nb']; |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Get flight info from Air France |
||
| 151 | * @param String $callsign The callsign |
||
| 152 | * @param String $date date we want flight number info |
||
| 153 | * @param String $carrier IATA code |
||
| 154 | * @return Flight departure and arrival airports and time |
||
| 155 | */ |
||
| 156 | private function getAirFrance($callsign, $date = 'NOW',$carrier = 'AF') { |
||
| 157 | $Common = new Common(); |
||
| 158 | $check_date = new Datetime($date); |
||
| 159 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
||
| 160 | if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
||
| 161 | $url = "http://www.airfrance.fr/cgi-bin/AF/FR/fr/local/resainfovol/infovols/detailsVolJson.do?codeCompagnie[0]=".$carrier."&numeroVol[0]=".$numvol."&dayFlightDate=".$check_date->format('d')."&yearMonthFlightDate=".$check_date->format('Ym'); |
||
| 162 | $json = $Common->getData($url); |
||
| 163 | |||
| 164 | $parsed_json = json_decode($json); |
||
| 165 | if (property_exists($parsed_json,'errors') === false) { |
||
| 166 | //$originLong = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originLong'}; |
||
| 167 | $originShort = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'originShort'}; |
||
| 168 | //$departureDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'departureDateMedium'}; |
||
| 169 | $departureTime = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'departureTime'}; |
||
| 170 | //$destinationLong = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'destinationLong'}; |
||
| 171 | $destinationShort = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'destinationShort'}; |
||
| 172 | //$arrivalDateMedium = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalDateMedium'}; |
||
| 173 | $arrivalTime = $parsed_json->{'flightsList'}[0]->{'segmentsList'}[0]->{'arrivalTime'}; |
||
| 174 | |||
| 175 | preg_match('/\((.*?)\)/',$originShort,$originiata); |
||
| 176 | $DepartureAirportIata = $originiata[1]; |
||
| 177 | preg_match('/\((.*?)\)/',$destinationShort,$destinationiata); |
||
| 178 | $ArrivalAirportIata = $destinationiata[1]; |
||
| 179 | |||
| 180 | /* |
||
| 181 | date_default_timezone_set('Europe/Paris'); |
||
| 182 | $departureTime = gmdate('H:i',strtotime($departureTime)); |
||
| 183 | $arrivalTime = gmdate('H:i',strtotime($arrivalTime)); |
||
| 184 | */ |
||
| 185 | |||
| 186 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_airfrance'); |
||
| 187 | } else return array(); |
||
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Get flight info from EasyJet |
||
| 192 | * @param String $callsign The callsign |
||
| 193 | * @param String $date date we want flight number info |
||
| 194 | * @return Flight departure and arrival airports and time |
||
| 195 | */ |
||
| 196 | private function getEasyJet($callsign, $date = 'NOW') { |
||
| 197 | global $globalTimezone; |
||
| 198 | $Common = new Common(); |
||
| 199 | date_default_timezone_set($globalTimezone); |
||
| 200 | $check_date = new Datetime($date); |
||
| 201 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
||
| 202 | if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
||
| 203 | $url = "http://www.easyjet.com/ft/api/flights?date=".$check_date->format('Y-m-d')."&fn=".$callsign; |
||
| 204 | $json = $Common->getData($url); |
||
| 205 | $parsed_json = json_decode($json); |
||
| 206 | |||
| 207 | $flights = $parsed_json->{'flights'}; |
||
| 208 | if (count($flights) > 0) { |
||
| 209 | $DepartureAirportIata = $parsed_json->{'flights'}[0]->{'airports'}->{'pda'}->{'iata'}; //name |
||
| 210 | $ArrivalAirportIata = $parsed_json->{'flights'}[0]->{'airports'}->{'paa'}->{'iata'}; //name |
||
| 211 | $departureTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fstd'}; |
||
| 212 | $arrivalTime = $parsed_json->{'flights'}[0]->{'dates'}->{'fsta'}; |
||
| 213 | |||
| 214 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_easyjet'); |
||
| 215 | } else return array(); |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Get flight info from Ryanair |
||
| 220 | * @param String $callsign The callsign |
||
| 221 | * @return Flight departure and arrival airports and time |
||
| 222 | */ |
||
| 223 | private function getRyanair($callsign) { |
||
| 224 | $Common = new Common(); |
||
| 225 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
||
| 226 | if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
||
| 227 | $url = "http://www.ryanair.com/fr/api/2/flight-info/0/50/"; |
||
| 228 | $post = '{"flight":"'.$numvol.'","minDepartureTime":"00:00","maxDepartureTime":"23:59"}'; |
||
| 229 | $headers = array('Content-Type: application/json','Content-Length: ' . strlen($post)); |
||
| 230 | $json = $Common->getData($url,'post',$post,$headers); |
||
| 231 | $parsed_json = json_decode($json); |
||
| 232 | if (isset($parsed_json->{'flightInfo'})) { |
||
| 233 | $flights = $parsed_json->{'flightInfo'}; |
||
| 234 | if (count($flights) > 0) { |
||
| 235 | $DepartureAirportIata = $parsed_json->{'flightInfo'}[0]->{'departureAirport'}->{'iata'}; //name |
||
| 236 | $ArrivalAirportIata = $parsed_json->{'flightInfo'}[0]->{'arrivalAirport'}->{'iata'}; //name |
||
| 237 | $departureTime = $parsed_json->{'flightInfo'}[0]->{'departureTime'}; |
||
| 238 | $arrivalTime = $parsed_json->{'flightInfo'}[0]->{'arrivalTime'}; |
||
| 239 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime, 'Source' => 'website_ryanair'); |
||
| 240 | } else return array(); |
||
| 241 | } else return array(); |
||
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Get flight info from Swiss |
||
| 246 | * @param String $callsign The callsign |
||
| 247 | * @return Flight departure and arrival airports and time |
||
| 248 | */ |
||
| 249 | private function getSwiss($callsign) { |
||
| 250 | $Common = new Common(); |
||
| 251 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
||
| 252 | if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
||
| 253 | $url = "http://www.world-of-swiss.com/fr/routenetwork.json"; |
||
| 254 | $json = $Common->getData($url); |
||
| 255 | $parsed_json = json_decode($json); |
||
| 256 | |||
| 257 | |||
| 258 | $flights = $parsed_json->{'flights'}; |
||
| 259 | if (count($flights) > 0) { |
||
| 260 | $departureTIme = ''; |
||
|
|
|||
| 261 | $arrivalTime = ''; |
||
| 262 | foreach ($flights as $flight) { |
||
| 263 | if ($flight->{'no'} == "Vol LX ".$numvol) { |
||
| 264 | $DepartureAirportIata = $flight->{'from'}->{'code'}; //city |
||
| 265 | $ArrivalAirportIata = $flight->{'to'}->{'code'}; //city |
||
| 266 | $departureTime = substr($flight->{'from'}->{'hour'},0,5); |
||
| 267 | $arrivalTime = substr($flight->{'to'}->{'hour'},0,5); |
||
| 268 | } |
||
| 269 | } |
||
| 270 | if (isset($DepartureAirportIata) && isset($ArrivalAirportIata)) { |
||
| 271 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_swiss'); |
||
| 272 | } else return array(); |
||
| 273 | } else return array(); |
||
| 274 | } |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Get flight info from British Airways API |
||
| 278 | * @param String $callsign The callsign |
||
| 279 | * @param String $date date we want flight number info |
||
| 280 | * @return Flight departure and arrival airports and time |
||
| 281 | */ |
||
| 282 | public function getBritishAirways($callsign, $date = 'NOW') { |
||
| 283 | global $globalBritishAirwaysKey; |
||
| 284 | $Common = new Common(); |
||
| 285 | $check_date = new Datetime($date); |
||
| 286 | $numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
||
| 287 | if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
||
| 288 | if ($globalBritishAirwaysKey == '') return array(); |
||
| 289 | $url = "https://api.ba.com/rest-v1/v1/flights;flightNumber=".$numvol.";scheduledDepartureDate=".$check_date->format('Y-m-d').".json"; |
||
| 290 | $headers = array('Client-Key: '.$globalBritishAirwaysKey); |
||
| 291 | $json = $Common->getData($url,'get','',$headers); |
||
| 292 | if ($json == '') return array(); |
||
| 293 | $parsed_json = json_decode($json); |
||
| 294 | $flights = $parsed_json->{'FlightsResponse'}; |
||
| 295 | if (count($flights) > 0) { |
||
| 296 | $DepartureAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'DepartureAirport'}; |
||
| 297 | $ArrivalAirportIata = $parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ArrivalAirport'}; |
||
| 298 | $departureTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledDepartureDateTime'})); |
||
| 299 | $arrivalTime = date('H:i',strtotime($parsed_json->{'FlightsResponse'}->{'Flight'}->{'Sector'}->{'ScheduledArrivalDateTime'})); |
||
| 300 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_britishairways'); |
||
| 301 | } else return array(); |
||
| 302 | } |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Get flight info from Lutfhansa API |
||
| 306 | * @param String $callsign The callsign |
||
| 307 | * @param String $date date we want flight number info |
||
| 308 | * @return Flight departure and arrival airports and time |
||
| 309 | */ |
||
| 310 | public function getLufthansa($callsign, $date = 'NOW') { |
||
| 311 | global $globalLufthansaKey; |
||
| 312 | $Common = new Common(); |
||
| 313 | $check_date = new Datetime($date); |
||
| 314 | $numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
||
| 315 | if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
||
| 316 | if (!isset($globalLufthansaKey) || $globalLufthansaKey == '' || !isset($globalLufthansaKey['key']) || $globalLufthansaKey['key'] == '') return array(); |
||
| 317 | $url = "https://api.lufthansa.com/v1/oauth/token"; |
||
| 318 | $post = array('client_id' => $globalLufthansaKey['key'],'client_secret' => $globalLufthansaKey['secret'],'grant_type' => 'client_credentials'); |
||
| 319 | $data = $Common->getData($url,'post',$post); |
||
|
1 ignored issue
–
show
|
|||
| 320 | $parsed_data = json_decode($data); |
||
| 321 | if (!isset($parsed_data->{'access_token'})) return array(); |
||
| 322 | $token = $parsed_data->{'access_token'}; |
||
| 323 | |||
| 324 | $url = "https://api.lufthansa.com/v1/operations/flightstatus/LH".$numvol."/".$check_date->format('Y-m-d'); |
||
| 325 | $headers = array('Authorization: Bearer '.$token,'Accept: application/json'); |
||
| 326 | $json = $Common->getData($url,'get','',$headers); |
||
| 327 | if ($json == '') return array(); |
||
| 328 | $parsed_json = json_decode($json); |
||
| 329 | if (isset($parsed_json->{'FlightStatusResource'}) && count($parsed_json->{'FlightStatusResource'}) > 0) { |
||
| 330 | $DepartureAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'AirportCode'}; |
||
| 331 | $departureTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Departure'}->{'ScheduledTimeLocal'}->{'DateTime'})); |
||
| 332 | $ArrivalAirportIata = $parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'AirportCode'}; |
||
| 333 | $arrivalTime = date('H:i',strtotime($parsed_json->{'FlightStatusResource'}->{'Flights'}->{'Flight'}->{'Arrival'}->{'ScheduledTimeLocal'}->{'DateTime'})); |
||
| 334 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa'); |
||
| 335 | } else return array(); |
||
| 336 | } |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Get flight info from Transavia API |
||
| 340 | * @param String $callsign The callsign |
||
| 341 | * @param String $date date we want flight number info |
||
| 342 | * @return Flight departure and arrival airports and time |
||
| 343 | */ |
||
| 344 | public function getTransavia($callsign, $date = 'NOW') { |
||
| 345 | global $globalTransaviaKey; |
||
| 346 | $Common = new Common(); |
||
| 347 | $check_date = new Datetime($date); |
||
| 348 | $numvol = sprintf('%04d',preg_replace('/^[A-Z]*/','',$callsign)); |
||
| 349 | if (!filter_var(preg_replace('/^[A-Z]*/','',$callsign),FILTER_VALIDATE_INT)) return array(); |
||
| 350 | if ($globalTransaviaKey == '') return array(); |
||
| 351 | $url = "https://tst.api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol; |
||
| 352 | //$url = "https://api.transavia.com/v1/flightstatus/departuredate/".$check_date->format('Ymd').'/flightnumber/HV'.$numvol; |
||
| 353 | $headers = array('apikey: '.$globalTransaviaKey); |
||
| 354 | $json = $Common->getData($url,'get','',$headers); |
||
| 355 | //echo 'result : '.$json; |
||
| 356 | if ($json == '') return array(); |
||
| 357 | $parsed_json = json_decode($json); |
||
| 358 | |||
| 359 | if (isset($parsed_json->{'data'}[0])) { |
||
| 360 | $DepartureAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'departureAirport'}->{'locationCode'}; |
||
| 361 | $departureTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'departureDateTime'})); |
||
| 362 | $ArrivalAirportIata = $parsed_json->{'data'}[0]->{'flight'}->{'arrivalAirport'}->{'locationCode'}; |
||
| 363 | $arrivalTime = date('H:i',strtotime($parsed_json->{'data'}[0]->{'flight'}->{'arrivalDateTime'})); |
||
| 364 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_transavia'); |
||
| 365 | } else return array(); |
||
| 366 | } |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Get flight info from Tunisair |
||
| 370 | * @param String $callsign The callsign |
||
| 371 | * @return Flight departure and arrival airports and time |
||
| 372 | */ |
||
| 373 | public function getTunisair($callsign) { |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Get flight info from Vueling |
||
| 390 | * @param String $callsign The callsign |
||
| 391 | * @return Flight departure and arrival airports and time |
||
| 392 | */ |
||
| 393 | public function getVueling($callsign,$date = 'NOW') { |
||
| 394 | $Common = new Common(); |
||
| 395 | $check_date = new Datetime($date); |
||
| 396 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
||
| 397 | if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
||
| 398 | $final_date = str_replace('/','%2F',$check_date->format('d/m/Y')); |
||
| 399 | $url = "http://www.vueling.com/Base/BaseProxy/RenderMacro/?macroalias=FlightStatusResult&searchBy=bycode&date=".$final_date."&flightNumber=".$numvol."&idioma=en-GB"; |
||
| 400 | $data = $Common->getData($url); |
||
| 401 | $data=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$data)); |
||
| 402 | if ($data != '') { |
||
| 403 | preg_match('/flightOri=[A-Z]{3}/',$data,$result); |
||
| 404 | $DepartureAirportIata = str_replace('flightOri=','',$result[0]); |
||
| 405 | preg_match('/flightDest=[A-Z]{3}/',$data,$result); |
||
| 406 | $ArrivalAirportIata = str_replace('flightDest=','',$result[0]); |
||
| 407 | if ($DepartureAirportIata != '' && $ArrivalAirportIata != '') return array('DepartureAirportIATA' => $DepartureAirportIata,'ArrivalAirportIATA' => $ArrivalAirportIata,'Source' => 'website_vueling'); |
||
| 408 | else return array(); |
||
| 409 | } |
||
| 410 | return array(); |
||
| 411 | } |
||
| 412 | |||
| 413 | /** |
||
| 414 | * Get flight info from Iberia |
||
| 415 | * @param String $callsign The callsign |
||
| 416 | * @param String $date date we want flight number info |
||
| 417 | * @return Flight departure and arrival airports and time |
||
| 418 | */ |
||
| 419 | public function getIberia($callsign, $date = 'NOW') { |
||
| 420 | $Common = new Common(); |
||
| 421 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
||
| 422 | $check_date = new Datetime($date); |
||
| 423 | if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
||
| 424 | $url = "https://www.iberia.com/web/flightDetail.do"; |
||
| 425 | $post = array('numvuelo' => $numvol,'fecha' => $check_date->format('Ymd'),'airlineID' => 'IB'); |
||
| 426 | $data = $Common->getData($url,'post',$post); |
||
|
1 ignored issue
–
show
|
|||
| 427 | if ($data != '') { |
||
| 428 | $table = $Common->table2array($data); |
||
| 429 | //print_r($table); |
||
| 430 | if (count($table) > 0) { |
||
| 431 | $flight = $table; |
||
| 432 | preg_match('/([A-Z]{3})/',$flight[3][0],$DepartureAirportIataMatch); |
||
| 433 | preg_match('/([A-Z]{3})/',$flight[5][0],$ArrivalAirportIataMatch); |
||
| 434 | $DepartureAirportIata = $DepartureAirportIataMatch[0]; |
||
| 435 | $ArrivalAirportIata = $ArrivalAirportIataMatch[0]; |
||
| 436 | $departureTime = substr(trim(str_replace(' lunes','',str_replace(' ','',$flight[3][2]))),0,5); |
||
| 437 | $arrivalTime = trim(str_replace(' lunes','',str_replace(' ','',$flight[5][1]))); |
||
| 438 | if ($arrivalTime == 'Hora estimada de llegada') { |
||
| 439 | $arrivalTime = substr(trim(str_replace(' lunes','',str_replace(' ','',$flight[5][2]))),0,5); |
||
| 440 | } else $arrivalTime = substr($arrivalTime,0,5); |
||
| 441 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_iberia'); |
||
| 442 | } |
||
| 443 | } |
||
| 444 | return array(); |
||
| 445 | } |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Get flight info from Star Alliance |
||
| 449 | * @param String $callsign The callsign |
||
| 450 | * @param String $date date we want flight number info |
||
| 451 | * @return Flight departure and arrival airports and time |
||
| 452 | */ |
||
| 453 | |||
| 454 | private function getStarAlliance($callsign, $date = 'NOW',$carrier = '') { |
||
| 481 | |||
| 482 | |||
| 483 | /** |
||
| 484 | * Get flight info from Alitalia |
||
| 485 | * @param String $callsign The callsign |
||
| 486 | * @param String $date date we want flight number info |
||
| 487 | * @return Flight departure and arrival airports and time |
||
| 488 | */ |
||
| 489 | private function getAlitalia($callsign, $date = 'NOW') { |
||
| 490 | $Common = new Common(); |
||
| 491 | $numvol = preg_replace('/^[A-Z]*/','',$callsign); |
||
| 492 | $check_date = new Datetime($date); |
||
| 493 | $url= "http://booking.alitalia.com/FlightStatus/fr_fr/FlightInfo?Brand=az&NumeroVolo=".$numvol."&DataCompleta=".$check_date->format('d/m/Y'); |
||
| 494 | if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Get flight info from Brussels airlines |
||
| 508 | * @param String $callsign The callsign |
||
| 509 | * @param String $date date we want flight number info |
||
| 510 | * @return Flight departure and arrival airports and time |
||
| 511 | */ |
||
| 512 | private function getBrussels($callsign, $date = 'NOW') { |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Get flight info from FlightRadar24 |
||
| 535 | * @param String $callsign The callsign |
||
| 536 | * @param String $date date we want flight number info |
||
| 537 | * @return Flight departure and arrival airports and time |
||
| 538 | */ |
||
| 539 | /* |
||
| 540 | public function getFlightRadar24($callsign, $date = 'NOW') { |
||
| 541 | $Common = new Common(); |
||
| 542 | $url= "http://arn.data.fr24.com/zones/fcgi/feed.js?flight=".$callsign; |
||
| 543 | $data = $Common->getData($url); |
||
| 544 | if ($data != '') { |
||
| 545 | $parsed_json = get_object_vars(json_decode($data)); |
||
| 546 | if (count($parsed_json) > 2) { |
||
| 547 | $info = array_splice($parsed_json,2,1); |
||
| 548 | $fr24id = current(array_keys($info)); |
||
| 549 | $urldata = "http://krk.data.fr24.com/_external/planedata_json.1.4.php?f=".$fr24id; |
||
| 550 | $datapl = $Common->getData($urldata); |
||
| 551 | if ($datapl != '') { |
||
| 552 | $parsed_jsonpl = json_decode($datapl); |
||
| 553 | if (isset($parsed_jsonpl->from_iata)) { |
||
| 554 | $DepartureAirportIata = $parsed_jsonpl->from_iata; |
||
| 555 | $ArrivalAirportIata = $parsed_jsonpl->to_iata; |
||
| 556 | $departureTime = date('H:i',$parsed_jsonpl->dep_schd); |
||
| 557 | $arrivalTime = date('H:i',$parsed_jsonpl->arr_schd); |
||
| 558 | return array('DepartureAirportIATA' => $DepartureAirportIata,'DepartureTime' => $departureTime,'ArrivalAirportIATA' => $ArrivalAirportIata,'ArrivalTime' => $arrivalTime,'Source' => 'website_flightradar24'); |
||
| 559 | } |
||
| 560 | } |
||
| 561 | } |
||
| 562 | } |
||
| 563 | return array(); |
||
| 564 | } |
||
| 565 | */ |
||
| 566 | /** |
||
| 567 | * Get flight info from Lufthansa |
||
| 568 | * @param String $callsign The callsign |
||
| 569 | * @param String $date date we want flight number info |
||
| 570 | * @return Flight departure and arrival airports and time |
||
| 571 | */ |
||
| 572 | |||
| 573 | /* private function getLufthansa($callsign, $date = 'NOW') { |
||
| 574 | $Common = new Common(); |
||
| 575 | */ |
||
| 576 | //$numvol = preg_replace('/^[A-Z]*/','',$callsign); |
||
| 577 | /* |
||
| 578 | $url= "http://www.lufthansa.com/fr/fr/Arrivees-Departs-fonction"; |
||
| 579 | $check_date = new Datetime($date); |
||
| 580 | if (!filter_var($numvol,FILTER_VALIDATE_INT)) return array(); |
||
| 581 | |||
| 582 | $post = array('flightNumber' => $numvol, 'date' => $check_date->format('Y-m-d'),'time' => '12:00','timezoneOffset' => '0','selection' => '0','arrivalDeparture' => 'D'); |
||
| 583 | $data = $Common->getData($url,'post',$post); |
||
| 584 | if ($data != '') { |
||
| 585 | $table = $Common->table2array($data); |
||
| 586 | $departureTime = trim(str_replace($check_date->format('d.m.Y'),'',$table[25][3])); |
||
| 587 | } |
||
| 588 | |||
| 589 | $post = array('flightNumber' => $numvol, 'date' => $check_date->format('Y-m-d'),'time' => '12:00','timezoneOffset' => '0','selection' => '0','arrivalDeparture' => 'A'); |
||
| 590 | $data = $Common->getData($url,'post',$post); |
||
| 591 | if ($data != '') { |
||
| 592 | $table = $Common->table2array($data); |
||
| 593 | $arrivalTime = trim(str_replace($check_date->format('d.m.Y'),'',$table[25][3])); |
||
| 594 | } |
||
| 595 | return array('DepartureAirportIATA' => '','DepartureTime' => $departureTime,'ArrivalAirportIATA' => '','ArrivalTime' => $arrivalTime,'Source' => 'website_lufthansa'); |
||
| 596 | } |
||
| 597 | */ |
||
| 598 | /** |
||
| 599 | * Get flight info from flytap |
||
| 600 | * @param String $callsign The callsign |
||
| 601 | * @param String $date date we want flight number info |
||
| 602 | * @return Flight departure and arrival airports and time |
||
| 603 | */ |
||
| 604 | private function getFlyTap($callsign, $date = 'NOW') { |
||
| 624 | |||
| 625 | /** |
||
| 626 | * Get flight info from flightmapper |
||
| 627 | * @param String $callsign The callsign |
||
| 628 | * @param String $date date we want flight number info |
||
| 629 | * @return Flight departure and arrival airports and time |
||
| 630 | */ |
||
| 631 | public function getFlightMapper($callsign, $date = 'NOW') { |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Get flight info from flightaware |
||
| 671 | * @param String $callsign The callsign |
||
| 672 | * @param String $date date we want flight number info |
||
| 673 | * @return Flight departure and arrival airports and time |
||
| 674 | */ |
||
| 675 | public function getFlightAware($callsign, $date = 'NOW') { |
||
| 705 | |||
| 706 | /** |
||
| 707 | * Get flight info from CostToTravel |
||
| 708 | * @param String $callsign The callsign |
||
| 709 | * @param String $date date we want flight number info |
||
| 710 | * @return Flight departure and arrival airports and time |
||
| 711 | */ |
||
| 712 | public function getCostToTravel($callsign, $date = 'NOW') { |
||
| 731 | |||
| 732 | /** |
||
| 733 | * Get flight info from Air Canada |
||
| 734 | * @param String $callsign The callsign |
||
| 735 | * @param String $date date we want flight number info |
||
| 736 | * @return Flight departure and arrival airports and time |
||
| 737 | */ |
||
| 738 | private function getAirCanada($callsign,$date = 'NOW') { |
||
| 759 | |||
| 760 | /** |
||
| 761 | * Get flight info from Vietnam Airlines |
||
| 762 | * @param String $callsign The callsign |
||
| 763 | * @param String $date date we want flight number info |
||
| 764 | * @return Flight departure and arrival airports and time |
||
| 765 | */ |
||
| 766 | private function getVietnamAirlines($callsign, $date = 'NOW') { |
||
| 785 | |||
| 786 | /** |
||
| 787 | * Get flight info from Air Berlin |
||
| 788 | * @param String $callsign The callsign |
||
| 789 | * @param String $date date we want flight number info |
||
| 790 | * @param String $carrier IATA code |
||
| 791 | * @return Flight departure and arrival airports and time |
||
| 792 | */ |
||
| 793 | private function getAirBerlin($callsign, $date = 'NOW') { |
||
| 847 | |||
| 848 | |||
| 849 | |||
| 850 | public function fetchSchedule($ident,$date = 'NOW') { |
||
| 1095 | } |
||
| 1096 | |||
| 1107 | ?> |
||
|
1 ignored issue
–
show
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.