phpvms/app/Support/Units/Altitude.php
2018-04-07 20:52:12 -05:00

31 lines
785 B
PHP

<?php
namespace App\Support\Units;
use App\Interfaces\Unit;
use PhpUnitsOfMeasure\PhysicalQuantity\Length;
/**
* @package App\Support\Units
*/
class Altitude extends Unit
{
/**
* @param float $value
* @param string $unit
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
*/
public function __construct(float $value, string $unit)
{
$this->unit = setting('units.altitude');
$this->instance = new Length($value, $unit);
$this->units = [
'm' => round($this->instance->toUnit('meters'), 2),
'km' => round($this->instance->toUnit('meters') / 1000, 2),
'ft' => round($this->instance->toUnit('feet'), 2),
];
}
}