| Conditions | 6 |
| Paths | 5 |
| Total Lines | 51 |
| Code Lines | 33 |
| 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 |
||
| 103 | public function request( |
||
| 104 | RequestInterface $request, |
||
| 105 | ResponseInterface $response, |
||
| 106 | array $vars = [], |
||
| 107 | array $flags = [] |
||
| 108 | ) { |
||
| 109 | $transport = $this->getTransport(); |
||
| 110 | |||
| 111 | try { |
||
| 112 | $transferResponse = $transport->request( |
||
| 113 | $request->getMethod(), |
||
| 114 | (string) $request->getUri(), |
||
| 115 | $request->getHeaders(), |
||
| 116 | $vars, |
||
| 117 | $flags |
||
| 118 | ); |
||
| 119 | } catch (TransportException $exception) { |
||
| 120 | if ($this->closeOnError) { |
||
| 121 | $transport->close(); |
||
| 122 | } |
||
| 123 | |||
| 124 | // Bubble exception |
||
| 125 | throw $exception; |
||
| 126 | } |
||
| 127 | |||
| 128 | $transferInfo = $transport->responseInfo(); |
||
| 129 | $transport->close(); |
||
| 130 | |||
| 131 | $responseHeaders = ''; |
||
| 132 | $responseContent = $transferResponse; |
||
| 133 | |||
| 134 | if (isset($transferInfo['header_size']) && $transferInfo['header_size']) { |
||
| 135 | $headersSize = $transferInfo['header_size']; |
||
| 136 | |||
| 137 | $responseHeaders = rtrim(substr($transferResponse, 0, $headersSize)); |
||
| 138 | $responseContent = (strlen($transferResponse) === $headersSize) |
||
| 139 | ? '' |
||
| 140 | : substr($transferResponse, $headersSize); |
||
| 141 | } |
||
| 142 | |||
| 143 | // Split headers blocks |
||
| 144 | $responseHeaders = preg_split('/(\\r?\\n){2}/', $responseHeaders); |
||
| 145 | |||
| 146 | $responseHeaders = $this->getTransferHeaders( |
||
| 147 | preg_split('/\\r?\\n/', array_pop($responseHeaders)), |
||
| 148 | $responseContent, |
||
| 149 | $transferInfo |
||
| 150 | ); |
||
| 151 | |||
| 152 | return $this->populateResponse($response, $responseHeaders, $responseContent); |
||
| 153 | } |
||
| 154 | |||
| 216 |