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 | * |
||
47 | * @return string The value formatted string with unit. |
||
48 | */ |
||
49 | 1 | public function __toString(): string |
|
53 | |||
54 | /** |
||
55 | * Get the value's unit. |
||
56 | * This also converts 'celsius' to 'C' and 'fahrenheit' to 'F'. |
||
57 | * |
||
58 | * @return string The value's unit. |
||
59 | */ |
||
60 | 3 | public function getUnit(): ?string |
|
70 | |||
71 | /** |
||
72 | * Get the value. |
||
73 | * |
||
74 | * @return float The value |
||
75 | */ |
||
76 | 1 | public function getValue(): float |
|
80 | |||
81 | /** |
||
82 | * Get the value's description. |
||
83 | * |
||
84 | * @return string Value's description. |
||
85 | */ |
||
86 | 1 | public function getDescription(): ?string |
|
90 | |||
91 | /** |
||
92 | * Get the value as a formatted string with unit. |
||
93 | * |
||
94 | * @return string The value as formatted string with unit. |
||
95 | */ |
||
96 | public function getFormatted(): string |
||
104 | } |
||
105 |