Issues (26)

src/Controller/WeatherCurl.php (3 issues)

1
<?php
2
3
4
namespace Anax\Controller;
5
6
class WeatherCurl
7
{
8
9
    private $key;
10
11
    public function setKey($key)
12
    {
13
        $this->key = $key;
14
    }
15
16
17
    /**
18
19
     * Curls the ip address to an api
20
21
     */
22
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))));
0 ignored issues
show
The assignment to $newdate is dead and can be removed.
Loading history...
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);
0 ignored issues
show
It seems like $ch can also be of type false; however, parameter $ch of curl_setopt_array() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
            curl_setopt_array(/** @scrutinizer ignore-type */ $ch, $options);
Loading history...
49
            curl_multi_add_handle($mh, $ch);
0 ignored issues
show
It seems like $ch can also be of type false; however, parameter $ch of curl_multi_add_handle() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
            curl_multi_add_handle($mh, /** @scrutinizer ignore-type */ $ch);
Loading history...
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
    }
75
}
76