Conditions | 15 |
Paths | 514 |
Total Lines | 59 |
Code Lines | 34 |
Lines | 16 |
Ratio | 27.12 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
36 | public function parse() { |
||
37 | |||
38 | // check xml load |
||
39 | if(!$this->xml) |
||
40 | return false; |
||
41 | |||
42 | $city = new City(); |
||
43 | View Code Duplication | foreach($this->xml->attributes() as $key => $value) { |
|
44 | if(isset(Mapping::mapCity()[$key])) |
||
45 | $city->{Mapping::mapCity()[$key]} = (string) $value; |
||
46 | } |
||
47 | |||
48 | $fact = new Detail(); |
||
49 | View Code Duplication | foreach ($this->xml->fact[0] as $key => $value) { |
|
50 | if(isset(Mapping::mapDetail()[$key])) { |
||
51 | $fact->{Mapping::mapDetail()[$key]} = (string) $value; |
||
52 | } |
||
53 | |||
54 | } |
||
55 | $city->fact = $fact; |
||
56 | |||
57 | $fact = new Detail(); |
||
58 | View Code Duplication | foreach ($this->xml->yesterday[0] as $key => $value) { |
|
59 | if(isset(Mapping::mapDetail()[$key])) { |
||
60 | $fact->{Mapping::mapDetail()[$key]} = (string) $value; |
||
61 | } |
||
62 | |||
63 | } |
||
64 | $city->yesterday = $fact; |
||
65 | |||
66 | $days = array(); |
||
67 | foreach($this->xml->day as $value) { |
||
68 | $day = new Day(); |
||
69 | foreach ($value as $key => $value1) { |
||
70 | if(isset(Mapping::mapDay()[$key])) { |
||
71 | $day->{Mapping::mapDay()[$key]} = (string) $value1; |
||
72 | } |
||
73 | //var_dump($value1->attributes()["typeid"]); |
||
74 | |||
75 | |||
76 | } |
||
77 | foreach ($value->day_part as $key2 => $value2) { |
||
78 | $detail = new Detail(); |
||
79 | foreach ($value2 as $key3 => $value3) { |
||
80 | if(isset(Mapping::mapDetail()[$key3])) { |
||
81 | $detail->{Mapping::mapDetail()[$key3]} = (string) $value3; |
||
82 | } |
||
83 | if(isset(Mapping::mapDetail()["inner"][$key3])) { |
||
84 | $detail->{Mapping::mapDetail()["inner"][$key3]} = (string) $value3->avg; |
||
85 | } |
||
86 | } |
||
87 | $day->{$value2->attributes()["type"]} = $detail; |
||
88 | } |
||
89 | $days[(string)$value->attributes()["date"]] = $day; |
||
90 | } |
||
91 | $city->days = $days; |
||
92 | |||
93 | return $city; |
||
94 | } |
||
95 | |||
110 | } |
This check marks private properties in classes that are never used. Those properties can be removed.