implements ArrayAccess for casting to type #189

This commit is contained in:
Nabeel Shahzad
2018-02-10 22:04:30 -06:00
parent cb02a7c15e
commit f14a9e3ba1
9 changed files with 126 additions and 17 deletions

View File

@@ -110,7 +110,7 @@ class Pirep extends BaseModel
public function getDistanceAttribute()
{
try {
$distance = (float)$this->attributes['distance'];
$distance = (float) $this->attributes['distance'];
return new Distance($distance, 'mi');
} catch (NonNumericValue $e) {
return 0;
@@ -119,6 +119,19 @@ class Pirep extends BaseModel
}
}
/**
* Set the distance unit, convert to our internal default unit
* @param $value
*/
public function setDistanceAttribute($value): void
{
if ($value instanceof Distance) {
$this->attributes['distance'] = $value->toUnit(Distance::STORAGE_UNIT);
} else {
$this->attributes['distance'] = $value;
}
}
/**
* Return the planned_distance in a converter class
* @return int|Distance
@@ -135,6 +148,19 @@ class Pirep extends BaseModel
}
}
/**
* Set the distance unit, convert to our internal default unit
* @param $value
*/
public function setPlannedDistanceAttribute($value)
{
if ($value instanceof Distance) {
$this->attributes['distance'] = $value->toUnit(Distance::STORAGE_UNIT);
} else {
$this->attributes['distance'] = $value;
}
}
/**
* Do some cleanup on the route
* @param $route