| Conditions | 6 |
| Paths | 8 |
| Total Lines | 55 |
| Code Lines | 38 |
| 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 |
||
| 21 | protected function handleApiCall($url, $method, array $headers = [], $requestData = null) |
||
| 22 | { |
||
| 23 | $this->outputCli('', true); |
||
| 24 | $this->outputCli(sprintf('REQUEST: %s %s', $method, $url), true); |
||
| 25 | |||
| 26 | $logger = new \WebServCo\Framework\Log\FileLogger( |
||
| 27 | 'ParcelValueAPI', |
||
| 28 | sprintf('%svar/log/', $this->data('path/project', '')), |
||
| 29 | $this->request() |
||
| 30 | ); |
||
| 31 | |||
| 32 | $apiHelper = new \ParcelValue\Api\Helper($logger, $this->config()->getEnv()); |
||
| 33 | $this->httpResponse = $apiHelper->getResponse($url, $method, $headers, $requestData); |
||
| 34 | |||
| 35 | $this->requestHeaders = $apiHelper->getRequestHeaders(); |
||
| 36 | foreach ($this->requestHeaders as $key => $value) { |
||
| 37 | $this->outputCli(sprintf('%s: %s', Ansi::sgr($key, [Sgr::BOLD]), $value), true); |
||
| 38 | } |
||
| 39 | if (Method::POST == $method) { |
||
| 40 | $this->outputCli('', true); |
||
| 41 | $this->outputCli($requestData, true); |
||
| 42 | } |
||
| 43 | |||
| 44 | $this->responseStatus = $this->httpResponse->getStatus(); |
||
| 45 | $this->responseHeaders = $this->httpResponse->getHeaders(); |
||
| 46 | $this->responseContent = $this->httpResponse->getContent(); |
||
| 47 | |||
| 48 | $this->outputCli('', true); |
||
| 49 | $statusCodes = \WebServCo\Framework\Http\StatusCode::getSupported(); |
||
| 50 | $this->outputCli( |
||
| 51 | sprintf( |
||
| 52 | 'RESPONSE: %s', |
||
| 53 | Ansi::sgr( |
||
| 54 | sprintf( |
||
| 55 | '%s %s', |
||
| 56 | $this->responseStatus, |
||
| 57 | $statusCodes[$this->responseStatus] ?: null |
||
| 58 | ), |
||
| 59 | [400 > $this->responseStatus ? Sgr::GREEN : sgr::RED] |
||
| 60 | ) |
||
| 61 | ), |
||
| 62 | true |
||
| 63 | ); |
||
| 64 | foreach ($this->responseHeaders as $key => $value) { |
||
| 65 | $this->outputCli(sprintf('%s: %s', Ansi::sgr($key, [Sgr::BOLD]), $value), true); |
||
| 66 | } |
||
| 67 | $this->outputCli('', true); |
||
| 68 | $this->outputCli($this->responseContent, true); |
||
| 69 | |||
| 70 | $this->outputCli('', true); |
||
| 71 | $this->outputCli( |
||
| 72 | sprintf('Processed result: %s', json_encode(json_decode($this->responseContent, true), JSON_PRETTY_PRINT)), |
||
| 73 | true |
||
| 74 | ); |
||
| 75 | return true; |
||
| 76 | } |
||
| 94 |