| Conditions | 8 |
| Paths | 52 |
| Total Lines | 51 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types=1); |
||
| 156 | public function getItemsDataProvider(int $dataProviderId, int $limit = 1000, int $offset = 0, ?bool $active = null, ?int $countryId = null): array |
||
| 157 | { |
||
| 158 | // Endpoint URI |
||
| 159 | $uri = sprintf('v1/dataproviders/%d/agencies', $dataProviderId); |
||
| 160 | |||
| 161 | $options = [ |
||
| 162 | 'query' => [ |
||
| 163 | 'limit' => $limit, |
||
| 164 | 'offset' => $offset, |
||
| 165 | 'active' => $active, |
||
| 166 | 'countryId' => $countryId |
||
| 167 | ], |
||
| 168 | ]; |
||
| 169 | |||
| 170 | |||
| 171 | $agencies = []; |
||
| 172 | |||
| 173 | try { |
||
| 174 | $data = null; |
||
| 175 | |||
| 176 | // try to get from cache |
||
| 177 | if ($this->cache) { |
||
| 178 | $data = $this->cache->get($this->cachePrefix, $uri, $options); |
||
| 179 | } |
||
| 180 | |||
| 181 | // load from API |
||
| 182 | if (!$data) { |
||
| 183 | $data = $this->httpClient->get($uri, $options)->getBody()->getContents(); |
||
| 184 | |||
| 185 | if ($this->cache && $data) { |
||
| 186 | $this->cache->put($this->cachePrefix, $uri, $options, $data); |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | $classArray = \json_decode($data); |
||
| 191 | |||
| 192 | foreach ($classArray as $class) { |
||
| 193 | $agencies[] = AgencyHydrator::fromStdClass($class); |
||
| 194 | } |
||
| 195 | } catch (ClientException $e) { |
||
| 196 | $response = $e->getResponse(); |
||
| 197 | if ($response === null) { |
||
| 198 | throw new RuntimeException('Null response'); |
||
| 199 | } |
||
| 200 | $responseBody = $response->getBody()->getContents(); |
||
| 201 | $responseCode = $response->getStatusCode(); |
||
| 202 | |||
| 203 | throw ApiException::translate($responseBody, $responseCode); |
||
| 204 | } |
||
| 205 | |||
| 206 | return $agencies; |
||
| 207 | } |
||
| 210 |