Conditions | 50 |
Paths | 12 |
Total Lines | 187 |
Code Lines | 114 |
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 |
||
80 | public function parse($data) { |
||
81 | //$data = str_replace(array('\n','\r','\r','\n'),'',$data); |
||
82 | $codes = implode('|', array_keys($this->texts)); |
||
83 | $regWeather = '#^(\+|\-|VC)?(' . $codes . ')(' . $codes . ')?$#'; |
||
84 | //$pieces = explode(' ',$data); |
||
85 | $pieces = preg_split('/\s/',$data); |
||
86 | $pos = 0; |
||
87 | if ($pieces[0] == 'METAR') $pos++; |
||
88 | elseif ($pieces[0] == 'SPECI') $pos++; |
||
89 | if (strlen($pieces[$pos]) != 4) $pos++; |
||
90 | $result = array(); |
||
91 | $result['location'] = $pieces[$pos]; |
||
92 | $pos++; |
||
93 | $result['dayofmonth'] = substr($pieces[$pos],0,2); |
||
94 | $result['time'] = substr($pieces[$pos],2,4); |
||
95 | $c = count($pieces); |
||
96 | for($pos++; $pos < $c; $pos++) { |
||
97 | $piece = $pieces[$pos]; |
||
98 | if ($piece == 'RMK') break; |
||
99 | if ($piece == 'AUTO') $result['auto'] = true; |
||
100 | if ($piece == 'COR') $result['correction'] = true; |
||
101 | // Wind Speed |
||
102 | if (preg_match('#(VRB|\d\d\d)(\d\d)(?:G(\d\d))?(KT|MPS|KPH)(?: (\d{1,3})V(\d{1,3}))?$#', $piece, $matches)) { |
||
103 | $result['wind']['direction'] = (float)$matches[1]; |
||
104 | $result['wind']['unit'] = $matches[4]; |
||
105 | if ($result['wind']['unit'] == 'KT') $result['wind']['speed'] = round(((float)$matches[2])*0.51444444444,2); |
||
106 | elseif ($result['wind']['unit'] == 'KPH') $result['wind']['speed'] = round(((float)$matches[2])*1000,2); |
||
107 | elseif ($result['wind']['unit'] == 'MPS') $result['wind']['speed'] = round(((float)$matches[2]),2); |
||
108 | $result['wind']['gust'] = (float)$matches[3]; |
||
109 | $result['wind']['unit'] = $matches[4]; |
||
110 | $result['wind']['min_variation'] = array_key_exists(5,$matches) ? $matches[5] : 0; |
||
111 | $result['wind']['max_variation'] = array_key_exists(6,$matches) ? $matches[6] : 0; |
||
112 | } |
||
113 | |||
114 | /* if (preg_match('#^([0-9]{3})([0-9]{2})(G([0-9]{2}))?(KT|MPS)$#', $piece, $matches)) { |
||
115 | $result['wind_direction'] = (float)$matches[1]; |
||
116 | if ($matches[5] == 'KT') { |
||
117 | $result['speed'] = round(((float)$matches[2])*0.51444444444,2); |
||
118 | } elseif ($matches[5] == 'KPH') { |
||
119 | $result['speed'] = round(((float)$matches[2])*1000,2); |
||
120 | } elseif ($matches[5] == 'MPS') { |
||
121 | $result['speed'] = round(((float)$matches[2]),2); |
||
122 | } |
||
123 | if ($matches[3]) { |
||
124 | $result['gust'] = $matches[4]; |
||
125 | $result['gust_format'] = $matches[5]; |
||
126 | } |
||
127 | } |
||
128 | */ |
||
129 | // Temperature |
||
130 | if (preg_match('#^(M?[0-9]{2,})/(M?[0-9]{2,})$#', $piece, $matches)) { |
||
131 | $temp = (float)$matches[1]; |
||
132 | if ($matches[1]{0} == 'M') { |
||
133 | $temp = ((float)substr($matches[1], 1)) * -1; |
||
134 | } |
||
135 | $result['temperature'] = $temp; |
||
136 | $dew = (float)$matches[2]; |
||
137 | if ($matches[2]{0} == 'M') { |
||
138 | $dew = ((float)substr($matches[2], 1)) * -1; |
||
139 | } |
||
140 | $result['dew'] = $dew; |
||
141 | } |
||
142 | // QNH |
||
143 | if (preg_match('#^(A|Q)([0-9]{4})$#', $piece, $matches)) { |
||
144 | // #^(Q|A)(////|[0-9]{4})( )# |
||
145 | if ($matches[1] == 'Q') { |
||
146 | // hPa |
||
147 | $result['QNH'] = $matches[2]; |
||
148 | } else { |
||
149 | // inHg |
||
150 | $result['QNH'] = round(($matches[2] / 100)*33.86389,2); |
||
151 | } |
||
152 | /* |
||
153 | $result['QNH'] = $matches[1] == 'Q' ? $matches[2] : ($matches[2] / 100); |
||
154 | $result['QNH_format'] = $matches[1] == 'Q' ? 'hPa' : 'inHg'; |
||
155 | */ |
||
156 | } |
||
157 | /* |
||
158 | // Wind Direction |
||
159 | if (preg_match('#^([0-9]{3})V([0-9]{3})$#', $piece, $matches)) { |
||
160 | $result['wind_direction'] = $matches[1]; |
||
161 | $result['wind_direction_other'] = $matches[2]; |
||
162 | } |
||
163 | // Wind Speed Variable |
||
164 | if (preg_match('#^VRB([0-9]{2})KT$#', $piece, $matches)) { |
||
165 | $result['speed_variable'] = $matches[1]; |
||
166 | } |
||
167 | */ |
||
168 | // Visibility |
||
169 | if (preg_match('#^([0-9]{4})|(([0-9]{1,4})SM)$#', $piece, $matches)) { |
||
170 | if (isset($matches[3]) && strlen($matches[3]) > 0) { |
||
171 | $result['visibility'] = (float)$matches[3] * 1609.34; |
||
172 | } else { |
||
173 | if ($matches[1] == '9999') { |
||
174 | $result['visibility'] = '> 10000'; |
||
175 | } else { |
||
176 | $result['visibility'] = (float)$matches[1]; |
||
177 | } |
||
178 | } |
||
179 | if (preg_match('#^CAVOK$#', $piece, $matches)) { |
||
180 | $result['visibility'] = '> 10000'; |
||
181 | $result['weather'] = "CAVOK"; |
||
182 | } |
||
183 | } |
||
184 | // Cloud Coverage |
||
185 | if (preg_match('#^(SKC|CLR|FEW|SCT|BKN|OVC|VV)([0-9]{3})(CB|TCU|CU|CI)?$#', $piece, $matches)) { |
||
186 | //$this->addCloudCover($matches[1], ((float)$matches[2]) * 100, isset($matches[3]) ? $matches[3] : ''); |
||
187 | $type = $matches[1]; |
||
188 | $cloud = array(); |
||
189 | if ($type == 'SKC') $cloud['type'] = 'No cloud/Sky clear'; |
||
190 | elseif ($type == 'CLR') $cloud['type'] = 'No cloud below 12,000ft (3700m)'; |
||
191 | elseif ($type == 'NSC') $cloud['type'] = 'No significant cloud'; |
||
192 | elseif ($type == 'FEW') $cloud['type'] = 'Few'; |
||
193 | elseif ($type == 'SCT') $cloud['type'] = 'Scattered'; |
||
194 | elseif ($type == 'BKN') $cloud['type'] = 'Broken'; |
||
195 | elseif ($type == 'OVC') $cloud['type'] = 'Overcast/Full cloud coverage'; |
||
196 | elseif ($type == 'VV') $cloud['type'] = 'Vertical visibility'; |
||
197 | $cloud['type_code'] = $type; |
||
198 | $cloud['level'] = round(((float)$matches[2]) * 100 * 0.3048); |
||
199 | $cloud['significant'] = isset($matches[3]) ? $matches[3] : ''; |
||
200 | $result['cloud'][] = $cloud; |
||
201 | } |
||
202 | // RVR |
||
203 | if (preg_match('#^(R.+)/([M|P])?(\d{4})(?:V(\d+)|[UDN])?(FT)?$#', $piece, $matches)) { |
||
204 | $rvr = array(); |
||
205 | $rvr['runway'] = $matches[1]; |
||
206 | $rvr['assessment'] = $matches[2]; |
||
207 | $rvr['rvr'] = $matches[3]; |
||
208 | $rvr['rvr_max'] = array_key_exists(4,$matches) ? $matches[4] : 0; |
||
209 | $rvr['unit'] = array_key_exists(5,$matches) ? $matches[5] : ''; |
||
210 | $result['RVR'] = $rvr; |
||
211 | } |
||
212 | |||
213 | //if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
||
214 | if (preg_match('#^R(\d{2}[LRC]?)/([\d/])([\d/])([\d/]{2})([\d/]{2})$#', $piece, $matches)) { |
||
215 | //print_r($matches); |
||
216 | // https://github.com/davidmegginson/metar-taf/blob/master/Metar.php |
||
217 | $result['RVR']['runway'] = $matches[1]; |
||
218 | $result['RVR']['deposits'] = $matches[2]; |
||
219 | $result['RVR']['extent'] = $matches[3]; |
||
220 | $result['RVR']['depth'] = $matches[4]; |
||
221 | $result['RVR']['friction'] = $matches[5]; |
||
222 | } |
||
223 | if (preg_match('#^(R[A-Z0-9]{2,3})/([0-9]{4})(V([0-9]{4}))?(FT)?$#', $piece, $matches)) { |
||
224 | //echo $piece; |
||
225 | //print_r($matches); |
||
226 | if (isset($matches[5])) $range = array('exact' => (float)$matches[2], 'unit' => $matches[5] ? 'FT' : 'M'); |
||
227 | else $range = array('exact' => (float)$matches[2], 'unit' => 'M'); |
||
228 | if (isset($matches[3])) { |
||
229 | $range = Array( |
||
230 | 'from' => (float)$matches[2], |
||
231 | 'to' => (float)$matches[4], |
||
232 | 'unit' => $matches[5] ? 'FT' : 'M' |
||
233 | ); |
||
234 | } |
||
235 | $result['RVR'] = $matches[1]; |
||
236 | $result['RVR_range'] = $range; |
||
237 | } |
||
238 | // Weather |
||
239 | if (preg_match($regWeather, $piece, $matches)) { |
||
240 | $text = Array(); |
||
241 | switch ($matches[1]) { |
||
242 | case '+': |
||
243 | $text[] = 'Heavy'; |
||
244 | break; |
||
245 | case '-': |
||
246 | $text[] = 'Light'; |
||
247 | break; |
||
248 | case 'VC': |
||
249 | $text[] = 'Vicinity'; |
||
250 | break; |
||
251 | default: |
||
252 | break; |
||
253 | } |
||
254 | if (isset($matches[2])) { |
||
255 | $text[] = $this->texts[$matches[2]]; |
||
256 | } |
||
257 | if (isset($matches[3])) { |
||
258 | $text[] = $this->texts[$matches[3]]; |
||
259 | } |
||
260 | if (!isset($result['weather'])) $result['weather'] = implode(' ', $text); |
||
261 | else $result['weather'] = $result['weather'].' / '.implode(' ', $text); |
||
262 | } |
||
263 | } |
||
264 | return $result; |
||
265 | |||
266 | } |
||
267 | |||
419 | ?> |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.