| Conditions | 7 |
| Paths | 12 |
| Total Lines | 52 |
| 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 |
||
| 95 | private function exec(array $curlOptions, array $requestHeaders) |
||
| 96 | { |
||
| 97 | $headerList = []; |
||
| 98 | |||
| 99 | $this->curlReset(); |
||
| 100 | |||
| 101 | $defaultCurlOptions = [ |
||
| 102 | CURLOPT_HEADER => false, |
||
| 103 | CURLOPT_CONNECTTIMEOUT => 5, |
||
| 104 | CURLOPT_TIMEOUT => 10, |
||
| 105 | CURLOPT_RETURNTRANSFER => true, |
||
| 106 | CURLOPT_HTTPHEADER => [], |
||
| 107 | CURLOPT_FOLLOWLOCATION => false, |
||
| 108 | CURLOPT_PROTOCOLS => $this->allowHttp ? CURLPROTO_HTTPS | CURLPROTO_HTTP : CURLPROTO_HTTPS, |
||
| 109 | CURLOPT_HEADERFUNCTION => function ($curlChannel, $headerData) use (&$headerList) { |
||
| 110 | if (false !== strpos($headerData, ':')) { |
||
| 111 | list($key, $value) = explode(':', $headerData, 2); |
||
| 112 | $headerList[trim($key)] = trim($value); |
||
| 113 | } |
||
| 114 | |||
| 115 | return strlen($headerData); |
||
| 116 | }, |
||
| 117 | ]; |
||
| 118 | |||
| 119 | if (0 !== count($requestHeaders)) { |
||
| 120 | $curlRequestHeaders = []; |
||
| 121 | foreach ($requestHeaders as $k => $v) { |
||
| 122 | $curlRequestHeaders[] = sprintf('%s: %s', $k, $v); |
||
| 123 | } |
||
| 124 | $defaultCurlOptions[CURLOPT_HTTPHEADER] = $curlRequestHeaders; |
||
| 125 | } |
||
| 126 | |||
| 127 | if (false === curl_setopt_array($this->curlChannel, $curlOptions + $defaultCurlOptions)) { |
||
| 128 | throw new CurlException('unable to set cURL options'); |
||
| 129 | } |
||
| 130 | |||
| 131 | if (false === $responseData = curl_exec($this->curlChannel)) { |
||
| 132 | throw new CurlException( |
||
| 133 | sprintf( |
||
| 134 | '[%d] %s', |
||
| 135 | curl_errno($this->curlChannel), |
||
| 136 | curl_error($this->curlChannel) |
||
| 137 | ) |
||
| 138 | ); |
||
| 139 | } |
||
| 140 | |||
| 141 | return new Response( |
||
| 142 | curl_getinfo($this->curlChannel, CURLINFO_HTTP_CODE), |
||
| 143 | $responseData, |
||
| 144 | $headerList |
||
| 145 | ); |
||
| 146 | } |
||
| 147 | } |
||
| 148 |