1 | <?php |
||
7 | class Unit |
||
8 | { |
||
9 | /** |
||
10 | * The value |
||
11 | * @var float |
||
12 | * @internal |
||
13 | */ |
||
14 | private $value; |
||
15 | |||
16 | /** |
||
17 | * The value's unit |
||
18 | * @var string |
||
19 | * @internal |
||
20 | */ |
||
21 | private $unit; |
||
22 | |||
23 | /** |
||
24 | * The value's description |
||
25 | * @var string |
||
26 | * @internal |
||
27 | */ |
||
28 | private $description; |
||
29 | |||
30 | /** |
||
31 | * Create a new unit object |
||
32 | * @param float $value The value |
||
33 | * @param string $unit The value's unit |
||
34 | * @param string $description The value's description |
||
35 | */ |
||
36 | 1 | public function __construct(float $value = 0.0, string $unit = null, string $description = null) |
|
42 | |||
43 | /** |
||
44 | * Get the value as formatted string with unit. |
||
45 | * Unit will not be included if it is empty |
||
46 | * @return string The value formatted string with unit. |
||
47 | */ |
||
48 | 1 | public function __toString(): string |
|
52 | |||
53 | /** |
||
54 | * Get the value's unit. |
||
55 | * This also converts 'celsius' to 'C' and 'fahrenheit' to 'F'. |
||
56 | * @return string The value's unit. |
||
57 | */ |
||
58 | 3 | public function getUnit(): ?string |
|
68 | |||
69 | /** |
||
70 | * Get the value. |
||
71 | * @return float The value |
||
72 | */ |
||
73 | 1 | public function getValue(): float |
|
77 | |||
78 | /** |
||
79 | * Get the value's description. |
||
80 | * @return string Value's description. |
||
81 | */ |
||
82 | 1 | public function getDescription(): ?string |
|
86 | |||
87 | /** |
||
88 | * Get the value as a formatted string with unit. |
||
89 | * @return string The value as formatted string with unit. |
||
90 | */ |
||
91 | 2 | public function getFormatted(): string |
|
99 | } |
||
100 |