Fix METAR parsing for runway visibility

This commit is contained in:
Nabeel Shahzad 2018-09-01 16:58:38 -04:00
parent aba23f99bd
commit 8171d681a6
2 changed files with 16 additions and 11 deletions

View File

@ -751,6 +751,7 @@ class Metar implements \ArrayAccess
* *
* @param mixed $part * @param mixed $part
* *
* @return bool
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName * @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue * @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
*/ */
@ -912,20 +913,15 @@ class Metar implements \ArrayAccess
if (!empty($observed['runway'])) { if (!empty($observed['runway'])) {
$report = []; $report = [];
if ($observed['variable'] !== null) { if ($observed['variable'] !== null) {
$unit = ' meters'; $report[] = $observed['variable']['nmi'].' nmi';
if ($observed['variable'] <= 1) { } elseif ($observed['interval_min'] !== null && $observed['interval_max'] !== null) {
$unit = ' meter';
}
$report[] = $observed['variable'].$unit;
} elseif (null !== $observed['interval_min'] && null !== $observed['interval_max']) {
if (isset(static::$rvr_prefix_codes[$observed['variable_prefix']])) { if (isset(static::$rvr_prefix_codes[$observed['variable_prefix']])) {
$report[] = 'varying from a min. of '.$observed['interval_min'].' meters until a max. of '. $report[] = 'varying from a min. of '.$observed['interval_min']['nmi'].' nmi until a max. of '.
static::$rvr_prefix_codes[$observed['variable_prefix']].' that '. static::$rvr_prefix_codes[$observed['variable_prefix']].' that '.
$observed['interval_max'].' meters'; $observed['interval_max']['nmi'].' nmi';
} else { } else {
$report[] = 'varying from a min. of '.$observed['interval_min'].' meters until a max. of '. $report[] = 'varying from a min. of '.$observed['interval_min']['nmi'].' nmi until a max. of '.
$observed['interval_max'].' meters'; $observed['interval_max']['nmi'].' nmi';
} }
} }

View File

@ -92,6 +92,15 @@ class MetarTest extends TestCase
$this->assertNull($parsed['clouds'][3]['height']['ft']); $this->assertNull($parsed['clouds'][3]['height']['ft']);
} }
public function testMetar3()
{
$metar = 'LEBL 310337Z 24006G18KT 210V320 1000 '
.'R25R/P2000 R07L/1900N R07R/1700D R25L/1900N '
.'+TSRA SCT006 BKN015 SCT030CB 22/21 Q1018 NOSIG';
$parsed = Metar::parse($metar);
}
public function testMetarTrends() public function testMetarTrends()
{ {
$metar = $metar =