From 75ef658d8f6f3f54927bf146f519b625c33f14e8 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 29 Aug 2018 07:27:53 +0800 Subject: [PATCH 1/2] Fix metar parsing issue --- app/Support/Metar.php | 2 +- tests/MetarTest.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Support/Metar.php b/app/Support/Metar.php index 7f48043a..2d38be5a 100644 --- a/app/Support/Metar.php +++ b/app/Support/Metar.php @@ -993,7 +993,7 @@ class Metar implements \ArrayAccess $observed['amount'] = $found[2]; } } // Cloud cover observed - elseif (isset($found[5]) && !empty($found[5])) { + elseif (isset($found[5]) && !empty($found[5]) && is_numeric($found[5])) { $observed['height'] = new Altitude($found[5] * 100, 'feet'); // Cloud height diff --git a/tests/MetarTest.php b/tests/MetarTest.php index 00c191f0..a947a7cb 100644 --- a/tests/MetarTest.php +++ b/tests/MetarTest.php @@ -82,6 +82,8 @@ class MetarTest extends TestCase { $metar = 'EGLL 261250Z AUTO 17014KT 8000 -RA BKN010/// ' .'BKN016/// OVC040/// //////TCU 13/12 Q1008 TEMPO 4000 RA'; + + $parsed = Metar::parse($metar); } public function testMetarTrends() From 525e8ba8bb06f4a3ac7c9fc2a5a3cdcef1e8de85 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 29 Aug 2018 07:58:57 +0800 Subject: [PATCH 2/2] Adding cloud height assertion --- tests/MetarTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/MetarTest.php b/tests/MetarTest.php index a947a7cb..df259a35 100644 --- a/tests/MetarTest.php +++ b/tests/MetarTest.php @@ -84,6 +84,12 @@ class MetarTest extends TestCase .'BKN016/// OVC040/// //////TCU 13/12 Q1008 TEMPO 4000 RA'; $parsed = Metar::parse($metar); + + $this->assertCount(4, $parsed['clouds']); + $this->assertEquals(1000, $parsed['clouds'][0]['height']['ft']); + $this->assertEquals(1600, $parsed['clouds'][1]['height']['ft']); + $this->assertEquals(4000, $parsed['clouds'][2]['height']['ft']); + $this->assertNull($parsed['clouds'][3]['height']['ft']); } public function testMetarTrends()