Fix for bad unit conversions in API responses
This commit is contained in:
@@ -35,10 +35,8 @@ class Flight extends Response
|
||||
|
||||
$res['ident'] = $this->ident;
|
||||
|
||||
if (!empty($res['distance'])) {
|
||||
$distance = new Distance($res['distance'], config('phpvms.internal_units.distance'));
|
||||
$res['distance'] = $distance->getResponseUnits();
|
||||
}
|
||||
$distance = new Distance($res['distance'], config('phpvms.internal_units.distance'));
|
||||
$res['distance'] = $distance->getResponseUnits();
|
||||
|
||||
$res['airline'] = new Airline($this->airline);
|
||||
$res['subfleets'] = Subfleet::collection($this->subfleets);
|
||||
|
||||
@@ -24,21 +24,27 @@ class Pirep extends Response
|
||||
$res['ident'] = $this->ident;
|
||||
|
||||
// Set these to the response units
|
||||
if (!empty($res['distance'])) {
|
||||
$distance = new Distance($res['distance'], config('phpvms.internal_units.distance'));
|
||||
$res['distance'] = $distance->getResponseUnits();
|
||||
if (!array_key_exists('distance', $res)) {
|
||||
$res['distance'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($res['fuel_used'])) {
|
||||
$fuel_used = new Fuel($res['fuel_used'], config('phpvms.internal_units.fuel'));
|
||||
$res['fuel_used'] = $fuel_used->getResponseUnits();
|
||||
$distance = new Distance($res['distance'], config('phpvms.internal_units.distance'));
|
||||
$res['distance'] = $distance->getResponseUnits();
|
||||
|
||||
if (!array_key_exists('fuel_used', $res)) {
|
||||
$res['fuel_used'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($res['planned_distance'])) {
|
||||
$planned_dist = new Distance($res['planned_distance'], config('phpvms.internal_units.distance'));
|
||||
$res['planned_distance'] = $planned_dist->getResponseUnits();
|
||||
$fuel_used = new Fuel($res['fuel_used'], config('phpvms.internal_units.fuel'));
|
||||
$res['fuel_used'] = $fuel_used->getResponseUnits();
|
||||
|
||||
if (! array_key_exists('planned_distance', $res)) {
|
||||
$res['planned_distance'] = 0;
|
||||
}
|
||||
|
||||
$planned_dist = new Distance($res['planned_distance'], config('phpvms.internal_units.distance'));
|
||||
$res['planned_distance'] = $planned_dist->getResponseUnits();
|
||||
|
||||
/*
|
||||
* Relationship fields
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user