diff --git a/app/Http/Resources/Flight.php b/app/Http/Resources/Flight.php index 45c59d28..f7e41a49 100644 --- a/app/Http/Resources/Flight.php +++ b/app/Http/Resources/Flight.php @@ -12,7 +12,7 @@ class Flight extends Resource $flight = parent::toArray($request); // Return multiple measures so the client can pick what they want - if(filled($this->distance) && $this->distance instanceof Distance) { + if($this->distance instanceof Distance) { $flight['distance'] = $this->distance->toObject(); } diff --git a/app/Http/Resources/Pirep.php b/app/Http/Resources/Pirep.php index aaa498f0..3b6191b4 100644 --- a/app/Http/Resources/Pirep.php +++ b/app/Http/Resources/Pirep.php @@ -17,11 +17,11 @@ class Pirep extends Resource { $pirep = parent::toArray($request); - if (filled($this->distance) && $this->distance instanceof Distance) { + if ($this->distance instanceof Distance) { $pirep['distance'] = $this->distance->toObject(); } - if (filled($this->planned_distance) && $this->planned_distance instanceof Distance) { + if ($this->planned_distance instanceof Distance) { $pirep['planned_distance'] = $this->planned_distance->toObject(); } diff --git a/app/Models/Flight.php b/app/Models/Flight.php index 874a5c12..e674a469 100644 --- a/app/Models/Flight.php +++ b/app/Models/Flight.php @@ -79,6 +79,10 @@ class Flight extends BaseModel */ public function getDistanceAttribute() { + if (!array_key_exists('distance', $this->attributes)) { + return null; + } + try { $distance = (float) $this->attributes['distance']; return new Distance($distance, Distance::STORAGE_UNIT); diff --git a/app/Models/Pirep.php b/app/Models/Pirep.php index 31b41fc7..8be11dba 100644 --- a/app/Models/Pirep.php +++ b/app/Models/Pirep.php @@ -109,6 +109,10 @@ class Pirep extends BaseModel */ public function getDistanceAttribute() { + if(!array_key_exists('distance', $this->attributes)) { + return null; + } + try { $distance = (float) $this->attributes['distance']; return new Distance($distance, Distance::STORAGE_UNIT); @@ -138,6 +142,10 @@ class Pirep extends BaseModel */ public function getPlannedDistanceAttribute() { + if (!array_key_exists('planned_distance', $this->attributes)) { + return null; + } + try { $distance = (float) $this->attributes['planned_distance']; return new Distance($distance, Distance::STORAGE_UNIT); diff --git a/tests/AcarsTest.php b/tests/AcarsTest.php index 715bf979..3de29f85 100644 --- a/tests/AcarsTest.php +++ b/tests/AcarsTest.php @@ -134,7 +134,7 @@ class AcarsTest extends TestCase $this->assertEquals('custom_field', $pirep['fields'][0]['name']); $this->assertEquals('custom_value', $pirep['fields'][0]['value']); - $this->assertHasKeys($pirep['distance'], ['mi', 'nmi', 'km']); + $this->assertHasKeys($pirep['planned_distance'], ['mi', 'nmi', 'km']); /** * Update the custom field diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 3ffc0836..c1ed7823 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -9,9 +9,6 @@ class UtilsTest extends TestCase public function testSecondsToTimeParts() { - $t = new \PhpUnitsOfMeasure\PhysicalQuantity\Time(65, 'm'); - echo $t->toUnit('hours'); - $t = Utils::secondsToTimeParts(3600); $this->assertEquals(['h' => 1, 'm' => 0, 's' => 0], $t);