finally fixed serialization of conversions #189
This commit is contained in:
parent
0700c96901
commit
d5c2d25c74
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user