AsaTirsen /
weather
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Asti\Weather; |
||||
| 4 | |||||
| 5 | |||||
| 6 | class CurlService |
||||
| 7 | { |
||||
| 8 | |||||
| 9 | 2 | public function getDataThroughCurl(string $url) |
|||
| 10 | { |
||||
| 11 | // $url = "http://localhost:8080/dbwebb/ramverk1/me/redovisa/htdocs/api/ipcheck/check?ipCheck=$ip"; |
||||
| 12 | |||||
| 13 | |||||
| 14 | // Initiate curl handler |
||||
| 15 | 2 | $ch = curl_init(); |
|||
| 16 | |||||
| 17 | // Will return the response, if false it print the response |
||||
| 18 | 2 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|||
| 19 | |||||
| 20 | // Set the url |
||||
| 21 | 2 | curl_setopt($ch, CURLOPT_URL, $url); |
|||
| 22 | |||||
| 23 | // Execute |
||||
| 24 | 2 | $data = curl_exec($ch); |
|||
| 25 | |||||
| 26 | // Closing |
||||
| 27 | 2 | curl_close($ch); |
|||
| 28 | |||||
| 29 | 2 | return json_decode($data, true); |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 30 | } |
||||
| 31 | |||||
| 32 | 2 | public function getMultipleCurls ($fetchURL, $dateArray, $fetchURLPart2) |
|||
| 33 | { |
||||
| 34 | 2 | $mh = curl_multi_init(); |
|||
| 35 | 2 | $multiCurl = []; |
|||
| 36 | 2 | $curlArray = []; |
|||
| 37 | |||||
| 38 | 2 | foreach($dateArray as $i => $date) { |
|||
| 39 | 2 | $URL = $fetchURL . $date . $fetchURLPart2; |
|||
| 40 | 2 | $multiCurl[$i] = curl_init(); |
|||
| 41 | 2 | curl_setopt($multiCurl[$i], CURLOPT_URL, $URL); |
|||
| 42 | 2 | curl_setopt($multiCurl[$i], CURLOPT_HEADER, 0); |
|||
| 43 | 2 | curl_setopt($multiCurl[$i], CURLOPT_RETURNTRANSFER, 1); |
|||
| 44 | 2 | curl_multi_add_handle($mh, $multiCurl[$i]); |
|||
|
0 ignored issues
–
show
It seems like
$mh can also be of type true; however, parameter $multi_handle of curl_multi_add_handle() does only seem to accept CurlMultiHandle|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...
|
|||||
| 45 | } |
||||
| 46 | 2 | $index = null; |
|||
| 47 | do { |
||||
| 48 | 2 | curl_multi_exec($mh, $index); |
|||
|
0 ignored issues
–
show
It seems like
$mh can also be of type true; however, parameter $multi_handle of curl_multi_exec() does only seem to accept CurlMultiHandle|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...
|
|||||
| 49 | 2 | } while ($index > 0); |
|||
| 50 | |||||
| 51 | 2 | foreach ($multiCurl as $k => $ch) { |
|||
| 52 | 2 | $result[$k] = curl_multi_getcontent($ch); |
|||
| 53 | 2 | array_push($curlArray, json_decode($result[$k], true)); |
|||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
| 54 | 2 | curl_multi_remove_handle($mh, $ch); |
|||
|
0 ignored issues
–
show
It seems like
$mh can also be of type true; however, parameter $multi_handle of curl_multi_remove_handle() does only seem to accept CurlMultiHandle|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...
|
|||||
| 55 | } |
||||
| 56 | 2 | curl_multi_close($mh); |
|||
|
0 ignored issues
–
show
It seems like
$mh can also be of type true; however, parameter $multi_handle of curl_multi_close() does only seem to accept CurlMultiHandle|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...
|
|||||
| 57 | 2 | return $curlArray; |
|||
| 58 | } |
||||
| 59 | } |
||||
| 60 |