Issues (10)

src/Curl/Curl.php (7 issues)

1
<?php
2
3
namespace Jenel\Curl;
4
5
/**
6
 * A class to place service in $di.
7
 * Curl
8
 * Return array
9
 */
10
class Curl
11
{
12
    /**
13
     * Curl one.
14
     * @param url
15
     *
16
     * @return array
17
     */
18 4
    public function curlOne($url) : array
19
    {
20 4
        $ch = curl_init($url);
21 4
        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 ignore-type  annotation

21
        curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_RETURNTRANSFER, true);
Loading history...
22 4
        $response = 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 ignore-type  annotation

22
        $response = curl_exec(/** @scrutinizer ignore-type */ $ch);
Loading history...
23 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 ignore-type  annotation

23
        curl_close(/** @scrutinizer ignore-type */ $ch);
Loading history...
24
25
26 4
        return json_decode($response, true);
27
    }
28
29
    /**
30
     * Curl multi.
31
     * @param urls
32
     *
33
     * @return array
34
     */
35 1
    public function curlMulti($urls) : array
36
    {
37
        $options = [
38 1
            CURLOPT_RETURNTRANSFER => true,
39
        ];
40
41
        //set the multi handler
42 1
        $mh = curl_multi_init();
43
44
        //set variable to catch all
45 1
        $chAll = [];
46
47 1
        foreach ($urls as $url) {
48 1
            $ch = curl_init($url);
49 1
            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

49
            curl_setopt_array(/** @scrutinizer ignore-type */ $ch, $options);
Loading history...
50 1
            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

50
            curl_multi_add_handle($mh, /** @scrutinizer ignore-type */ $ch);
Loading history...
51 1
            $chAll[] = $ch;
52
        };
53
54
        // execute all queries simultaneously, and continue when all are complete
55 1
        $running = null;
56
        do {
57 1
            curl_multi_exec($mh, $running);
58 1
        } while ($running);
59
60
        //fix to return as array json
61 1
        foreach ($chAll as $ch) {
62 1
            $data = curl_multi_getcontent($ch);
63 1
            $response[] = json_decode($data, true);
64
        };
65
66
        //close the handles
67 1
        curl_multi_remove_handle($mh, $ch);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ch does not seem to be defined for all execution paths leading up to this point.
Loading history...
68 1
        curl_multi_close($mh);
69
70 1
        return $response;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $response seems to be defined by a foreach iteration on line 61. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
71
    }
72
}
73