1 | <?php |
||
21 | abstract class HttpApi |
||
22 | { |
||
23 | /** |
||
24 | * @var HttpClient |
||
25 | */ |
||
26 | protected $httpClient; |
||
27 | |||
28 | /** |
||
29 | * @var Hydrator |
||
30 | */ |
||
31 | protected $hydrator; |
||
32 | |||
33 | /** |
||
34 | * @var RequestBuilder |
||
35 | */ |
||
36 | protected $requestBuilder; |
||
37 | |||
38 | /** |
||
39 | * @param HttpClient $httpClient |
||
40 | * @param RequestBuilder $requestBuilder |
||
41 | * @param Hydrator $hydrator |
||
42 | */ |
||
43 | 19 | public function __construct(HttpClient $httpClient, Hydrator $hydrator, RequestBuilder $requestBuilder) |
|
51 | |||
52 | /** |
||
53 | * Send a GET request with query parameters. |
||
54 | * |
||
55 | * @param string $path Request path |
||
56 | * @param array $params GET parameters |
||
57 | * @param array $requestHeaders Request Headers |
||
58 | * |
||
59 | * @return ResponseInterface |
||
60 | */ |
||
61 | 11 | protected function httpGet(string $path, array $params = [], array $requestHeaders = []): ResponseInterface |
|
71 | |||
72 | /** |
||
73 | * Send a POST request with JSON-encoded parameters. |
||
74 | * |
||
75 | * @param string $path Request path |
||
76 | * @param array $params POST parameters to be JSON encoded |
||
77 | * @param array $requestHeaders Request headers |
||
78 | * |
||
79 | * @return ResponseInterface |
||
80 | */ |
||
81 | 4 | protected function httpPost(string $path, array $params = [], array $requestHeaders = []): ResponseInterface |
|
85 | |||
86 | /** |
||
87 | * Send a POST request with raw data. |
||
88 | * |
||
89 | * @param string $path Request path |
||
90 | * @param array|string $body Request body |
||
91 | * @param array $requestHeaders Request headers |
||
92 | * |
||
93 | * @return ResponseInterface |
||
94 | */ |
||
95 | 4 | protected function httpPostRaw(string $path, $body, array $requestHeaders = []): ResponseInterface |
|
101 | |||
102 | /** |
||
103 | * Send a PUT request with JSON-encoded parameters. |
||
104 | * |
||
105 | * @param string $path Request path |
||
106 | * @param array $params POST parameters to be JSON encoded |
||
107 | * @param array $requestHeaders Request headers |
||
108 | * |
||
109 | * @return ResponseInterface |
||
110 | */ |
||
111 | 4 | protected function httpPut(string $path, array $params = [], array $requestHeaders = []): ResponseInterface |
|
117 | |||
118 | /** |
||
119 | * Send a DELETE request with JSON-encoded parameters. |
||
120 | * |
||
121 | * @param string $path Request path |
||
122 | * @param array $params POST parameters to be JSON encoded |
||
123 | * @param array $requestHeaders Request headers |
||
124 | * |
||
125 | * @return ResponseInterface |
||
126 | */ |
||
127 | 1 | protected function httpDelete(string $path, array $params = [], array $requestHeaders = []): ResponseInterface |
|
133 | |||
134 | /** |
||
135 | * Create a JSON encoded version of an array of parameters. |
||
136 | * |
||
137 | * @param array $params Request parameters |
||
138 | * |
||
139 | * @return null|string |
||
140 | */ |
||
141 | 9 | private function createJsonBody(array $params) |
|
145 | |||
146 | /** |
||
147 | * Handle HTTP errors. |
||
148 | * |
||
149 | * Call is controlled by the specific API methods. |
||
150 | * |
||
151 | * @param ResponseInterface $response |
||
152 | * |
||
153 | * @throws \Billogram\Exception\DomainException |
||
154 | */ |
||
155 | protected function handleErrors(ResponseInterface $response) |
||
169 | |||
170 | /** |
||
171 | * @param ResponseInterface $response |
||
172 | * @param string $class to hydrate |
||
173 | * |
||
174 | * @return mixed |
||
175 | * |
||
176 | * @throws \Billogram\Exception |
||
177 | */ |
||
178 | 19 | protected function handleResponse(ResponseInterface $response, $class) |
|
190 | } |
||
191 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.