| Conditions | 5 |
| Paths | 12 |
| Total Lines | 59 |
| Code Lines | 34 |
| 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 |
||
| 135 | protected function retrieve($url) |
||
| 136 | { |
||
| 137 | $this->debugInit(); |
||
| 138 | |||
| 139 | $this->curl = curl_init(); |
||
| 140 | curl_setopt_array( |
||
| 141 | $this->curl, |
||
| 142 | [ |
||
| 143 | CURLOPT_RETURNTRANSFER => true, /* return instead of outputting */ |
||
| 144 | CURLOPT_URL => $url, |
||
| 145 | CURLOPT_HEADER => true, /* include the header in the output */ |
||
| 146 | CURLOPT_FOLLOWLOCATION => true /* follow redirects */ |
||
| 147 | ] |
||
| 148 | ); |
||
| 149 | if (!empty($this->requestHeaders)) { |
||
| 150 | curl_setopt( |
||
| 151 | $this->curl, |
||
| 152 | CURLOPT_HTTPHEADER, |
||
| 153 | $this->parseRequestHeaders($this->requestHeaders) |
||
| 154 | ); |
||
| 155 | } |
||
| 156 | |||
| 157 | $this->debugDo(); |
||
| 158 | |||
| 159 | if ($this->method == Http::METHOD_POST) { |
||
| 160 | curl_setopt($this->curl, CURLOPT_POST, true); |
||
| 161 | if (!empty($this->postData)) { |
||
| 162 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, $this->postData); |
||
| 163 | } |
||
| 164 | } |
||
| 165 | |||
| 166 | $this->response = curl_exec($this->curl); |
||
| 167 | if (false === $this->response) { |
||
| 168 | throw new ApplicationException(curl_error($this->curl)); |
||
| 169 | } |
||
| 170 | |||
| 171 | $this->debugInfo = curl_getinfo($this->curl); |
||
| 172 | |||
| 173 | $httpCode = $this->getHttpCode(); |
||
| 174 | |||
| 175 | curl_close($this->curl); |
||
| 176 | |||
| 177 | /** |
||
| 178 | * For redirects, the response will contain evey header/body pair. |
||
| 179 | * The last header/body will be at the end of the response. |
||
| 180 | */ |
||
| 181 | $responseParts = explode("\r\n\r\n", $this->response); |
||
| 182 | $body = array_pop($responseParts); |
||
| 183 | $headerString = array_pop($responseParts); |
||
| 184 | |||
| 185 | $body = trim($body); |
||
| 186 | $headers = $this->parseResponseHeaders($headerString); |
||
| 187 | |||
| 188 | $this->debugFinish(); |
||
| 189 | |||
| 190 | return new \WebServCo\Framework\HttpResponse( |
||
| 191 | $body, |
||
| 192 | $httpCode, |
||
| 193 | $headers |
||
| 194 | ); |
||
| 197 |