Conditions | 6 |
Paths | 16 |
Total Lines | 51 |
Code Lines | 33 |
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 |
||
23 | public function curl($lat, $long) |
||
24 | { |
||
25 | // $access_key = "c5d9fa305d5b063807a2cd9ff701c080"; |
||
26 | $url = "https://api.darksky.net/forecast"; |
||
27 | $time = "12:00:00"; |
||
28 | $date = date("Y-m-d"); |
||
29 | $key = ""; |
||
30 | $days = 7; |
||
31 | |||
32 | $mh = curl_multi_init(); |
||
33 | $chAll = []; |
||
34 | |||
35 | $newdate = date('Y-m-d', (strtotime('1 day', strtotime($date)))); |
||
|
|||
36 | |||
37 | $options = [ |
||
38 | CURLOPT_RETURNTRANSFER => true, |
||
39 | ]; |
||
40 | |||
41 | if ($this->key) { |
||
42 | $key = $this->key; |
||
43 | } else { |
||
44 | $key = "c5d9fa305d5b063807a2cd9ff701c080"; |
||
45 | } |
||
46 | while ($days > 0) { |
||
47 | $ch = curl_init("$url/$key/$lat,$long,{$date}T$time?units=si"); |
||
48 | curl_setopt_array($ch, $options); |
||
49 | curl_multi_add_handle($mh, $ch); |
||
50 | $chAll[] = $ch; |
||
51 | $date = date('Y-m-d', (strtotime('1 day', strtotime($date)))); |
||
52 | $days = $days - 1; |
||
53 | } |
||
54 | |||
55 | $go = null; |
||
56 | |||
57 | do { |
||
58 | curl_multi_exec($mh, $go); |
||
59 | } while ($go); |
||
60 | |||
61 | foreach ($chAll as $ch) { |
||
62 | curl_multi_remove_handle($mh, $ch); |
||
63 | } |
||
64 | curl_multi_close($mh); |
||
65 | |||
66 | $res = []; |
||
67 | |||
68 | foreach ($chAll as $ch) { |
||
69 | $data = curl_multi_getcontent($ch); |
||
70 | |||
71 | $res[] = json_decode($data, true); |
||
72 | } |
||
73 | return $res; |
||
74 | } |
||
76 |