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