| 1 | <?php |
||
| 9 | final class Storage |
||
| 10 | { |
||
| 11 | public const UNITS = [ |
||
| 12 | 'bouteille', |
||
| 13 | 'boite', |
||
| 14 | 'carton', |
||
| 15 | 'colis', |
||
| 16 | 'kilogramme', |
||
| 17 | 'litre', |
||
| 18 | 'pièce', |
||
| 19 | 'poche', |
||
| 20 | 'portion', |
||
| 21 | ]; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | private $unit; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var float |
||
| 30 | */ |
||
| 31 | private $quantity; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Storage constructor. |
||
| 35 | * |
||
| 36 | * @param string $unit |
||
| 37 | * @param float $quantity |
||
| 38 | */ |
||
| 39 | public function __construct(string $unit, float $quantity) |
||
| 44 | |||
| 45 | public static function fromArray(array $storage): self |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Test the unit. |
||
| 55 | * |
||
| 56 | * @param string $unit |
||
| 57 | * |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | private static function unit(string $unit): string |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Test the quantity. |
||
| 71 | * |
||
| 72 | * @param float $quantity |
||
| 73 | * |
||
| 74 | * @return float |
||
| 75 | */ |
||
| 76 | private static function quantity(float $quantity): float |
||
| 84 | |||
| 85 | public function toArray(): array |
||
| 89 | } |
||
| 90 |
Late static binding only has effect in subclasses. A
finalclass cannot be extended anymore so late static binding cannot occurr. Consider replacingstatic::withself::.To learn more about late static binding, please refer to the PHP core documentation.