CurlService   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 52
ccs 27
cts 27
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataThroughCurl() 0 21 1
A getMultipleCurls() 0 26 4
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
It seems like $data can also be of type true; however, parameter $json of json_decode() does only seem to accept string, 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

29
        return json_decode(/** @scrutinizer ignore-type */ $data, true);
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
Bug introduced by
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 ignore-type  annotation

44
            curl_multi_add_handle(/** @scrutinizer ignore-type */ $mh, $multiCurl[$i]);
Loading history...
45
        }
46 2
        $index = null;
47
        do {
48 2
            curl_multi_exec($mh, $index);
0 ignored issues
show
Bug introduced by
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 ignore-type  annotation

48
            curl_multi_exec(/** @scrutinizer ignore-type */ $mh, $index);
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
The variable $result seems to be defined later in this foreach loop on line 52. Are you sure it is defined here?
Loading history...
54 2
            curl_multi_remove_handle($mh, $ch);
0 ignored issues
show
Bug introduced by
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 ignore-type  annotation

54
            curl_multi_remove_handle(/** @scrutinizer ignore-type */ $mh, $ch);
Loading history...
55
        }
56 2
        curl_multi_close($mh);
0 ignored issues
show
Bug introduced by
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 ignore-type  annotation

56
        curl_multi_close(/** @scrutinizer ignore-type */ $mh);
Loading history...
57 2
        return $curlArray;
58
    }
59
}
60