1 | <?PHP |
||
26 | class RestClient |
||
27 | { |
||
28 | /** |
||
29 | * Your API key. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | private $apiKey; |
||
34 | |||
35 | /** |
||
36 | * @var HttpClient |
||
37 | */ |
||
38 | protected $httpClient; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $apiHost; |
||
44 | |||
45 | /** |
||
46 | * @var CacheItemPoolInterface |
||
47 | */ |
||
48 | protected $cache; |
||
49 | |||
50 | /** |
||
51 | * @param string $apiKey |
||
52 | * @param string $apiHost |
||
53 | * @param HttpClient $httpClient |
||
54 | * @param CacheItemPoolInterface $cache |
||
55 | */ |
||
56 | public function __construct($apiKey, $apiHost, $httpClient = null, CacheItemPoolInterface $cache = null) |
||
63 | |||
64 | /** |
||
65 | * @return HttpClient |
||
66 | */ |
||
67 | protected function getHttpClient() |
||
81 | |||
82 | /** |
||
83 | * Sends the API request if cache not hit |
||
84 | * |
||
85 | * @param string $method |
||
86 | * @param string $uri |
||
87 | * @param null $body |
||
88 | * @param array $headers |
||
89 | * @param string $cacheKey |
||
90 | * @param integer $ttl |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | public function send($method, $uri, $body = null, array $headers = [], $cacheKey = null, $ttl = null) |
||
128 | |||
129 | /** |
||
130 | * Process the API response, provides error handling |
||
131 | * |
||
132 | * @param ResponseInterface $response |
||
133 | * |
||
134 | * @throws \Exception |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | public function processResponse(ResponseInterface $response) |
||
161 | |||
162 | /** |
||
163 | * @param string $endpointUrl |
||
164 | * @param array $queryString |
||
165 | * @param string|null $cacheKey |
||
166 | * @param integer|null $ttl |
||
167 | * |
||
168 | * @return ResponseInterface |
||
169 | */ |
||
170 | public function get($endpointUrl, $queryString = [], $cacheKey = null, $ttl = null) |
||
174 | |||
175 | /** |
||
176 | * @param string $endpointUrl |
||
177 | * @param array $postData |
||
178 | * |
||
179 | * @return \stdClass |
||
180 | */ |
||
181 | public function post($endpointUrl, array $postData = []) |
||
203 | |||
204 | /** |
||
205 | * @param $uri |
||
206 | * |
||
207 | * @return string |
||
208 | */ |
||
209 | private function getApiUrl($uri) |
||
213 | |||
214 | /** |
||
215 | * @param string $apiEndpoint |
||
216 | * |
||
217 | * @return string |
||
218 | */ |
||
219 | private function generateEndpoint($apiEndpoint) |
||
223 | } |
||
224 |
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.