Temperature::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 7
crap 1
1
<?php
2
namespace Bhhaskin\WeatherBee\Util;
3
4
use Bhhaskin\WeatherBee\Util\Unit;
5
6
/**
7
* Class for handling temperature
8
*/
9
class Temperature
10
{
11
    /**
12
    * Current temperature.
13
    * @var Unit
14
    */
15
    public $now;
16
17
    /**
18
    * The minimal temperature.
19
    * @var Unit
20
    */
21
    public $min;
22
23
    /**
24
    * The maximal temperature.
25
    * @var Unit
26
    */
27
    public $max;
28
29
    /**
30
    * The day temperature.
31
    * Might be null.
32
    * @var Unit
33
    */
34
    public $day;
35
36
    /**
37
    * The morning temperature.
38
    * Might be null.
39
    * @var Unit
40
    */
41
    public $morning;
42
43
    /**
44
    * The evening temperature.
45
    * Might be null.
46
    * @var Unit
47
    */
48
    public $evening;
49
50
    /**
51
    * The night temperature.
52
    * Might be null.
53
    * @var Unit
54
    */
55
    public $night;
56
57
    /**
58
    * Get the current temperature as a formatted string with unit.
59
    * Unit will not be inlucded if Empty
60
    * @return string The temperature formatted string with unit.
61
    */
62 1
    public function __toString()
63
    {
64 1
        return $this->now->__toString();
65
    }
66
67
    /**
68
    * Creates new temperature object
69
    * @param Unit $now The current temperature.
70
    * @param Unit $min The minimal temperature.
71
    * @param Unit $max The maximal temperature.
72
    * @param Unit $day The day temperature. Might not be null.
73
    * @param Unit $morning The morning temperature. Might not be null.
74
    * @param Unit $evening The evening temperature. Might not be null.
75
    * @param Unit $night The night temperature. Might not be null.
76
    */
77 1
    public function __construct(
78
        Unit $now,
79
        Unit $min,
80
        Unit $max,
81
        Unit $day = null,
82
        Unit $morning = null,
83
        Unit $evening = null,
84
        Unit $night = null
85
        )
86
        {
87 1
            $this->now = $now;
88 1
            $this->min = $min;
89 1
            $this->max = $max;
90 1
            $this->day = $day;
91 1
            $this->morning = $morning;
92 1
            $this->evening = $evening;
93 1
            $this->night = $night;
94 1
        }
95
96
        /**
97
        * Get the current temperature unit.
98
        * This also converts 'celsius' to 'C' and 'fahrenheit' to 'F'.
99
        * @return string The temperature unit.
100
        */
101 3
        public function getUnit(): ?string
102
        {
103 3
            return $this->now->getUnit();
104
        }
105
106
        /**
107
        * Get the current temperature value.
108
        * @return float The value
109
        */
110 1
        public function getValue(): float
111
        {
112 1
            return $this->now->getValue();
113
        }
114
115
        /**
116
        * Get the current temperature description.
117
        * @return string Value's description.
118
        */
119 1
        public function getDescription(): ?string
120
        {
121 1
            return $this->now->getDescription();
122
        }
123
124
        /**
125
        * Get the current temperature as a formatted string with unit.
126
        * @return string The current temperature as formatted string with unit.
127
        */
128 2
        public function getFormatted(): string
129
        {
130 2
            return $this->now->getFormatted();
131
        }
132
    }
133