| Total Complexity | 9 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| 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 | 64 | public function __construct(Scale $scale, float $degrees) |
|
| 25 | 64 | } |
|
| 26 | |||
| 27 | 50 | public static function celsius(float $degrees): self |
|
| 30 | } |
||
| 31 | |||
| 32 | 12 | public static function fahrenheit(int $degrees): self |
|
| 33 | { |
||
| 34 | 12 | return new self(Scale::fahrenheit(), (float)$degrees); |
|
| 35 | } |
||
| 36 | |||
| 37 | 51 | public function getScale(): Scale |
|
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @return float|int |
||
| 44 | */ |
||
| 45 | 69 | public function getDegrees() |
|
| 46 | { |
||
| 47 | 69 | if ($this->scale->isCelsius()) { |
|
| 48 | 39 | return self::roundCelsius($this->degrees); |
|
| 49 | } |
||
| 50 | |||
| 51 | 30 | return (int)$this->degrees; |
|
| 52 | } |
||
| 53 | |||
| 54 | 62 | private static function roundCelsius(float $degrees): float |
|
| 55 | { |
||
| 56 | 62 | return round($degrees * 2) / 2; |
|
| 57 | } |
||
| 58 | |||
| 59 | 18 | public function __toString(): string |
|
| 71 | ); |
||
| 72 | } |
||
| 73 | } |
||
| 74 |