Total Complexity | 9 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Coverage | 73.91% |
Changes | 0 |
1 | <?php |
||
9 | final class Temperature |
||
10 | { |
||
11 | /** |
||
12 | * @var Scale |
||
13 | */ |
||
14 | private $scale; |
||
15 | |||
16 | /** |
||
17 | * @var float |
||
18 | */ |
||
19 | private $degrees; |
||
20 | |||
21 | 17 | public function __construct(Scale $scale, float $degrees) |
|
25 | 17 | } |
|
26 | |||
27 | 10 | public static function celsius(float $degrees): self |
|
30 | } |
||
31 | |||
32 | 5 | public static function fahrenheit(int $degrees): self |
|
33 | { |
||
34 | 5 | return new self(Scale::fahrenheit(), (float)$degrees); |
|
35 | } |
||
36 | |||
37 | 11 | public function getScale(): Scale |
|
38 | { |
||
39 | 11 | return $this->scale; |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * @return float|int |
||
44 | */ |
||
45 | 13 | public function getDegrees() |
|
46 | { |
||
47 | 13 | if ($this->scale->isFahrenheit()) { |
|
48 | 6 | return (int) $this->degrees; |
|
49 | } |
||
50 | |||
51 | 7 | if ($this->scale->isCelsius()) { |
|
52 | 7 | return self::roundCelsius($this->degrees); |
|
53 | } |
||
54 | } |
||
55 | |||
56 | 11 | private static function roundCelsius(float $degrees): float |
|
57 | { |
||
58 | 11 | return round($degrees * 2) / 2; |
|
59 | } |
||
60 | |||
61 | public function __toString(): string |
||
67 | ); |
||
68 | } |
||
69 | } |
||
70 |