| Conditions | 23 | 
| Paths | > 20000 | 
| Total Lines | 103 | 
| Code Lines | 85 | 
| 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  | 
            ||
| 29 | 	public function getAccidentData($limit = '',$type = '',$date = '') { | 
            ||
| 30 | global $globalURL, $globalDBdriver;  | 
            ||
| 31 | $Image = new Image($this->db);  | 
            ||
| 32 | $Spotter = new Spotter($this->db);  | 
            ||
| 33 | $Translation = new Translation($this->db);  | 
            ||
| 34 | $date = filter_var($date,FILTER_SANITIZE_STRING);  | 
            ||
| 35 | 		date_default_timezone_set('UTC'); | 
            ||
| 36 | $result = array();  | 
            ||
| 37 | $limit_query = '';  | 
            ||
| 38 | if ($limit != "")  | 
            ||
| 39 | 		{ | 
            ||
| 40 | 			$limit_array = explode(",", $limit); | 
            ||
| 41 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);  | 
            ||
| 42 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);  | 
            ||
| 43 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0)  | 
            ||
| 44 | 			{ | 
            ||
| 45 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];  | 
            ||
| 46 | }  | 
            ||
| 47 | }  | 
            ||
| 48 | |||
| 49 | 		if ($type != '') { | 
            ||
| 50 | 			if ($date != '') { | 
            ||
| 51 | 				if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/",$date)) { | 
            ||
| 52 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND date = :date GROUP BY registration) ORDER BY date DESC".$limit_query;  | 
            ||
| 53 | 				} else { | 
            ||
| 54 | $date = $date.'%';  | 
            ||
| 55 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND to_char(date,'YYYY-MM-DD') LIKE :date GROUP BY registration) ORDER BY date DESC".$limit_query;  | 
            ||
| 56 | }  | 
            ||
| 57 | 				$query_values = array(':type' => $type,':date' => $date); | 
            ||
| 58 | 			} else { | 
            ||
| 59 | $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;  | 
            ||
| 60 | 				$query_values = array(':type' => $type); | 
            ||
| 61 | }  | 
            ||
| 62 | 		} else { | 
            ||
| 63 | 			if ($date != '') { | 
            ||
| 64 | 				if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/",$date)) { | 
            ||
| 65 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE date = :date GROUP BY registration) ORDER BY date DESC".$limit_query;  | 
            ||
| 66 | 				} else { | 
            ||
| 67 | $date = $date.'%';  | 
            ||
| 68 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE to_char(date,'YYYY-MM-DD') LIKE :date GROUP BY registration) ORDER BY date DESC".$limit_query;  | 
            ||
| 69 | }  | 
            ||
| 70 | 				$query_values = array(':date' => $date); | 
            ||
| 71 | 			} else { | 
            ||
| 72 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents GROUP BY registration) ORDER BY date DESC".$limit_query;  | 
            ||
| 73 | $query_values = array();  | 
            ||
| 74 | }  | 
            ||
| 75 | }  | 
            ||
| 76 | |||
| 77 | 		try { | 
            ||
| 78 | $sth = $this->db->prepare($query);  | 
            ||
| 79 | $sth->execute($query_values);  | 
            ||
| 80 | 		} catch(PDOException $e) { | 
            ||
| 81 | return "error : ".$e->getMessage();  | 
            ||
| 82 | }  | 
            ||
| 83 | $i = 0;  | 
            ||
| 84 | 		while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { | 
            ||
| 85 | $data = array();  | 
            ||
| 86 | 			if ($row['registration'] != '') { | 
            ||
| 87 | $image_array = $Image->getSpotterImage($row['registration']);  | 
            ||
| 88 | 				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'])); | 
            ||
| 89 | 				else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); | 
            ||
| 90 | $aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']);  | 
            ||
| 91 | $aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type);  | 
            ||
| 92 | 				if (!empty($aircraft_info)) { | 
            ||
| 93 | $data['aircraft_type'] = $aircraft_info[0]['icao'];  | 
            ||
| 94 | $data['aircraft_name'] = $aircraft_info[0]['type'];  | 
            ||
| 95 | $data['aircraft_manufacturer'] = $aircraft_info[0]['manufacturer'];  | 
            ||
| 96 | 				} else { | 
            ||
| 97 | 					$data = array_merge($data,array('aircraft_type' => 'NA')); | 
            ||
| 98 | }  | 
            ||
| 99 | $owner_data = $Spotter->getAircraftOwnerByRegistration($row['registration']);  | 
            ||
| 100 | 				if (!empty($owner_data)) { | 
            ||
| 101 | $data['aircraft_owner'] = $owner_data['owner'];  | 
            ||
| 102 | $data['aircraft_base'] = $owner_data['base'];  | 
            ||
| 103 | $data['aircraft_date_first_reg'] = $owner_data['date_first_reg'];  | 
            ||
| 104 | }  | 
            ||
| 105 | 			} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); | 
            ||
| 106 | if ($row['registration'] == '') $row['registration'] = 'NA';  | 
            ||
| 107 | if ($row['ident'] == '') $row['ident'] = 'NA';  | 
            ||
| 108 | $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2));  | 
            ||
| 109 | 			if (isset($identicao[0])) { | 
            ||
| 110 | 				if (substr($row['ident'],0,2) == 'AF') { | 
            ||
| 111 | 					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; | 
            ||
| 112 | else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');  | 
            ||
| 113 | } else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');  | 
            ||
| 114 | 				$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name'])); | 
            ||
| 115 | } else $icao = $row['ident'];  | 
            ||
| 116 | $icao = $Translation->checkTranslation($icao,false);  | 
            ||
| 117 | 			//$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url'])); | 
            ||
| 118 | $data = array_merge($row,$data);  | 
            ||
| 119 | if ($data['ident'] == null) $data['ident'] = $icao;  | 
            ||
| 120 | 			if ($data['title'] == null) { | 
            ||
| 121 | $data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country'];  | 
            ||
| 122 | } else $data['message'] = strtolower($data['title']);  | 
            ||
| 123 | $result[] = $data;  | 
            ||
| 124 | $i++;  | 
            ||
| 125 | }  | 
            ||
| 126 | 		if (isset($result)) { | 
            ||
| 127 | $result[0]['query_number_rows'] = $i;  | 
            ||
| 128 | return $result;  | 
            ||
| 129 | }  | 
            ||
| 130 | else return array();  | 
            ||
| 131 | }  | 
            ||
| 132 | |||
| 298 | ?>  | 
            
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.