| Conditions | 9 |
| Paths | 48 |
| Total Lines | 55 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 19 | ||
| Bugs | 0 | Features | 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 |
||
| 108 | private function _call($url, $params = null, $headers = null, $method = "GET") |
||
| 109 | { |
||
| 110 | $ch = curl_init(); |
||
| 111 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_URL, $url); |
||
| 112 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_FOLLOWLOCATION, false); |
||
| 113 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_TIMEOUT, $this->_timeout); |
||
| 114 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_RETURNTRANSFER, true); |
||
| 115 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_SSL_VERIFYPEER, $this->_verify_ssl); |
||
| 116 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_SSL_VERIFYHOST, $this->_verify_host); |
||
| 117 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_HEADER, true); |
||
| 118 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLINFO_HEADER_OUT, true); |
||
| 119 | if ($this->curlProxy) { |
||
| 120 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_PROXY, $this->curlProxy); |
||
| 121 | } |
||
| 122 | if ($this->_curl_callback) { |
||
| 123 | call_user_func($this->_curl_callback, $ch, $params, $headers, $method); |
||
| 124 | } |
||
| 125 | switch (strtoupper($method)) { |
||
| 126 | case 'PATCH': |
||
| 127 | if (!empty($params)) { |
||
| 128 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); |
||
| 129 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_POSTFIELDS, json_encode($params)); |
||
| 130 | } |
||
| 131 | break; |
||
| 132 | case 'DELETE': |
||
| 133 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
||
| 134 | break; |
||
| 135 | case 'POST': |
||
| 136 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_POST, true); |
||
| 137 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_POSTFIELDS, $params); |
||
| 138 | break; |
||
| 139 | case 'GET': |
||
| 140 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_HTTPGET, true); |
||
| 141 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_URL, $url); |
||
| 142 | break; |
||
| 143 | } |
||
| 144 | |||
| 145 | curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_HTTPHEADER, $this->_createHeaders($headers)); |
||
| 146 | |||
| 147 | $this->request['method'] = strtoupper($method); |
||
| 148 | $this->request['headers'] = $this->_createHeaders($headers); |
||
| 149 | $this->request['params'] = $params; |
||
| 150 | |||
| 151 | $this->response = curl_exec(/** @scrutinizer ignore-type */ $ch); |
||
| 152 | |||
| 153 | if (curl_errno(/** @scrutinizer ignore-type */ $ch)) { |
||
| 154 | $this->curlErrno = curl_errno(/** @scrutinizer ignore-type */ $ch); |
||
| 155 | $this->curlError = curl_error(/** @scrutinizer ignore-type */ $ch); |
||
| 156 | curl_close(/** @scrutinizer ignore-type */ $ch); |
||
| 157 | return; |
||
| 158 | } |
||
| 159 | |||
| 160 | $this->curlInfo = curl_getinfo(/** @scrutinizer ignore-type */ $ch); |
||
| 161 | curl_close(/** @scrutinizer ignore-type */ $ch); |
||
| 162 | return new Result($this->_getBody(), $this->_getHeaders(), $this->curlInfo); |
||
| 163 | } |
||
| 279 |