Conditions | 2 |
Paths | 2 |
Total Lines | 77 |
Code Lines | 62 |
Lines | 0 |
Ratio | 0 % |
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 |
||
55 | public function indexActionGet() |
||
56 | { |
||
57 | $request = $this->di->get("request"); |
||
58 | $ip = $request->getGet("ip"); |
||
59 | |||
60 | $ipres = $this->IpCurl->curl($ip); |
||
61 | $lat = $ipres["latitude"]; |
||
62 | $long = $ipres["longitude"]; |
||
63 | $weatherres = $this->WeatherCurl->curl($lat, $long); |
||
64 | |||
65 | if (isset($weatherres[0]["daily"])) { |
||
66 | $day1 = [ |
||
67 | "valid" => "True", |
||
68 | "summary" => $weatherres[0]["daily"]["data"][0]["summary"], |
||
69 | "date" => gmdate("Y-m-d", $weatherres[0]["daily"]["data"][0]["time"]), |
||
70 | "highest_temp" => $weatherres[0]["daily"]["data"][0]["temperatureMax"], |
||
71 | "lowest_temp" => $weatherres[0]["daily"]["data"][0]["temperatureMin"], |
||
72 | ]; |
||
73 | $day2 = [ |
||
74 | "valid" => "True", |
||
75 | "summary" => $weatherres[1]["daily"]["data"][0]["summary"], |
||
76 | "date" => gmdate("Y-m-d", $weatherres[1]["daily"]["data"][0]["time"]), |
||
77 | "highest_temp" => $weatherres[1]["daily"]["data"][0]["temperatureMax"], |
||
78 | "lowest_temp" => $weatherres[1]["daily"]["data"][0]["temperatureMin"], |
||
79 | ]; |
||
80 | $day3 = [ |
||
81 | "valid" => "True", |
||
82 | "summary" => $weatherres[2]["daily"]["data"][0]["summary"], |
||
83 | "date" => gmdate("Y-m-d", $weatherres[2]["daily"]["data"][0]["time"]), |
||
84 | "highest_temp" => $weatherres[2]["daily"]["data"][0]["temperatureMax"], |
||
85 | "lowest_temp" => $weatherres[2]["daily"]["data"][0]["temperatureMin"], |
||
86 | ]; |
||
87 | $day4 = [ |
||
88 | "valid" => "True", |
||
89 | "summary" => $weatherres[3]["daily"]["data"][0]["summary"], |
||
90 | "date" => gmdate("Y-m-d", $weatherres[3]["daily"]["data"][0]["time"]), |
||
91 | "highest_temp" => $weatherres[3]["daily"]["data"][0]["temperatureMax"], |
||
92 | "lowest_temp" => $weatherres[3]["daily"]["data"][0]["temperatureMin"], |
||
93 | ]; |
||
94 | $day5 = [ |
||
95 | "valid" => "True", |
||
96 | "summary" => $weatherres[4]["daily"]["data"][0]["summary"], |
||
97 | "date" => gmdate("Y-m-d", $weatherres[4]["daily"]["data"][0]["time"]), |
||
98 | "highest_temp" => $weatherres[4]["daily"]["data"][0]["temperatureMax"], |
||
99 | "lowest_temp" => $weatherres[4]["daily"]["data"][0]["temperatureMin"], |
||
100 | ]; |
||
101 | $day6 = [ |
||
102 | "valid" => "True", |
||
103 | "summary" => $weatherres[5]["daily"]["data"][0]["summary"], |
||
104 | "date" => gmdate("Y-m-d", $weatherres[5]["daily"]["data"][0]["time"]), |
||
105 | "highest_temp" => $weatherres[5]["daily"]["data"][0]["temperatureMax"], |
||
106 | "lowest_temp" => $weatherres[5]["daily"]["data"][0]["temperatureMin"], |
||
107 | ]; |
||
108 | $day7 = [ |
||
109 | "valid" => "True", |
||
110 | "summary" => $weatherres[6]["daily"]["data"][0]["summary"], |
||
111 | "date" => gmdate("Y-m-d", $weatherres[6]["daily"]["data"][0]["time"]), |
||
112 | "highest_temp" => $weatherres[6]["daily"]["data"][0]["temperatureMax"], |
||
113 | "lowest_temp" => $weatherres[6]["daily"]["data"][0]["temperatureMin"], |
||
114 | ]; |
||
115 | $res = [ |
||
116 | "1" => $day1, |
||
117 | "2" => $day2, |
||
118 | "3" => $day3, |
||
119 | "4" => $day4, |
||
120 | "5" => $day5, |
||
121 | "6" => $day6, |
||
122 | "7" => $day7, |
||
123 | ]; |
||
124 | } else { |
||
125 | $jsonres = [ |
||
126 | "Message" => "No data found for this location!", |
||
127 | ]; |
||
128 | return [$jsonres]; |
||
129 | } |
||
130 | |||
131 | return [$res]; |
||
132 | } |
||
134 |