| Conditions | 10 |
| Paths | 12 |
| Total Lines | 39 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 75 | public function call($payload = null, $uri, $hydrationClass = null, $isList = false, $method = 'GET', array $queryParams = [], $isJson = true) |
||
| 76 | { |
||
| 77 | $uri = rtrim(sprintf('%s/%s', $this->apiUri, $uri), '/'); |
||
| 78 | |||
| 79 | if (count($queryParams) > 0) { |
||
| 80 | $uri .= '?'.http_build_query($queryParams); |
||
| 81 | } |
||
| 82 | |||
| 83 | $request = new Request($method, $uri, [ |
||
| 84 | 'X-API-Key' => $this->apiKey, |
||
| 85 | 'Content-Type' => 'application/json', |
||
| 86 | ], $payload); |
||
| 87 | |||
| 88 | $response = $this->client->sendRequest($request); |
||
| 89 | $responseBody = $response->getBody()->getContents(); |
||
| 90 | |||
| 91 | if (!$isJson) { |
||
| 92 | return $responseBody; |
||
| 93 | } |
||
| 94 | |||
| 95 | $responseData = json_decode($responseBody); |
||
| 96 | |||
| 97 | |||
| 98 | if ($response->getStatusCode() >= 300 && isset($responseData->error)) { |
||
| 99 | throw new \LogicException(sprintf('Error on %s request %s: %s', $method, $uri, $responseData->error)); |
||
| 100 | } |
||
| 101 | if ($response->getStatusCode() >= 300) { |
||
| 102 | $message = isset($responseData->message) ?? 'Unknown'; |
||
| 103 | throw new \Exception(sprintf('Error on request %s: %s', $response->getStatusCode(), $message)); |
||
| 104 | } |
||
| 105 | |||
| 106 | if (null !== $hydrationClass && class_exists($hydrationClass)) { |
||
| 107 | return $this->denormalizeObject($hydrationClass, $responseData, $isList); |
||
| 108 | } |
||
| 109 | if (null !== $hydrationClass && !class_exists($hydrationClass)) { |
||
| 110 | throw new \Exception(sprintf('HydrationClass (%s) does not exist', $hydrationClass)); |
||
| 111 | } |
||
| 112 | |||
| 113 | return $responseData; |
||
| 114 | } |
||
| 145 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..