Conditions | 5 |
Paths | 4 |
Total Lines | 63 |
Code Lines | 44 |
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 |
||
39 | public function create($clientId, $clientKey, $serverKey) |
||
40 | { |
||
41 | $this->outputCli('', true); |
||
42 | $this->outputCli(Ansi::sgr(__METHOD__, [Sgr::BOLD]), true); |
||
43 | |||
44 | $url = sprintf( |
||
45 | '%s%s/shipments', |
||
46 | $this->config()->get('app/api/url'), |
||
47 | $this->config()->get('app/api/version') |
||
48 | ); |
||
49 | |||
50 | $jwt = \ParcelValue\Api\AuthenticationToken::generate($clientId, $clientKey, $serverKey); |
||
51 | $this->curlBrowser->setRequestHeader('Authorization', sprintf('Bearer %s', $jwt)); |
||
52 | $this->curlBrowser->setRequestHeader('Content-Type', Document::CONTENT_TYPE); |
||
53 | |||
54 | $shipment = $this->repository->getTestShipment(); |
||
55 | |||
56 | $document = new Document(); |
||
57 | $document->setData($shipment); |
||
58 | $postData = $document->toJson(); |
||
59 | |||
60 | $this->outputCli('', true); |
||
61 | $this->outputCli(sprintf('REQUEST: POST %s', $url), true); |
||
62 | $this->httpResponse = $this->curlBrowser->post($url, $postData); |
||
63 | $this->requestHeaders = $this->curlBrowser->getRequestHeaders(); |
||
64 | foreach ($this->requestHeaders as $key => $value) { |
||
65 | $this->outputCli(sprintf('%s: %s', Ansi::sgr($key, [Sgr::BOLD]), $value), true); |
||
66 | } |
||
67 | $this->outputCli('', true); |
||
68 | $this->outputCli($postData, true); |
||
69 | |||
70 | $this->responseStatus = $this->httpResponse->getStatus(); |
||
71 | $this->responseHeaders = $this->httpResponse->getHeaders(); |
||
72 | $this->responseContent = $this->httpResponse->getContent(); |
||
73 | |||
74 | $this->outputCli('', true); |
||
75 | $this->outputCli( |
||
76 | sprintf( |
||
77 | 'RESPONSE: %s', |
||
78 | Ansi::sgr( |
||
79 | sprintf( |
||
80 | '%s %s', |
||
81 | $this->responseStatus, |
||
82 | Http::$statusCodes[$this->responseStatus] ?: null |
||
83 | ), |
||
84 | [400 > $this->responseStatus ? Sgr::GREEN : sgr::RED] |
||
85 | ) |
||
86 | ), |
||
87 | true |
||
88 | ); |
||
89 | foreach ($this->responseHeaders as $key => $value) { |
||
90 | $this->outputCli(sprintf('%s: %s', Ansi::sgr($key, [Sgr::BOLD]), $value), true); |
||
91 | } |
||
92 | $this->outputCli('', true); |
||
93 | $this->outputCli($this->responseContent, true); |
||
94 | |||
95 | $this->outputCli('', true); |
||
96 | $this->outputCli( |
||
97 | sprintf('Processed result: %s', json_encode(json_decode($this->responseContent, true), JSON_PRETTY_PRINT)), |
||
98 | true |
||
99 | ); |
||
100 | |||
101 | return new CliResponse('', true); |
||
102 | } |
||
104 |