1 | <?php |
||||
2 | |||||
3 | namespace Hab\MeModule; |
||||
4 | |||||
5 | use Anax\Commons\ContainerInjectableInterface; |
||||
6 | use Anax\Commons\ContainerInjectableTrait; |
||||
7 | |||||
8 | class Fetch2 implements ContainerInjectableInterface |
||||
9 | { |
||||
10 | use ContainerInjectableTrait; |
||||
11 | |||||
12 | private $curl; |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
13 | private $url; |
||||
14 | private $method; |
||||
15 | private $data; |
||||
16 | private $sweChars; |
||||
17 | |||||
18 | 13 | public function __construct(String $method = "GET", String $url = "", Array $data = []) |
|||
19 | { |
||||
20 | 13 | $this->method = $method; |
|||
21 | 13 | $this->url = $url; |
|||
22 | 13 | $this->data = $data; |
|||
23 | 13 | $this->sweChars = [ |
|||
24 | "å" => "a", |
||||
25 | "ä" => "a", |
||||
26 | "ö" => "o" |
||||
27 | ]; |
||||
28 | 13 | } |
|||
29 | |||||
30 | 1 | public function setMethod(String $method = "GET") |
|||
31 | { |
||||
32 | 1 | $this->method = $method; |
|||
33 | 1 | } |
|||
34 | |||||
35 | 1 | public function setUrl(String $url) |
|||
36 | { |
||||
37 | 1 | $this->url = $url; |
|||
38 | 1 | } |
|||
39 | |||||
40 | 2 | public function getMethod() : String |
|||
41 | { |
||||
42 | 2 | return $this->method; |
|||
43 | } |
||||
44 | |||||
45 | 11 | public function fetch(String $method, String $url, Array $params = [], Array $data = []) |
|||
0 ignored issues
–
show
The parameter
$params is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
46 | { |
||||
47 | 11 | $curl = curl_init(); |
|||
48 | 11 | $url = str_replace(array_keys($this->sweChars), $this->sweChars, $url);; |
|||
49 | 11 | switch ($method) { |
|||
50 | 11 | case "GET": |
|||
51 | 7 | break; |
|||
52 | 4 | case "POST": |
|||
53 | 1 | curl_setopt($curl, CURLOPT_POSTFIELDS, $data); |
|||
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
![]() |
|||||
54 | 1 | curl_setopt($curl, CURLOPT_POST, true); |
|||
55 | 1 | break; |
|||
56 | 3 | case "PUT": |
|||
57 | 1 | curl_setopt($curl, CURLOPT_POSTFIELDS, $data); |
|||
58 | 1 | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); |
|||
59 | 1 | break; |
|||
60 | 2 | case "DELETE": |
|||
61 | 1 | curl_setopt($curl, CURLOPT_POSTFIELDS, $data); |
|||
62 | 1 | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|||
63 | 1 | break; |
|||
64 | default: |
||||
65 | 1 | 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
![]() |
|||||
66 | 1 | return false; |
|||
67 | // break; |
||||
68 | } |
||||
69 | 10 | curl_setopt($curl, CURLOPT_URL, $url); |
|||
70 | 10 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|||
71 | 10 | $res = 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
![]() |
|||||
72 | 10 | curl_close($curl); |
|||
73 | |||||
74 | 10 | return $res; |
|||
75 | } |
||||
76 | |||||
77 | // public function multiFetch($urls = []) |
||||
78 | // { |
||||
79 | // $mc = curl_multi_init(); |
||||
80 | // $curls = []; |
||||
81 | // foreach ($urls as $url) { |
||||
82 | // // var_dump($urls); |
||||
83 | // // die(); |
||||
84 | // $curl = $this->prep($url[0], $url[1], $url[2]); |
||||
85 | // curl_multi_add_handle($mc, $curl); |
||||
86 | // array_push($curls, $curl); |
||||
87 | // } |
||||
88 | // do { |
||||
89 | // $status = curl_multi_exec($mc, $active); |
||||
90 | // if ($active) { |
||||
91 | // curl_multi_select($mc); |
||||
92 | // } |
||||
93 | // } while ($active && $status == CURLM_OK); |
||||
94 | // foreach ($curls as $curl) { |
||||
95 | // curl_multi_remove_handle($mc, $curl); |
||||
96 | // } |
||||
97 | // curl_multi_close($mc); |
||||
98 | |||||
99 | // return $mc; |
||||
100 | // } |
||||
101 | } |
||||
102 |