Conditions | 162 |
Paths | 0 |
Total Lines | 378 |
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 |
||
188 | public function parse($input) { |
||
189 | global $globalDebug; |
||
190 | $debug = false; |
||
191 | $result = array(); |
||
192 | $input_len = strlen($input); |
||
193 | |||
194 | /* Find the end of header checking for NULL bytes while doing it. */ |
||
195 | $splitpos = strpos($input,':'); |
||
196 | |||
197 | /* Check that end was found and body has at least one byte. */ |
||
198 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
||
199 | if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
||
200 | return false; |
||
201 | } |
||
202 | |||
203 | if ($debug) echo 'input : '.$input."\n"; |
||
204 | /* Save header and body. */ |
||
205 | $body = substr($input,$splitpos+1,$input_len); |
||
206 | $body_len = strlen($body); |
||
|
|||
207 | $header = substr($input,0,$splitpos); |
||
208 | if ($debug) echo 'header : '.$header."\n"; |
||
209 | |||
210 | /* Parse source, target and path. */ |
||
211 | //FLRDF0A52>APRS,qAS,LSTB |
||
212 | if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
||
213 | $ident = $matches[1]; |
||
214 | $all_elements = $matches[2]; |
||
215 | if ($ident == 'AIRCRAFT') { |
||
216 | $result['format_source'] = 'famaprs'; |
||
217 | $result['source_type'] = 'modes'; |
||
218 | } elseif ($ident == 'MARINE') { |
||
219 | $result['format_source'] = 'famaprs'; |
||
220 | $result['source_type'] = 'ais'; |
||
221 | } else { |
||
222 | if ($debug) echo 'ident : '.$ident."\n"; |
||
223 | $result['ident'] = $ident; |
||
224 | } |
||
225 | } else { |
||
226 | if ($debug) 'No ident'."\n"; |
||
227 | return false; |
||
228 | } |
||
229 | $elements = explode(',',$all_elements); |
||
230 | $source = end($elements); |
||
231 | $result['source'] = $source; |
||
232 | foreach ($elements as $element) { |
||
233 | if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
||
234 | //if ($element == 'TCPIP*') return false; |
||
235 | } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
||
236 | if ($debug) echo 'element : '.$element."\n"; |
||
237 | return false; |
||
238 | } |
||
239 | /* |
||
240 | } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) { |
||
241 | //echo "ok"; |
||
242 | } else { |
||
243 | return false; |
||
244 | } |
||
245 | */ |
||
246 | } |
||
247 | |||
248 | $type = substr($body,0,1); |
||
249 | if ($debug) echo 'type : '.$type."\n"; |
||
250 | if ($type == ';') { |
||
251 | if (isset($result['source_type']) && $result['source_type'] == 'modes') { |
||
252 | $result['address'] = trim(substr($body,1,9)); |
||
253 | } elseif (isset($result['source_type']) && $result['source_type'] == 'ais') { |
||
254 | $result['mmsi'] = trim(substr($body,1,9)); |
||
255 | } else $result['ident'] = trim(substr($body,1,9)); |
||
256 | } elseif ($type == ',') { |
||
257 | // Invalid data or test data |
||
258 | return false; |
||
259 | } |
||
260 | |||
261 | // Check for Timestamp |
||
262 | $find = false; |
||
263 | $body_parse = substr($body,1); |
||
264 | if (preg_match('/^;(.){9}\*/',$body,$matches)) { |
||
265 | $body_parse = substr($body_parse,10); |
||
266 | $find = true; |
||
267 | } |
||
268 | if (preg_match('/^`(.*)\//',$body,$matches)) { |
||
269 | $body_parse = substr($body_parse,strlen($matches[1])-1); |
||
270 | $find = true; |
||
271 | } |
||
272 | if (preg_match("/^'(.*)\//",$body,$matches)) { |
||
273 | $body_parse = substr($body_parse,strlen($matches[1])-1); |
||
274 | $find = true; |
||
275 | } |
||
276 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { |
||
277 | $find = true; |
||
278 | $timestamp = $matches[0]; |
||
279 | if ($matches[4] == 'h') { |
||
280 | $timestamp = strtotime(date('Ymd').' '.$matches[1].':'.$matches[2].':'.$matches[3]); |
||
281 | /* |
||
282 | if (time() + 3900 < $timestamp) $timestamp -= 86400; |
||
283 | elseif (time() - 82500 > $timestamp) $timestamp += 86400; |
||
284 | */ |
||
285 | } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
||
286 | // This work or not ? |
||
287 | $timestamp = strtotime(date('Ym').$matches[1].' '.$matches[2].':'.$matches[3]); |
||
288 | } |
||
289 | $body_parse = substr($body_parse,7); |
||
290 | $result['timestamp'] = $timestamp; |
||
291 | } |
||
292 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/',$body_parse,$matches)) { |
||
293 | $find = true; |
||
294 | $timestamp = strtotime(date('Y').$matches[1].$matches[2].' '.$matches[3].':'.$matches[4]); |
||
295 | $body_parse = substr($body_parse,8); |
||
296 | $result['timestamp'] = $timestamp; |
||
297 | } |
||
298 | //if (strlen($body_parse) > 19) { |
||
299 | if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) { |
||
300 | $find = true; |
||
301 | // 4658.70N/00707.78Ez |
||
302 | $sind = strtoupper($matches[3]); |
||
303 | $wind = strtoupper($matches[7]); |
||
304 | $lat_deg = $matches[1]; |
||
305 | $lat_min = $matches[2]; |
||
306 | $lon_deg = $matches[5]; |
||
307 | $lon_min = $matches[6]; |
||
308 | $symbolll = $matches[4]; |
||
309 | //$symbol_table = $matches[4]; |
||
310 | $lat = intval($lat_deg); |
||
311 | $lon = intval($lon_deg); |
||
312 | if ($lat > 89 || $lon > 179) return false; |
||
313 | /* |
||
314 | $tmp_5b = str_replace('.','',$lat_min); |
||
315 | if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) { |
||
316 | print_r($matches); |
||
317 | } |
||
318 | */ |
||
319 | $latitude = $lat + floatval($lat_min)/60; |
||
320 | $longitude = $lon + floatval($lon_min)/60; |
||
321 | if ($sind == 'S') $latitude = 0-$latitude; |
||
322 | if ($wind == 'W') $longitude = 0-$longitude; |
||
323 | $result['latitude'] = $latitude; |
||
324 | $result['longitude'] = $longitude; |
||
325 | $body_parse = substr($body_parse,18); |
||
326 | $body_parse_len = strlen($body_parse); |
||
327 | } |
||
328 | $body_parse_len = strlen($body_parse); |
||
329 | if ($body_parse_len > 0) { |
||
330 | /* |
||
331 | if (!isset($result['timestamp']) && !isset($result['latitude'])) { |
||
332 | $body_split = str_split($body); |
||
333 | $symbol_code = $body_split[0]; |
||
334 | $body_parse = substr($body,1); |
||
335 | $body_parse_len = strlen($body_parse); |
||
336 | } else { |
||
337 | if ($find === false) { |
||
338 | $body_split = str_split($body); |
||
339 | $symbol_code = $body_split[0]; |
||
340 | $body_parse = substr($body,1); |
||
341 | $body_parse_len = strlen($body_parse); |
||
342 | } else { |
||
343 | */ |
||
344 | if ($find) { |
||
345 | $body_split = str_split($body_parse); |
||
346 | $symbol_code = $body_split[0]; |
||
347 | if (!isset($symbolll) || $symbolll == '/') $symbol_code = '/'.$symbol_code; |
||
348 | else $symbol_code = '\\'.$symbol_code; |
||
349 | //' |
||
350 | //if ($type != ';' && $type != '>') { |
||
351 | if ($type != '') { |
||
352 | $body_parse = substr($body_parse,1); |
||
353 | $body_parse_len = strlen($body_parse); |
||
354 | $result['symbol_code'] = $symbol_code; |
||
355 | if (isset($this->symbols[$symbol_code])) $result['symbol'] = $this->symbols[$symbol_code]; |
||
356 | if ($symbol_code != '_') { |
||
357 | } |
||
358 | if ($body_parse_len >= 7) { |
||
359 | if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
||
360 | $course = substr($body_parse,0,3); |
||
361 | $tmp_s = intval($course); |
||
362 | if ($tmp_s >= 1 && $tmp_s <= 360) $result['heading'] = intval($course); |
||
363 | $speed = substr($body_parse,4,3); |
||
364 | if ($speed != '...') { |
||
365 | $result['speed'] = intval($speed); |
||
366 | } |
||
367 | $body_parse = substr($body_parse,7); |
||
368 | } |
||
369 | // Check PHGR, PHG, RNG |
||
370 | } |
||
371 | /* |
||
372 | else if ($body_parse_len > 0) { |
||
373 | $rest = $body_parse; |
||
374 | } |
||
375 | */ |
||
376 | if (strlen($body_parse) > 0) { |
||
377 | if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
||
378 | $altitude = intval($matches[1]); |
||
379 | $result['altitude'] = $altitude; |
||
380 | //$body_parse = trim(substr($body_parse,strlen($matches[0]))); |
||
381 | $body_parse = trim(preg_replace('/\\/A=(-[0-9]{5}|[0-9]{6})/','',$body_parse)); |
||
382 | } |
||
383 | } |
||
384 | // Telemetry |
||
385 | /* |
||
386 | if (preg_match('/^([0-9]+),(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,([01]{0,8})/',$body_parse,$matches)) { |
||
387 | // Nothing yet... |
||
388 | } |
||
389 | */ |
||
390 | // DAO |
||
391 | if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
||
392 | $dao = $matches[1]; |
||
393 | if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
||
394 | $dao_split = str_split($dao); |
||
395 | $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
||
396 | $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
||
397 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
||
398 | else $result['latitude'] += $lat_off; |
||
399 | if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
||
400 | else $result['longitude'] += $lon_off; |
||
401 | } |
||
402 | $body_parse = substr($body_parse,6); |
||
403 | } |
||
404 | if (preg_match('/CS=([0-9A-Z_]*)/',$body_parse,$matches)) { |
||
405 | $result['ident'] = str_replace('_',' ',$matches[1]); |
||
406 | } |
||
407 | if (preg_match('/SQ=([0-9]{4})/',$body_parse,$matches)) { |
||
408 | $result['squawk'] = $matches[1]; |
||
409 | } |
||
410 | if (preg_match('/AI=([0-9A-Z]{4})/',$body_parse,$matches)) { |
||
411 | $result['aircraft_icao'] = $matches[1]; |
||
412 | } |
||
413 | if (preg_match('/VR=([-0-9]*)/',$body_parse,$matches)) { |
||
414 | $result['verticalrate'] = $matches[1]; |
||
415 | } |
||
416 | if (preg_match('/TI=([0-9]*)/',$body_parse,$matches)) { |
||
417 | $result['typeid'] = $matches[1]; |
||
418 | } |
||
419 | if (preg_match('/SI=([0-9]*)/',$body_parse,$matches)) { |
||
420 | $result['statusid'] = $matches[1]; |
||
421 | } |
||
422 | if (preg_match('/IMO=([0-9]{7})/',$body_parse,$matches)) { |
||
423 | $result['imo'] = $matches[1]; |
||
424 | } |
||
425 | if (preg_match('/AD=([0-9]*)/',$body_parse,$matches)) { |
||
426 | $result['arrival_date'] = $matches[1]; |
||
427 | } |
||
428 | if (preg_match('/AC=([0-9A-Z_]*)/',$body_parse,$matches)) { |
||
429 | $result['arrival_code'] = str_replace('_',' ',$matches[1]); |
||
430 | } |
||
431 | // OGN comment |
||
432 | //if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
||
433 | if (preg_match('/^id([0-9A-F]{8})/',$body_parse,$matches)) { |
||
434 | $id = $matches[1]; |
||
435 | //$mode = substr($id,0,2); |
||
436 | $address = substr($id,2); |
||
437 | $addressType = (intval(substr($id,0,2),16))&3; |
||
438 | if ($addressType == 0) $result['addresstype'] = "RANDOM"; |
||
439 | elseif ($addressType == 1) $result['addresstype'] = "ICAO"; |
||
440 | elseif ($addressType == 2) $result['addresstype'] = "FLARM"; |
||
441 | elseif ($addressType == 3) $result['addresstype'] = "OGN"; |
||
442 | $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); |
||
443 | $result['aircrafttype_code'] = $aircraftType; |
||
444 | if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; |
||
445 | elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; |
||
446 | elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE"; |
||
447 | elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
||
448 | elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE"; |
||
449 | elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE"; |
||
450 | elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER"; |
||
451 | elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER"; |
||
452 | elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
||
453 | elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT"; |
||
454 | elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO"; |
||
455 | elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON"; |
||
456 | elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; |
||
457 | elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; |
||
458 | elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; |
||
459 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
||
460 | $result['stealth'] = $stealth; |
||
461 | $result['address'] = $address; |
||
462 | } |
||
463 | //Comment |
||
464 | $result['comment'] = trim($body_parse); |
||
465 | // parse weather |
||
466 | if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
||
467 | $result['wind_dir'] = intval($matches[1]); |
||
468 | $result['wind_speed'] = round(intval($matches[2])*1.60934,1); |
||
469 | $result['wind_gust'] = round(intval($matches[3])*1.60934,1); |
||
470 | $result['temp'] = round(5/9*((intval($matches[4]))-32),1); |
||
471 | $body_parse = substr($body_parse,strlen($matches[0])+1); |
||
472 | } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
||
473 | $result['wind_dir'] = intval($matches[1]); |
||
474 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
||
475 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
||
476 | $result['temp'] = round(5/9*(($matches[4])-32),1); |
||
477 | $body_parse = substr($body_parse,strlen($matches[0])+1); |
||
478 | } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
||
479 | $result['wind_dir'] = intval($matches[1]); |
||
480 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
||
481 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
||
482 | $body_parse = substr($body_parse,strlen($matches[0])+1); |
||
483 | } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
||
484 | $result['wind_dir'] = intval($matches[1]); |
||
485 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
||
486 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
||
487 | $body_parse = substr($body_parse,strlen($matches[0])+1); |
||
488 | } |
||
489 | // temperature |
||
490 | //g012t088r000p000P000h38b10110 |
||
491 | //g011t086r000p000P000h29b10198 |
||
492 | if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3,4})r([0-9 \\.]{3})p([0-9 \\.]{3})P([0-9 \\.]{3})h([0-9 \\.]{2,3})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
||
493 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
||
494 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
||
495 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
||
496 | if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1,1); |
||
497 | if ($matches[5] != '...') $result['precipitation24h'] = round((intval($matches[5])/100)*25.1,1); |
||
498 | if ($matches[6] != '...') $result['humidity'] = intval($matches[6]); |
||
499 | if ($matches[7] != '...') $result['pressure'] = round((intval($matches[7])/10),1); |
||
500 | $body_parse = substr($body_parse,strlen($matches[0])); |
||
501 | } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3,4})r([0-9 \\.]{3})P([0-9 \\.]{3})p([0-9 \\.]{3})h([0-9 \\.]{2,3})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
||
502 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
||
503 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
||
504 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
||
505 | if ($matches[5] != '...') $result['precipitation'] = round((intval($matches[5])/100)*25.1,1); |
||
506 | if ($matches[4] != '...') $result['precipitation24h'] = round((intval($matches[4])/100)*25.1,1); |
||
507 | if ($matches[6] != '...') $result['humidity'] = intval($matches[6]); |
||
508 | if ($matches[7] != '...') $result['pressure'] = round((intval($matches[7])/10),1); |
||
509 | $body_parse = substr($body_parse,strlen($matches[0])); |
||
510 | } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})P([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/',$body_parse,$matches)) { |
||
511 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
||
512 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
||
513 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
||
514 | if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1,1); |
||
515 | if ($matches[5] != '...') $result['precipitation24h'] = round((intval($matches[5])/100)*25.1,1); |
||
516 | if ($matches[7] != '...') $result['humidity'] = intval($matches[7]); |
||
517 | if ($matches[6] != '...') $result['pressure'] = round((intval($matches[6])/10),1); |
||
518 | $body_parse = substr($body_parse,strlen($matches[0])); |
||
519 | } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})P([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/',$body_parse,$matches)) { |
||
520 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
||
521 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
||
522 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
||
523 | if ($matches[4] != '...') $result['precipitation24h'] = round((intval($matches[4])/100)*25.1,1); |
||
524 | if ($matches[6] != '...') $result['humidity'] = intval($matches[6]); |
||
525 | if ($matches[5] != '...') $result['pressure'] = round((intval($matches[5])/10),1); |
||
526 | $body_parse = substr($body_parse,strlen($matches[0])); |
||
527 | } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})b([0-9 \\.]{5})h([0-9 \\.]{2})/',$body_parse,$matches)) { |
||
528 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
||
529 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
||
530 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
||
531 | if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1,1); |
||
532 | if ($matches[6] != '...') $result['humidity'] = intval($matches[6]); |
||
533 | if ($matches[5] != '...') $result['pressure'] = round((intval($matches[5])/10),1); |
||
534 | $body_parse = substr($body_parse,strlen($matches[0])); |
||
535 | } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{3})p([0-9 \\.]{3})h([0-9 \\.]{2})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
||
536 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
||
537 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
||
538 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
||
539 | if ($matches[4] != '...') $result['precipitation'] = round((intval($matches[4])/100)*25.1,1); |
||
540 | if ($matches[5] != '...') $result['humidity'] = intval($matches[5]); |
||
541 | if ($matches[6] != '...') $result['pressure'] = round((intval($matches[6])/10),1); |
||
542 | $body_parse = substr($body_parse,strlen($matches[0])); |
||
543 | } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})h([0-9 \\.]{2})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
||
544 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
||
545 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
||
546 | if ($matches[2] != '...') $result['humidity'] = intval($matches[3]); |
||
547 | if ($matches[4] != '...') $result['pressure'] = round((intval($matches[4])/10),1); |
||
548 | $body_parse = substr($body_parse,strlen($matches[0])); |
||
549 | } elseif (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9 \\.]{3})t([0-9 \\.]{3})r([0-9 \\.]{2,3})h([0-9 \\.]{2})b([0-9 \\.]{5})/',$body_parse,$matches)) { |
||
550 | if ($matches[1] != '...') $result['wind_gust'] = round($matches[1]*1.60934,1); |
||
551 | if ($matches[2] != '...') $result['temp'] = round(5/9*((intval($matches[2]))-32),1); |
||
552 | if ($matches[3] != '...') $result['rain'] = round((intval($matches[3])/100)*25.1,1); |
||
553 | if ($matches[4] != '...') $result['humidity'] = intval($matches[4]); |
||
554 | if ($matches[5] != '...') $result['pressure'] = round((intval($matches[5])/10),1); |
||
555 | $body_parse = substr($body_parse,strlen($matches[0])); |
||
556 | } |
||
557 | $result['comment'] = trim($body_parse); |
||
558 | } |
||
559 | } else $result['comment'] = trim($body_parse); |
||
560 | } |
||
561 | if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
||
562 | if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
||
563 | if ($debug) print_r($result); |
||
564 | return $result; |
||
565 | } |
||
566 | |||
718 | ?> |
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.