public function parse($remaining_taf, $cavok = false) { $result = $this->consume($remaining_taf); $found = $result['found']; $new_remaining_taf = $result['remaining']; // handle the case where nothing has been found and taf is not cavok if ($found == null && !$cavok) { throw new ChunkDecoderException($remaining_taf, $new_remaining_taf, 'Bad format for clouds information', $this); } // default case: CAVOK or clear sky, no cloud layer $result = array('clouds' => array()); // there are clouds, handle cloud layers and visibility if ($found != null && $found[2] == null) { for ($i = 3; $i <= 15; $i += 4) { if (trim($found[$i]) != null) { $layer = new CloudLayer(); $layer_height = Value::toInt($found[$i + 2]); if ($layer_height !== null) { $layer_height_ft = $layer_height * 100; } else { $layer_height_ft = null; } $layer->setAmount($found[$i + 1])->setBaseHeight(Value::newValue($layer_height_ft, Value::FEET))->setType($found[$i + 3]); $result['clouds'][] = $layer; } } } // return result + remaining taf return array('result' => $result, 'remaining_taf' => $new_remaining_taf); }
public function parse($remaining_taf, $cavok = false) { $result = $this->consume($remaining_taf); $found = $result['found']; $new_remaining_taf = $result['remaining']; // handle the case where nothing has been found if ($found == null) { throw new ChunkDecoderException($remaining_taf, $new_remaining_taf, 'Bad format for visibility information', $this); } if ($found[1] == 'CAVOK') { // ceiling and visibility OK $cavok = true; $visibility = null; } elseif ($found[1] == '////') { // information not available $cavok = false; $visibility = null; } else { $cavok = false; $visibility = new Visibility(); if (trim($found[2]) != null) { // icao visibility $visibility->setVisibility(Value::newIntValue($found[2], Value::METER)); } else { // us visibility $main = intval($found[4]); $is_greater = $found[3] === 'P' ? true : false; $frac_top = intval($found[6]); $frac_bot = intval($found[7]); if ($frac_bot != 0) { $vis_value = $main + $frac_top / $frac_bot; } else { $vis_value = $main; } $visibility->setVisibility(Value::newValue($vis_value, Value::STATUTE_MILE)); $visibility->setGreater($is_greater); } } $result = array('cavok' => $cavok, 'visibility' => $visibility); // return result + remaining taf return array('result' => $result, 'remaining_taf' => $new_remaining_taf); }
/** * Test invalid values */ public function testValueErrors() { $newValue = new Value(null, null); $this->assertNull($newValue->getValue()); $this->assertNull($newValue->newValue(null, null)); $this->assertNull($newValue->newIntValue('AB', null)->getValue()); }