|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: ignatenkov |
|
5
|
|
|
* Date: 23.08.15 |
|
6
|
|
|
* Time: 4:56 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace YaWeather\Models; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class Detail { |
|
13
|
|
|
|
|
14
|
|
|
public $temperature_from; |
|
15
|
|
|
public $temperature_to; |
|
16
|
|
|
public $temperature_avg; |
|
17
|
|
|
|
|
18
|
|
|
public $station; |
|
19
|
|
|
public $observation_time; |
|
20
|
|
|
public $uptime; |
|
21
|
|
|
public $temperature; |
|
22
|
|
|
public $weather_condition; |
|
23
|
|
|
public $image; |
|
24
|
|
|
public $image_v2; |
|
25
|
|
|
public $image_v3; |
|
26
|
|
|
public $weather_type; |
|
27
|
|
|
public $wind_direction; |
|
28
|
|
|
public $wind_speed; |
|
29
|
|
|
public $humidity; |
|
30
|
|
|
public $pressure; |
|
31
|
|
|
public $mslp_pressure; |
|
32
|
|
|
public $daytime; |
|
33
|
|
|
public $season; |
|
34
|
|
|
public $ipad_image; |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function getTemperatureStr() { |
|
39
|
|
|
return $this->temperature > 0 ? '+'.$this->temperature : $this->temperature; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getTemperatureAvgStr() { |
|
43
|
|
|
return $this->temperature_avg > 0 ? '+'.$this->temperature_avg : $this->temperature_avg; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function getTemperatureFromStr() { |
|
47
|
|
|
return $this->temperature_from > 0 ? '+'.$this->temperature_from : $this->temperature_from; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getTemperatureToStr() { |
|
51
|
|
|
return $this->temperature_to > 0 ? '+'.$this->temperature_to : $this->temperature_to; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getTemperatureFromTo() { |
|
55
|
|
|
if($this->temperature_from && $this->temperature_to) |
|
56
|
|
|
return $this->getTemperatureFromStr().'...'.$this->getTemperatureToStr(); |
|
57
|
|
|
else |
|
58
|
|
|
return $this->getTemperatureAvgStr(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get current time |
|
63
|
|
|
* @return bool|string |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getObservationTime() { |
|
66
|
|
|
return $time = date("H:i",strtotime($this->observation_time)); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get icon for weather |
|
71
|
|
|
* @return mixed |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getIcon() { |
|
74
|
|
|
if(substr($this->image_v3, -3, 1) == "-") { |
|
75
|
|
|
$this->image_v3 = str_replace("-", "", $this->image_v3); |
|
76
|
|
|
} |
|
77
|
|
|
$this->image_v3 = str_replace("+", "", $this->image_v3); |
|
78
|
|
|
return str_replace("_", "-", $this->image_v3); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Get wind direction |
|
83
|
|
|
* @return mixed |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getWindDirection() { |
|
86
|
|
|
$windDirection = [ |
|
87
|
|
|
's'=>'Ю', |
|
88
|
|
|
'n'=>'С', |
|
89
|
|
|
'w'=>'З', |
|
90
|
|
|
'e'=>'В', |
|
91
|
|
|
'sw'=>'ЮЗ', |
|
92
|
|
|
'se'=>'ЮВ', |
|
93
|
|
|
'nw'=>'СЗ', |
|
94
|
|
|
'ne'=>'СВ']; |
|
95
|
|
|
|
|
96
|
|
|
if(isset($windDirection[$this->wind_direction])) |
|
97
|
|
|
return $windDirection[$this->wind_direction]; |
|
98
|
|
|
|
|
99
|
|
|
return null; |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.