1 | <?php |
||||
2 | |||||
3 | namespace Anax\Models; |
||||
4 | |||||
5 | use Anax\Config\access; |
||||
0 ignored issues
–
show
|
|||||
6 | |||||
7 | /** |
||||
8 | * Class Weather |
||||
9 | */ |
||||
10 | class Weather |
||||
11 | { |
||||
12 | private $keys; |
||||
13 | |||||
14 | public function setKeys($config) |
||||
15 | { |
||||
16 | $this->keys = $config; |
||||
17 | } |
||||
18 | |||||
19 | /** |
||||
20 | * Curl from url |
||||
21 | */ |
||||
22 | |||||
23 | public function curl($url) |
||||
24 | { |
||||
25 | $curl = curl_init($url); |
||||
26 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||||
0 ignored issues
–
show
It seems like
$curl can also be of type false ; however, parameter $ch of curl_setopt() 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
![]() |
|||||
27 | $data = curl_exec($curl); |
||||
0 ignored issues
–
show
It seems like
$curl can also be of type false ; however, parameter $ch of curl_exec() 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
![]() |
|||||
28 | curl_close($curl); |
||||
0 ignored issues
–
show
It seems like
$curl can also be of type false ; however, parameter $ch of curl_close() 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
![]() |
|||||
29 | |||||
30 | return $data; |
||||
31 | } |
||||
32 | |||||
33 | public function multiCurl($urls) |
||||
34 | { |
||||
35 | $opts = [ |
||||
36 | CURLOPT_RETURNTRANSFER => true, |
||||
37 | ]; |
||||
38 | $cAll = []; |
||||
39 | |||||
40 | $mh = curl_multi_init(); |
||||
41 | |||||
42 | foreach ($urls as $url) { |
||||
43 | $ch = curl_init("$url"); |
||||
44 | curl_setopt_array($ch, $opts); |
||||
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
![]() |
|||||
45 | 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
![]() |
|||||
46 | $cAll[] = $ch; |
||||
47 | } |
||||
48 | |||||
49 | $running = null; |
||||
50 | do { |
||||
51 | curl_multi_exec($mh, $running); |
||||
52 | } while ($running); |
||||
53 | |||||
54 | foreach ($cAll as $ch) { |
||||
55 | curl_multi_remove_handle($mh, $ch); |
||||
56 | } |
||||
57 | curl_multi_close($mh); |
||||
58 | |||||
59 | $response = []; |
||||
60 | foreach ($cAll as $ch) { |
||||
61 | $data = curl_multi_getcontent($ch); |
||||
62 | array_push($response, $data); |
||||
63 | } |
||||
64 | |||||
65 | return $response; |
||||
66 | } |
||||
67 | |||||
68 | public function getWeather($lat, $long, $geo) |
||||
69 | { |
||||
70 | $urls; |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
71 | $accessToken = $this->keys["darkSky"]; |
||||
72 | |||||
73 | if ($geo == "future") { |
||||
74 | $url = 'https://api.darksky.net/forecast/' . $accessToken . "/" . $lat . "," . $long . "?units=si"; |
||||
75 | $data = json_decode($this->curl($url)); |
||||
76 | } else { |
||||
77 | $days = 5; |
||||
78 | for ($i = 0; $i < $days; $i++) { |
||||
79 | $timestamp = "-" . $i . " day"; |
||||
80 | $time = strtotime($timestamp, time()); |
||||
81 | $urls[$i] = 'https://api.darksky.net/forecast/' . $accessToken . "/" . $lat . "," . $long . "," . $time . "?units=si"; |
||||
82 | } |
||||
83 | $curlResponse = $this->multiCurl($urls); |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
84 | for ($i = 0; $i < $days; $i++) { |
||||
85 | $data[$i] = json_decode($curlResponse[$i]); |
||||
86 | } |
||||
87 | } |
||||
88 | $mapUrl = "https://nominatim.openstreetmap.org/reverse?lat=$lat&lon=$long&[email protected]&format=json"; |
||||
89 | $mapData = json_decode($this->curl($mapUrl)); |
||||
90 | $weatherData = [ |
||||
91 | "data" => $data, |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
92 | "mapData" => $mapData |
||||
93 | ]; |
||||
94 | return $weatherData; |
||||
95 | } |
||||
96 | } |
||||
97 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths