implements ArrayAccess for casting to type #189
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Units;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
|
||||
/**
|
||||
* Wrap the converter class
|
||||
* @package App\Support\Units
|
||||
*/
|
||||
class Distance extends \PhpUnitsOfMeasure\PhysicalQuantity\Length
|
||||
class Distance extends \PhpUnitsOfMeasure\PhysicalQuantity\Length implements Arrayable
|
||||
{
|
||||
/**
|
||||
* The unit that this is stored as
|
||||
@@ -26,7 +27,7 @@ class Distance extends \PhpUnitsOfMeasure\PhysicalQuantity\Length
|
||||
/**
|
||||
* For the HTTP Resource call
|
||||
*/
|
||||
public function toJson()
|
||||
public function toObject(): array
|
||||
{
|
||||
return [
|
||||
'mi' => round($this->toUnit('miles'), 2),
|
||||
@@ -34,4 +35,12 @@ class Distance extends \PhpUnitsOfMeasure\PhysicalQuantity\Length
|
||||
'km' => round($this->toUnit('meters') / 1000, 2),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance as an array.
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return round($this->toUnit(self::STORAGE_UNIT), 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user