oscarLang /
weatherModule
| 1 | <?php |
||||
| 2 | namespace Osln\Weather; |
||||
| 3 | |||||
| 4 | use Anax\Commons\ContainerInjectableInterface; |
||||
| 5 | use Anax\Commons\ContainerInjectableTrait; |
||||
| 6 | |||||
| 7 | class CurlRequest implements ContainerInjectableInterface |
||||
| 8 | { |
||||
| 9 | use ContainerInjectableTrait; |
||||
| 10 | 4 | public function fetch($url) |
|||
| 11 | { |
||||
| 12 | 4 | $ch = curl_init($url); |
|||
| 13 | 4 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 14 | |||||
| 15 | 4 | $json = curl_exec($ch); |
|||
|
0 ignored issues
–
show
It seems like
$ch 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
Loading history...
|
|||||
| 16 | 4 | curl_close($ch); |
|||
|
0 ignored issues
–
show
It seems like
$ch 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
Loading history...
|
|||||
| 17 | 4 | $decoded = json_decode($json, true); |
|||
| 18 | 4 | return $decoded; |
|||
| 19 | } |
||||
| 20 | |||||
| 21 | 2 | public function fetchMultiple($urls) |
|||
| 22 | { |
||||
| 23 | 2 | $mh = curl_multi_init(); |
|||
| 24 | 2 | $chAll = []; |
|||
| 25 | 2 | foreach ($urls as $url) { |
|||
| 26 | 2 | $ch = curl_init($url); |
|||
| 27 | 2 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|||
|
0 ignored issues
–
show
It seems like
$ch 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
Loading history...
|
|||||
| 28 | 2 | 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
Loading history...
|
|||||
| 29 | 2 | $chAll[] = $ch; |
|||
| 30 | } |
||||
| 31 | |||||
| 32 | 2 | $running = null; |
|||
| 33 | do { |
||||
| 34 | 2 | curl_multi_exec($mh, $running); |
|||
| 35 | 2 | } while ($running); |
|||
| 36 | |||||
| 37 | 2 | foreach ($chAll as $ch) { |
|||
| 38 | 2 | curl_multi_remove_handle($mh, $ch); |
|||
| 39 | } |
||||
| 40 | 2 | curl_multi_close($mh); |
|||
| 41 | |||||
| 42 | 2 | $response = []; |
|||
| 43 | 2 | foreach ($chAll as $ch) { |
|||
| 44 | 2 | $data = curl_multi_getcontent($ch); |
|||
| 45 | 2 | $response[] = json_decode($data, true); |
|||
| 46 | } |
||||
| 47 | 2 | return $response; |
|||
| 48 | } |
||||
| 49 | } |
||||
| 50 |