Fix for bad unit conversions in API responses

This commit is contained in:
Nabeel Shahzad
2019-09-20 09:05:09 -04:00
parent 5f9e7d5754
commit eb27c94637
10 changed files with 57 additions and 21 deletions

View File

@@ -20,8 +20,12 @@ class Altitude extends Unit
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
*/
public function __construct(float $value, string $unit)
public function __construct($value, string $unit)
{
if (empty($value)) {
$value = 0;
}
$this->unit = setting('units.altitude');
$this->instance = new Length($value, $unit);
}

View File

@@ -22,8 +22,12 @@ class Distance extends Unit
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
*/
public function __construct(float $value, string $unit)
public function __construct($value, string $unit)
{
if (empty($value)) {
$value = 0;
}
$this->unit = setting('units.distance');
$this->instance = new Length($value, $unit);
}

View File

@@ -19,8 +19,12 @@ class Fuel extends Unit
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
*/
public function __construct(float $value, string $unit)
public function __construct($value, string $unit)
{
if (empty($value)) {
$value = 0;
}
$this->unit = setting('units.fuel');
$this->instance = new Mass($value, $unit);
}

View File

@@ -19,8 +19,12 @@ class Mass extends Unit
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
*/
public function __construct(float $value, string $unit)
public function __construct($value, string $unit)
{
if (empty($value)) {
$value = 0;
}
$this->unit = setting('units.weight');
$this->instance = new MassUnit($value, $unit);
}

View File

@@ -22,8 +22,12 @@ class Pressure extends Unit
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
*/
public function __construct(float $value, string $unit)
public function __construct($value, string $unit)
{
if (empty($value)) {
$value = 0;
}
$this->unit = setting('units.temperature');
$this->instance = new PressureUnit($value, $unit);
}

View File

@@ -22,8 +22,12 @@ class Temperature extends Unit
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
*/
public function __construct(float $value, string $unit)
public function __construct($value, string $unit)
{
if (empty($value)) {
$value = 0;
}
$this->unit = setting('units.temperature');
$this->instance = new TemperatureUnit($value, $unit);
}

View File

@@ -22,8 +22,12 @@ class Velocity extends Unit
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
*/
public function __construct(float $value, string $unit)
public function __construct($value, string $unit)
{
if (empty($value)) {
$value = 0;
}
$this->unit = setting('units.speed');
$this->instance = new VelocityUnit($value, $unit);
}

View File

@@ -22,8 +22,12 @@ class Volume extends Unit
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
*/
public function __construct(float $value, string $unit)
public function __construct($value, string $unit)
{
if (empty($value)) {
$value = 0;
}
$this->unit = setting('units.volume');
$this->instance = new VolumeUnit($value, $unit);
}