Issues (7)

src/darkSkyApi/DarkSky.php (6 issues)

1
<?php
2
namespace Anax\darkSkyApi;
3
4
class DarkSky
5
{
6 3
    public static function wheatherSevenActionGet($days, $time)
7
    {
8 3
        $timeRefined = $time;
9
10 3
        $dates = [];
11 3
        for ($i=0; $i < $days; $i++) {
12 3
            $date = strtotime($timeRefined . "-" . $i ."day");
13 3
            array_push($dates, date("Y-m-d", $date) . "T" . date("h:m:s", $date));
14
        }
15
16 3
        return $dates;
17
    }
18
19
20 3
    public static function wheatherThirtyActionGet($res = null, $time = null, $accessKey = null) : array
21
    {
22 3
        for ($j=0; $j < count($time); $j++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
23 3
            ${"ch$j"}  = curl_init('https://api.darksky.net/forecast/'.$accessKey.'/'.$res[0]->latitude .
24 3
                  ','. $res[0]->longitude . "," . $time[$j] . "?exclude=minutely?exclude=hourly");
25
        }
26 3
          $mhcurl = curl_multi_init();
27 3
        for ($i=0; $i < count($time); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
28 3
            curl_setopt(${"ch$i"}, CURLOPT_RETURNTRANSFER, true);
29 3
            curl_multi_add_handle($mhcurl, ${"ch$i"});
30
        }
31 3
          $responseArray = [];
32 3
        for ($k=0; $k < count($time); $k++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
33 3
            $running = null;
34
            do {
35 3
                curl_multi_exec($mhcurl, $running);
36 3
            } while ($running);
37 3
            ${"response$i"} = curl_multi_getcontent(${"ch$k"});
38 3
            $jsonDecodeResponse = json_decode(${"response$i"});
39
40 3
            array_push($responseArray, $jsonDecodeResponse);
41
        }
42 3
        curl_multi_close($mhcurl);
43 3
        return $responseArray;
44
    }
45
46
47
48
49 3
    public static function wheatherActionGet($res = null, $accessKey = null) : array
50
    {
51 3
        for ($j=0; $j < count($res); $j++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
52 3
            ${"ch$j"}  = curl_init('https://api.darksky.net/forecast/'.$accessKey.'/'.$res[$j]->latitude .
53 3
              ','. $res[$j]->longitude . "?exclude=minutely?exclude=hourly");
54
        }
55
56
57
58 3
        $mhcurl = curl_multi_init();
59 3
        for ($i=0; $i < count($res); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
60 3
            curl_setopt(${"ch$i"}, CURLOPT_RETURNTRANSFER, true);
61 3
            curl_multi_add_handle($mhcurl, ${"ch$i"});
62
        }
63 3
        $responseArray = [];
64 3
        for ($k=0; $k < count($res); $k++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
65 3
            $running = null;
66
            do {
67 3
                curl_multi_exec($mhcurl, $running);
68 3
            } while ($running);
69 3
            ${"response$i"} = curl_multi_getcontent(${"ch$k"});
70
        // $jsonDecodeResponse = json_decode(${"response$i"});
71
72 3
            array_push($responseArray, ${"response$i"});
73
        }
74
75 3
        curl_multi_close($mhcurl);
76 3
        return $responseArray;
77
    }
78
79
80
81
82 1
    public function streetActionGet($lat, $long) : string
83
    {
84
85 1
        $curlh  = curl_init('https://nominatim.openstreetmap.org/[email protected]&format=jsonv2&lat=' .$long. "&lon=".$lat);
86
87 1
        curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true);
88
89
90 1
        $json = curl_exec($curlh);
91 1
        curl_close($curlh);
92
93
94
        // $apiResult = json_decode($json, true);
95
96 1
        return $json;
97
    }
98
}
99