Temperature::setData()   B
last analyzed

Complexity

Conditions 7
Paths 16

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 0
cts 12
cp 0
rs 8.2222
cc 7
eloc 11
nc 16
nop 1
crap 56
1
<?php
2
/**
3
 *
4
 * PHP version 5.5
5
 *
6
 * @package Forecast
7
 * @author  Sergey V.Kuzin <[email protected]>
8
 * @license MIT
9
 */
10
declare(strict_types=1);
11
namespace Forecast\Model;
12
13
14
use Forecast\ForecastItemInterface;
15
16
class Temperature implements ModelInterface
17
{
18
    /**
19
     * @var float
20
     */
21
    protected $current = null;
22
23
    /**
24
     * @var float
25
     */
26
    protected $max = null;
27
28
    /**
29
     * @var float
30
     */
31
    protected $min = null;
32
33
    /**
34
     * @var float
35
     */
36
    protected $apparent = null;
37
38
    /**
39
     * @api
40
     *
41
     * @return float
42
     */
43
    public function getCurrent($precision = 2)
44
    {
45
        return round($this->current, $precision);
46
    }
47
48
    /**
49
     * @api
50
     *
51
     * @return float
52
     */
53
    public function getMax()
54
    {
55
        return $this->max;
56
    }
57
58
    /**
59
     * @api
60
     *
61
     * @return float
62
     */
63
    public function getMin()
64
    {
65
        return $this->min;
66
    }
67
68
    /**
69
     * @api
70
     *
71
     * @return string
72
     */
73
    public function __toString()
74
    {
75
        return (string)$this->current;
76
    }
77
78
    /**
79
     * @param array $data
80
     * @return $this
81
     */
82
    public function setData(array $data)
83
    {
84
        if (
85
            !($trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)) ||
86
            !(isset($trace[1]['class']) && in_array(ForecastItemInterface::class, class_implements($trace[1]['class'])))
87
        ) {
88
            trigger_error('Member not available: setData', E_USER_ERROR);
89
        }
90
91
        $this->current = $data['current'];
92
        $this->apparent =
93
            isset($data['apparent']) ? $data['apparent'] : $data['current'];
94
        $this->max = isset($data['max']) ? $data['max'] : $data['current'];
95
        $this->min = isset($data['min']) ? $data['min'] : $data['current'];
96
97
        return $this;
98
    }
99
}
100