Conditions | 19 |
Paths | 6936 |
Total Lines | 83 |
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 |
||
29 | public function getLatestAccidentData($limit = '',$type = '') { |
||
30 | global $globalURL, $globalDBdriver; |
||
31 | $Image = new Image($this->db); |
||
32 | $Spotter = new Spotter($this->db); |
||
33 | $Translation = new Translation($this->db); |
||
34 | date_default_timezone_set('UTC'); |
||
35 | $result = array(); |
||
36 | $limit_query = ''; |
||
37 | if ($limit != "") |
||
38 | { |
||
39 | $limit_array = explode(",", $limit); |
||
40 | $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
||
41 | $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
||
42 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
||
43 | { |
||
44 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
||
45 | } |
||
46 | } |
||
47 | |||
48 | if ($type != '') { |
||
49 | $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; |
||
50 | $query_values = array(':type' => $type); |
||
51 | } else { |
||
52 | //$query = "SELECT * FROM accidents GROUP BY registration ORDER BY date DESC".$limit_query; |
||
53 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents GROUP BY registration) ORDER BY date DESC".$limit_query; |
||
54 | $query_values = array(); |
||
55 | } |
||
56 | |||
57 | try { |
||
58 | $sth = $this->db->prepare($query); |
||
59 | $sth->execute($query_values); |
||
60 | } catch(PDOException $e) { |
||
61 | return "error : ".$e->getMessage(); |
||
62 | } |
||
63 | $i = 0; |
||
64 | while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { |
||
65 | $data = array(); |
||
66 | if ($row['registration'] != '') { |
||
67 | $image_array = $Image->getSpotterImage($row['registration']); |
||
68 | 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'])); |
||
69 | else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
||
70 | $aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']); |
||
71 | $aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type); |
||
72 | if (!empty($aircraft_info)) { |
||
73 | $data['aircraft_type'] = $aircraft_info[0]['icao']; |
||
74 | $data['aircraft_name'] = $aircraft_info[0]['type']; |
||
75 | $data['aircraft_manufacturer'] = $aircraft_info[0]['manufacturer']; |
||
76 | } else { |
||
77 | $data = array_merge($data,array('aircraft_type' => 'NA')); |
||
78 | } |
||
79 | $owner_data = $Spotter->getAircraftOwnerByRegistration($row['registration']); |
||
80 | if (!empty($owner_data)) { |
||
81 | $data['aircraft_owner'] = $owner_data['owner']; |
||
82 | $data['aircraft_base'] = $owner_data['base']; |
||
83 | $data['aircraft_date_first_reg'] = $owner_data['date_first_reg']; |
||
84 | } |
||
85 | } else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
||
86 | if ($row['registration'] == '') $row['registration'] = 'NA'; |
||
87 | if ($row['ident'] == '') $row['ident'] = 'NA'; |
||
88 | $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2)); |
||
89 | if (isset($identicao[0])) { |
||
90 | if (substr($row['ident'],0,2) == 'AF') { |
||
91 | if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; |
||
92 | else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); |
||
93 | } else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); |
||
94 | $data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name'])); |
||
95 | } else $icao = $row['ident']; |
||
96 | $icao = $Translation->checkTranslation($icao,false); |
||
97 | //$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url'])); |
||
98 | $data = array_merge($row,$data); |
||
99 | if ($data['ident'] == null) $data['ident'] = $icao; |
||
100 | if ($data['title'] == null) { |
||
101 | $data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country']; |
||
102 | } else $data['message'] = strtolower($data['title']); |
||
103 | $result[] = $data; |
||
104 | $i++; |
||
105 | } |
||
106 | if (isset($result)) { |
||
107 | $result[0]['query_number_rows'] = $i; |
||
108 | return $result; |
||
109 | } |
||
110 | else return array(); |
||
111 | } |
||
112 | |||
261 | ?> |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.