These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace CanalTP\AbstractGuzzle\Version; |
||
4 | |||
5 | use GuzzleHttp\Psr7\Request; |
||
6 | use GuzzleHttp\Psr7\Response; |
||
7 | use GuzzleHttp\Stream\Stream; |
||
8 | use GuzzleHttp\Client; |
||
9 | use CanalTP\AbstractGuzzle\Guzzle; |
||
10 | |||
11 | class Guzzle5 extends Guzzle |
||
12 | { |
||
13 | /** |
||
14 | * @var Client |
||
15 | */ |
||
16 | private $client; |
||
17 | |||
18 | /** |
||
19 | * {@InheritDoc} |
||
20 | */ |
||
21 | public function __construct($baseUri, $options = []) |
||
22 | { |
||
23 | $this->defaultOptions = [ |
||
24 | 'base_url' => $baseUri, |
||
25 | 'defaults' => $options |
||
26 | ]; |
||
27 | |||
28 | $this->client = new Client($this->defaultOptions); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * We have to recreate client to modify baseUri |
||
33 | * |
||
34 | * @param string $baseUri |
||
35 | */ |
||
36 | public function setBaseUri($baseUri) |
||
37 | { |
||
38 | $this->__construct($baseUri, []); |
||
39 | } |
||
40 | |||
41 | public function getBaseUri() |
||
42 | { |
||
43 | return $this->client->getBaseUrl(); |
||
44 | } |
||
45 | |||
46 | public function setDefaultOptions($options = []) |
||
47 | { |
||
48 | $this->__construct($this->getBaseUri(), $options); |
||
49 | } |
||
50 | |||
51 | public function getDefaultOptions() |
||
52 | { |
||
53 | return $this->client->getDefaultOption(); |
||
54 | } |
||
55 | |||
56 | public function setDefaultAuth($username, $password, $type = 'basic') |
||
57 | { |
||
58 | $this->client->setDefaultOption('auth', [$username, $password, $type]); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @return Client |
||
63 | */ |
||
64 | public function getClient() |
||
65 | { |
||
66 | return $this->client; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @param Client $client |
||
71 | * |
||
72 | * @return self |
||
73 | */ |
||
74 | public function setClient(Client $client) |
||
75 | { |
||
76 | $this->client = $client; |
||
77 | |||
78 | return $this; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * {@InheritDoc} |
||
83 | */ |
||
84 | View Code Duplication | public function send(Request $request) |
|
85 | { |
||
86 | $guzzleRequest = $this->client->createRequest( |
||
87 | $request->getMethod(), |
||
88 | $request->getUri(), |
||
89 | ['headers' => $request->getHeaders()] |
||
90 | ); |
||
91 | |||
92 | $guzzleRequest->setBody(Stream::factory($request->getBody())); |
||
93 | |||
94 | $guzzleResponse = $this->getClient()->send($guzzleRequest); |
||
95 | |||
96 | $response = new Response( |
||
97 | $guzzleResponse->getStatusCode(), |
||
98 | $guzzleResponse->getHeaders(), |
||
99 | $guzzleResponse->getBody(true) |
||
0 ignored issues
–
show
|
|||
100 | ); |
||
101 | |||
102 | return $response; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Used to mock client |
||
107 | * |
||
108 | * @return \GuzzleHttp\Event\Emitter|\GuzzleHttp\Event\EmitterInterface |
||
109 | */ |
||
110 | public function getEmitter() |
||
111 | { |
||
112 | return $this->client->getEmitter(); |
||
113 | } |
||
114 | } |
||
115 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.