| Conditions | 5 |
| Paths | 12 |
| Total Lines | 53 |
| Code Lines | 32 |
| 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 |
||
| 116 | protected function retrieve($url) |
||
| 117 | { |
||
| 118 | $this->debugInit(); |
||
| 119 | |||
| 120 | $this->curl = curl_init(); |
||
| 121 | curl_setopt_array( |
||
| 122 | $this->curl, |
||
| 123 | [ |
||
| 124 | CURLOPT_RETURNTRANSFER => true, /* return instead of outputting */ |
||
| 125 | CURLOPT_URL => $url, |
||
| 126 | CURLOPT_HEADER => true, /* include the header in the output */ |
||
| 127 | CURLOPT_FOLLOWLOCATION => true /* follow redirects */ |
||
| 128 | ] |
||
| 129 | ); |
||
| 130 | if ($this->setting('headers', false)) { |
||
| 131 | curl_setopt( |
||
| 132 | $this->curl, |
||
| 133 | CURLOPT_HTTPHEADER, |
||
| 134 | $this->parseRequestHeaders($this->setting('headers')) |
||
| 135 | ); |
||
| 136 | } |
||
| 137 | |||
| 138 | $this->debugDo(); |
||
| 139 | |||
| 140 | if ($this->method == Http::METHOD_POST) { |
||
| 141 | curl_setopt($this->curl, CURLOPT_POST, true); |
||
| 142 | if ($this->data('post', [])) { |
||
| 143 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, $this->data('post', [])); |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | $this->response = curl_exec($this->curl); |
||
| 148 | if (false === $this->response) { |
||
| 149 | throw new ApplicationException(curl_error($this->curl)); |
||
| 150 | } |
||
| 151 | |||
| 152 | $this->debugInfo = curl_getinfo($this->curl); |
||
| 153 | |||
| 154 | $httpCode = $this->getHttpCode(); |
||
| 155 | |||
| 156 | curl_close($this->curl); |
||
| 157 | |||
| 158 | list($headerString, $body) = explode("\r\n\r\n", $this->response, 2); |
||
| 159 | |||
| 160 | $body = trim($body); |
||
| 161 | $headers = $this->parseResponseHeaders($headerString); |
||
| 162 | |||
| 163 | $this->debugFinish(); |
||
| 164 | |||
| 165 | return new \WebServCo\Framework\HttpResponse( |
||
| 166 | $body, |
||
| 167 | $httpCode, |
||
| 168 | $headers |
||
| 169 | ); |
||
| 172 |