1 | <?php namespace Arcanedev\Units\Measures; |
||
13 | class LiquidVolume extends UnitMeasure implements LiquidVolumeContract |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Traits |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | |||
20 | use Calculatable; |
||
21 | |||
22 | /* ----------------------------------------------------------------- |
||
23 | | Constructor |
||
24 | | ----------------------------------------------------------------- |
||
25 | */ |
||
26 | |||
27 | /** |
||
28 | * Volume constructor. |
||
29 | * |
||
30 | * @param float|int $value |
||
31 | * @param string $unit |
||
32 | * @param array $options |
||
33 | */ |
||
34 | 66 | public function __construct($value = 0, $unit = self::L, array $options = []) |
|
38 | |||
39 | /* ----------------------------------------------------------------- |
||
40 | | Getters & Setters |
||
41 | | ----------------------------------------------------------------- |
||
42 | */ |
||
43 | |||
44 | /** |
||
45 | * Get the default names. |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | 63 | public function defaultNames() |
|
50 | { |
||
51 | 63 | return array_combine(static::units(), [ |
|
52 | 63 | 'kilolitre', |
|
53 | 'hectolitre', |
||
54 | 'decalitre', |
||
55 | 'litre', |
||
56 | 'decilitre', |
||
57 | 'centilitre', |
||
58 | 'millilitre', |
||
59 | ]); |
||
60 | } |
||
61 | |||
62 | /* ----------------------------------------------------------------- |
||
63 | | Main Functions |
||
64 | | ----------------------------------------------------------------- |
||
65 | */ |
||
66 | |||
67 | /** |
||
68 | * Make a volume instance. |
||
69 | * |
||
70 | * @param float|int $value |
||
71 | * @param string $unit |
||
72 | * @param array $options |
||
73 | * |
||
74 | * @return \Arcanedev\Units\Contracts\Measures\LiquidVolume|\Arcanedev\Units\Contracts\UnitMeasure |
||
75 | */ |
||
76 | 27 | public static function make($value = 0, $unit = self::L, array $options = []) |
|
80 | |||
81 | /* ----------------------------------------------------------------- |
||
82 | | Calculation Methods |
||
83 | | ----------------------------------------------------------------- |
||
84 | */ |
||
85 | |||
86 | /** |
||
87 | * Add the volume. |
||
88 | * |
||
89 | * @param float|int $value |
||
90 | * @param string $unit |
||
91 | * |
||
92 | * @return \Arcanedev\Units\Contracts\Measures\LiquidVolume|\Arcanedev\Units\Contracts\UnitMeasure |
||
93 | */ |
||
94 | 6 | public function addVolume($value, $unit = self::L) |
|
98 | |||
99 | /** |
||
100 | * Sub the volume. |
||
101 | * |
||
102 | * @param float|int $value |
||
103 | * @param string $unit |
||
104 | * |
||
105 | * @return \Arcanedev\Units\Contracts\Measures\LiquidVolume|\Arcanedev\Units\Contracts\UnitMeasure |
||
106 | */ |
||
107 | 6 | public function subVolume($value, $unit = self::L) |
|
111 | |||
112 | /* ----------------------------------------------------------------- |
||
113 | | Other Methods |
||
114 | | ----------------------------------------------------------------- |
||
115 | */ |
||
116 | |||
117 | /** |
||
118 | * Get the volume convert ratio. |
||
119 | * |
||
120 | * @param string $to |
||
121 | * @param string $from |
||
122 | * |
||
123 | * @return float|int |
||
124 | */ |
||
125 | 9 | protected static function getRatio($to, $from) |
|
136 | |||
137 | /** |
||
138 | * Get all the volume ratios. |
||
139 | * |
||
140 | * @return array |
||
141 | */ |
||
142 | 9 | protected static function getRatios() |
|
159 | } |
||
160 |