diff --git a/app/Http/Resources/Flight.php b/app/Http/Resources/Flight.php index aaeba142..c18918d7 100644 --- a/app/Http/Resources/Flight.php +++ b/app/Http/Resources/Flight.php @@ -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); diff --git a/app/Http/Resources/Pirep.php b/app/Http/Resources/Pirep.php index 2d14c62d..42706e21 100644 --- a/app/Http/Resources/Pirep.php +++ b/app/Http/Resources/Pirep.php @@ -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 */ diff --git a/app/Support/Units/Altitude.php b/app/Support/Units/Altitude.php index d0c96b3a..8ddfa6ee 100644 --- a/app/Support/Units/Altitude.php +++ b/app/Support/Units/Altitude.php @@ -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); } diff --git a/app/Support/Units/Distance.php b/app/Support/Units/Distance.php index 77ac51d9..4e7c4b83 100644 --- a/app/Support/Units/Distance.php +++ b/app/Support/Units/Distance.php @@ -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); } diff --git a/app/Support/Units/Fuel.php b/app/Support/Units/Fuel.php index 204c7915..f76ea118 100644 --- a/app/Support/Units/Fuel.php +++ b/app/Support/Units/Fuel.php @@ -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); } diff --git a/app/Support/Units/Mass.php b/app/Support/Units/Mass.php index 5bfded97..99249d71 100644 --- a/app/Support/Units/Mass.php +++ b/app/Support/Units/Mass.php @@ -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); } diff --git a/app/Support/Units/Pressure.php b/app/Support/Units/Pressure.php index 6d6c7580..58899580 100644 --- a/app/Support/Units/Pressure.php +++ b/app/Support/Units/Pressure.php @@ -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); } diff --git a/app/Support/Units/Temperature.php b/app/Support/Units/Temperature.php index 279252fe..1343d0e7 100644 --- a/app/Support/Units/Temperature.php +++ b/app/Support/Units/Temperature.php @@ -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); } diff --git a/app/Support/Units/Velocity.php b/app/Support/Units/Velocity.php index e14197dc..a13b4e3e 100644 --- a/app/Support/Units/Velocity.php +++ b/app/Support/Units/Velocity.php @@ -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); } diff --git a/app/Support/Units/Volume.php b/app/Support/Units/Volume.php index 55fc121b..3a6fd3e8 100644 --- a/app/Support/Units/Volume.php +++ b/app/Support/Units/Volume.php @@ -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); }