1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: ignatenkov |
5
|
|
|
* Date: 21.08.15 |
6
|
|
|
* Time: 1:22 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace YaWeather\Models; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class City { |
13
|
|
|
|
14
|
|
|
public $city; |
15
|
|
|
public $country; |
16
|
|
|
public $region; |
17
|
|
|
|
18
|
|
|
public $fact; |
19
|
|
|
public $yesterday; |
20
|
|
|
|
21
|
|
|
public $days; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get current model day |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
View Code Duplication |
public function getCurrentDay() { |
|
|
|
|
29
|
|
|
$current = date("Y-m-d"); |
30
|
|
|
if(isset($this->days[$current])) |
31
|
|
|
return $this->days[$current]; |
32
|
|
|
else |
33
|
|
|
return "not found current day"; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get List models Day |
38
|
|
|
* @return mixed |
39
|
|
|
*/ |
40
|
|
View Code Duplication |
public function getListDays() { |
|
|
|
|
41
|
|
|
$current = date("Y-m-d"); |
42
|
|
|
if(isset($this->days[$current])) |
43
|
|
|
unset($this->days[$current]); |
44
|
|
|
|
45
|
|
|
return $this->days; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get yesterday model day |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function getYesterday() { |
|
|
|
|
53
|
|
|
$yesterday = date("Y-m-d", time() - 86400); |
54
|
|
|
|
55
|
|
|
if(isset($this->days[$yesterday])) |
56
|
|
|
return $this->days[$yesterday]; |
57
|
|
|
else |
58
|
|
|
return "not found yesterday day"; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/*public $listDay = array(); |
|
|
|
|
65
|
|
|
private $xml; |
66
|
|
|
|
67
|
|
|
public function __construct($fileName) { |
68
|
|
|
|
69
|
|
|
$this->xml = simplexml_load_file($fileName); |
70
|
|
|
/*$day = new Day(); |
71
|
|
|
$day->p = 0; |
72
|
|
|
$day->p1 = 1; |
73
|
|
|
|
74
|
|
|
$this->listDay[] = $day;*/ |
75
|
|
|
//echo $fileName; |
76
|
|
|
//$xml = simplexml_load_file($fileName, "Day"); |
|
|
|
|
77
|
|
|
|
78
|
|
|
|
79
|
|
|
|
80
|
|
|
//$xml1 = $file = file_get_contents($fileName, true);; |
|
|
|
|
81
|
|
|
//var_dump($xml); |
82
|
|
|
//$xml1 = simplexml_load_string($xml, 'Day'); |
|
|
|
|
83
|
|
|
//var_dump($xml->day[0]); |
|
|
|
|
84
|
|
|
//var_dump($xml); |
85
|
|
|
//var_dump($this->listDay); |
|
|
|
|
86
|
|
|
/*} |
|
|
|
|
87
|
|
|
|
88
|
|
|
public function getListDay() { |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
|
92
|
|
|
|
93
|
|
|
foreach ($this->xml->day as $day) { |
94
|
|
|
$this->listDay[] = new Day($day); |
95
|
|
|
//var_dump($day->sunrise); |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return $this->listDay; |
100
|
|
|
|
101
|
|
|
}*/ |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/*public function getListDay() { |
|
|
|
|
105
|
|
|
return $this->listDay; |
106
|
|
|
}*/ |
107
|
|
|
|
108
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.