Completed
Push — master ( 4a2f3f...6ed42c )
by Bryan
18:05 queued 57s
created

Temperature   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 124
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 4 1
A __construct() 0 18 1
A getUnit() 0 4 1
A getValue() 0 4 1
A getDescription() 0 4 1
A getFormatted() 0 4 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
    function __construct(
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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