| Conditions | 19 |
| Paths | 6936 |
| Total Lines | 90 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 30 | public function getLatestAccidentData($limit = '',$type = '') { |
||
| 31 | global $globalURL, $globalDBdriver; |
||
| 32 | $Image = new Image($this->db); |
||
| 33 | $Spotter = new Spotter($this->db); |
||
| 34 | $Translation = new Translation($this->db); |
||
| 35 | date_default_timezone_set('UTC'); |
||
| 36 | $result = array(); |
||
| 37 | $limit_query = ''; |
||
| 38 | if ($limit != "") |
||
| 39 | { |
||
| 40 | $limit_array = explode(",", $limit); |
||
| 41 | |||
| 42 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
| 43 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
| 44 | |||
| 45 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
| 46 | { |
||
| 47 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | if ($type != '') { |
||
| 52 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type GROUP BY registration) ORDER BY date DESC".$limit_query; |
||
| 53 | $query_values = array(':type' => $type); |
||
| 54 | } else { |
||
| 55 | //$query = "SELECT * FROM accidents GROUP BY registration ORDER BY date DESC".$limit_query; |
||
| 56 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents GROUP BY registration) ORDER BY date DESC".$limit_query; |
||
| 57 | $query_values = array(); |
||
| 58 | } |
||
| 59 | try { |
||
| 60 | |||
| 61 | $sth = $this->db->prepare($query); |
||
| 62 | $sth->execute($query_values); |
||
| 63 | } catch(PDOException $e) { |
||
| 64 | return "error : ".$e->getMessage(); |
||
| 65 | } |
||
| 66 | $i = 0; |
||
| 67 | while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { |
||
| 68 | $data = array(); |
||
| 69 | if ($row['registration'] != '') { |
||
| 70 | // $row['registration'] = str_replace('.','',$row['registration']); |
||
| 71 | $image_array = $Image->getSpotterImage($row['registration']); |
||
| 72 | if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website'])); |
||
| 73 | else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
||
| 74 | $aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']); |
||
| 75 | $aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type); |
||
| 76 | //echo $row['registration']; |
||
| 77 | //print_r($aircraft_info); |
||
| 78 | if (!empty($aircraft_info)) { |
||
| 79 | //echo 'ok!!!'; |
||
| 80 | $data['aircraft_type'] = $aircraft_info[0]['icao']; |
||
| 81 | $data['aircraft_name'] = $aircraft_info[0]['type']; |
||
| 82 | $data['aircraft_manufacturer'] = $aircraft_info[0]['manufacturer']; |
||
| 83 | } else { |
||
| 84 | $data = array_merge($data,array('aircraft_type' => 'NA')); |
||
| 85 | } |
||
| 86 | $owner_data = $Spotter->getAircraftOwnerByRegistration($row['registration']); |
||
| 87 | if (!empty($owner_data)) { |
||
| 88 | $data['aircraft_owner'] = $owner_data['owner']; |
||
| 89 | $data['aircraft_base'] = $owner_data['base']; |
||
| 90 | $data['aircraft_date_first_reg'] = $owner_data['date_first_reg']; |
||
| 91 | } |
||
| 92 | } else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
||
| 93 | if ($row['registration'] == '') $row['registration'] = 'NA'; |
||
| 94 | if ($row['ident'] == '') $row['ident'] = 'NA'; |
||
| 95 | $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2)); |
||
| 96 | if (isset($identicao[0])) { |
||
| 97 | if (substr($row['ident'],0,2) == 'AF') { |
||
| 98 | if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; |
||
| 99 | else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); |
||
| 100 | } else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); |
||
| 101 | |||
| 102 | $data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name'])); |
||
| 103 | } else $icao = $row['ident']; |
||
| 104 | $icao = $Translation->checkTranslation($icao,false); |
||
| 105 | //$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url'])); |
||
| 106 | $data = array_merge($row,$data); |
||
| 107 | if ($data['ident'] == null) $data['ident'] = $icao; |
||
| 108 | if ($data['title'] == null) { |
||
| 109 | $data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country']; |
||
| 110 | } else $data['message'] = strtolower($data['title']); |
||
| 111 | $result[] = $data; |
||
| 112 | $i++; |
||
| 113 | } |
||
| 114 | if (isset($result)) { |
||
| 115 | $result[0]['query_number_rows'] = $i; |
||
| 116 | return $result; |
||
| 117 | } |
||
| 118 | else return array(); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | ?> |