1 | <?php |
||
21 | abstract class HttpApi |
||
22 | { |
||
23 | /** |
||
24 | * @var HttpClient |
||
25 | */ |
||
26 | protected $httpClient; |
||
27 | /** |
||
28 | * @var Hydrator |
||
29 | */ |
||
30 | protected $hydrator; |
||
31 | /** |
||
32 | * @var RequestBuilder |
||
33 | */ |
||
34 | protected $requestBuilder; |
||
35 | |||
36 | /** |
||
37 | * @param HttpClient $httpClient |
||
38 | * @param RequestBuilder $requestBuilder |
||
39 | * @param Hydrator $hydrator |
||
40 | */ |
||
41 | 19 | public function __construct(HttpClient $httpClient, Hydrator $hydrator, RequestBuilder $requestBuilder) |
|
49 | |||
50 | /** |
||
51 | * Send a GET request with query parameters. |
||
52 | * |
||
53 | * @param string $path Request path |
||
54 | * @param array $params GET parameters |
||
55 | * @param array $requestHeaders Request Headers |
||
56 | * |
||
57 | * @return ResponseInterface |
||
58 | */ |
||
59 | 11 | protected function httpGet(string $path, array $params = [], array $requestHeaders = []): ResponseInterface |
|
69 | |||
70 | /** |
||
71 | * Send a POST request with JSON-encoded parameters. |
||
72 | * |
||
73 | * @param string $path Request path |
||
74 | * @param array $params POST parameters to be JSON encoded |
||
75 | * @param array $requestHeaders Request headers |
||
76 | * |
||
77 | * @return ResponseInterface |
||
78 | */ |
||
79 | 4 | protected function httpPost(string $path, array $params = [], array $requestHeaders = []): ResponseInterface |
|
83 | |||
84 | /** |
||
85 | * Send a POST request with raw data. |
||
86 | * |
||
87 | * @param string $path Request path |
||
88 | * @param array|string $body Request body |
||
89 | * @param array $requestHeaders Request headers |
||
90 | * |
||
91 | * @return ResponseInterface |
||
92 | */ |
||
93 | 4 | protected function httpPostRaw(string $path, $body, array $requestHeaders = []): ResponseInterface |
|
99 | |||
100 | /** |
||
101 | * Send a PUT request with JSON-encoded parameters. |
||
102 | * |
||
103 | * @param string $path Request path |
||
104 | * @param array $params POST parameters to be JSON encoded |
||
105 | * @param array $requestHeaders Request headers |
||
106 | * |
||
107 | * @return ResponseInterface |
||
108 | */ |
||
109 | 4 | protected function httpPut(string $path, array $params = [], array $requestHeaders = []): ResponseInterface |
|
115 | |||
116 | /** |
||
117 | * Send a DELETE request with JSON-encoded parameters. |
||
118 | * |
||
119 | * @param string $path Request path |
||
120 | * @param array $params POST parameters to be JSON encoded |
||
121 | * @param array $requestHeaders Request headers |
||
122 | * |
||
123 | * @return ResponseInterface |
||
124 | */ |
||
125 | 1 | protected function httpDelete(string $path, array $params = [], array $requestHeaders = []): ResponseInterface |
|
131 | |||
132 | /** |
||
133 | * Create a JSON encoded version of an array of parameters. |
||
134 | * |
||
135 | * @param array $params Request parameters |
||
136 | * |
||
137 | * @return null|string |
||
138 | */ |
||
139 | 9 | private function createJsonBody(array $params) |
|
143 | |||
144 | /** |
||
145 | * Handle HTTP errors. |
||
146 | * |
||
147 | * Call is controlled by the specific API methods. |
||
148 | * |
||
149 | * @param ResponseInterface $response |
||
150 | * |
||
151 | * @throws \Billogram\Exception\DomainException |
||
152 | */ |
||
153 | protected function handleErrors(ResponseInterface $response) |
||
167 | |||
168 | /** |
||
169 | * @param ResponseInterface $response |
||
170 | * @param string $class to hydrate |
||
171 | * |
||
172 | * @return mixed |
||
173 | * |
||
174 | * @throws \Billogram\Exception |
||
175 | */ |
||
176 | 19 | protected function handleResponse(ResponseInterface $response, $class) |
|
188 | } |
||
189 |
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.