1 | <?php namespace Arcanedev\Units\Measures; |
||
14 | class Distance extends UnitMeasure implements DistanceContract |
||
15 | { |
||
16 | /* ------------------------------------------------------------------------------------------------ |
||
17 | | Traits |
||
18 | | ------------------------------------------------------------------------------------------------ |
||
19 | */ |
||
20 | use Calculatable; |
||
21 | |||
22 | /* ------------------------------------------------------------------------------------------------ |
||
23 | | Constructor |
||
24 | | ------------------------------------------------------------------------------------------------ |
||
25 | */ |
||
26 | /** |
||
27 | * Distance constructor. |
||
28 | * |
||
29 | * @param float|int $value |
||
30 | * @param string $unit |
||
31 | * @param array $options |
||
32 | */ |
||
33 | 168 | public function __construct($value = 0, $unit = self::M, array $options = []) |
|
44 | |||
45 | /* ------------------------------------------------------------------------------------------------ |
||
46 | | Getters & Setters |
||
47 | | ------------------------------------------------------------------------------------------------ |
||
48 | */ |
||
49 | /** |
||
50 | * Get the symbol's names. |
||
51 | * |
||
52 | * @return array |
||
53 | */ |
||
54 | 8 | public static function names() |
|
66 | |||
67 | /** |
||
68 | * Get the symbol name. |
||
69 | * |
||
70 | * @param string $unit |
||
71 | * |
||
72 | * @return string |
||
73 | */ |
||
74 | 8 | public static function getSymbolName($unit) |
|
80 | |||
81 | /* ------------------------------------------------------------------------------------------------ |
||
82 | | Main Functions |
||
83 | | ------------------------------------------------------------------------------------------------ |
||
84 | */ |
||
85 | /** |
||
86 | * Make a distance instance. |
||
87 | * |
||
88 | * @param float|int $value |
||
89 | * @param string $unit |
||
90 | * @param array $options |
||
91 | * |
||
92 | * @return \Arcanedev\Units\Contracts\Distance |
||
93 | */ |
||
94 | 72 | public static function make($value = 0, $unit = self::M, array $options = []) |
|
98 | |||
99 | /** |
||
100 | * Convert the weight to the given unit. |
||
101 | * |
||
102 | * @param string $to |
||
103 | * |
||
104 | * @return \Arcanedev\Units\Contracts\Distance |
||
105 | */ |
||
106 | 72 | public function to($to) |
|
114 | |||
115 | /** |
||
116 | * Convert the weight. |
||
117 | * |
||
118 | * @param string $from |
||
119 | * @param string $to |
||
120 | * @param float|int $value |
||
121 | * |
||
122 | * @return float|int |
||
123 | */ |
||
124 | 24 | public static function convert($from, $to, $value) |
|
128 | |||
129 | /* ------------------------------------------------------------------------------------------------ |
||
130 | | Calculation Functions |
||
131 | | ------------------------------------------------------------------------------------------------ |
||
132 | */ |
||
133 | /** |
||
134 | * Add the distance. |
||
135 | * |
||
136 | * @param float|int $value |
||
137 | * @param string $unit |
||
138 | * |
||
139 | * @return \Arcanedev\Units\Contracts\Distance |
||
140 | */ |
||
141 | 16 | public function addDistance($value, $unit = self::M) |
|
147 | |||
148 | /** |
||
149 | * Add the distance instance. |
||
150 | * |
||
151 | * @param \Arcanedev\Units\Contracts\Distance $distance |
||
152 | * |
||
153 | * @return \Arcanedev\Units\Contracts\Distance |
||
154 | */ |
||
155 | 32 | public function add(DistanceContract $distance) |
|
163 | |||
164 | /** |
||
165 | * Sub the weight. |
||
166 | * |
||
167 | * @param float|int $value |
||
168 | * @param string $unit |
||
169 | * |
||
170 | * @return \Arcanedev\Units\Contracts\Distance |
||
171 | */ |
||
172 | 16 | public function subDistance($value, $unit = self::M) |
|
178 | |||
179 | /** |
||
180 | * Sub the distance instance. |
||
181 | * |
||
182 | * @param \Arcanedev\Units\Contracts\Distance $distance |
||
183 | * |
||
184 | * @return \Arcanedev\Units\Contracts\Distance |
||
185 | */ |
||
186 | 16 | public function sub(DistanceContract $distance) |
|
194 | |||
195 | /** |
||
196 | * Multiply distance by the given number. |
||
197 | * |
||
198 | * @param float|int $number |
||
199 | * |
||
200 | * @return \Arcanedev\Units\Contracts\Distance |
||
201 | */ |
||
202 | 16 | public function multiply($number) |
|
208 | |||
209 | /** |
||
210 | * Divide distance by the given number. |
||
211 | * |
||
212 | * @param float|int $number |
||
213 | * |
||
214 | * @return \Arcanedev\Units\Contracts\Distance |
||
215 | */ |
||
216 | 16 | public function divide($number) |
|
222 | |||
223 | /* ------------------------------------------------------------------------------------------------ |
||
224 | | Other Functions |
||
225 | | ------------------------------------------------------------------------------------------------ |
||
226 | */ |
||
227 | /** |
||
228 | * Get the weight convert ratio. |
||
229 | * |
||
230 | * @param string $to |
||
231 | * @param string $from |
||
232 | * |
||
233 | * @return double|float|integer |
||
234 | */ |
||
235 | 24 | protected static function getRatio($to, $from) |
|
246 | |||
247 | /** |
||
248 | * Get all the weight ratios. |
||
249 | * |
||
250 | * @return array |
||
251 | */ |
||
252 | 24 | protected static function getRatios() |
|
269 | } |
||
270 |