Cleanup SI Unit classes and interface for REST responses; fixes to a few METAR parsing issues

This commit is contained in:
Nabeel Shahzad
2019-07-15 15:14:40 -04:00
parent 466d04caf7
commit 06d8f11ca3
33 changed files with 399 additions and 222 deletions

View File

@@ -20,18 +20,19 @@ class Unit implements ArrayAccess
/**
* All of the units of this class
*
* @var array
*/
public $units;
/**
* Holds an instance of the PhpUnit type
*
* @var
*/
protected $instance;
/**
* Units that are included as part of the REST response
*/
public $responseUnits = [];
/**
* @return mixed
*/
@@ -40,6 +41,31 @@ class Unit implements ArrayAccess
return $this->__toString();
}
/**
* Just call toUnit() on the PhpUnitOfMeasure instance
*
* @param string $unit
*
* @return mixed
*/
public function toUnit($unit)
{
return $this->instance->toUnit($unit);
}
/**
* Return all of the units that get sent back in a response
*/
public function getResponseUnits(): array
{
$response = [];
foreach ($this->responseUnits as $unit) {
$response[$unit] = $this[$unit];
}
return $response;
}
/**
* Implements ArrayAccess
*
@@ -61,7 +87,7 @@ class Unit implements ArrayAccess
*/
public function offsetGet($offset)
{
return $this->units[$offset];
return round($this->instance->toUnit($offset), 2);
}
/**
@@ -72,7 +98,7 @@ class Unit implements ArrayAccess
*/
public function offsetSet($offset, $value)
{
$this->units[$offset] = $value;
// $this->units[$offset] = $value;
}
/**
@@ -82,7 +108,7 @@ class Unit implements ArrayAccess
*/
public function offsetUnset($offset)
{
$this->units[$offset] = null;
// $this->units[$offset] = null;
}
/**