| Conditions | 20 |
| Paths | 1011 |
| Total Lines | 103 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 127 | public function write( |
||
| 128 | $method, $uri, $http_ver = '1.1', $headers = array(), $body = '' |
||
| 129 | ) |
||
| 130 | { |
||
| 131 | // If no proxy is set, fall back to default Socket adapter |
||
| 132 | if (!$this->config['proxy_host']) { |
||
| 133 | return parent::write($method, $uri, $http_ver, $headers, $body); |
||
| 134 | } |
||
| 135 | |||
| 136 | // Make sure we're properly connected |
||
| 137 | if (!$this->socket) { |
||
| 138 | require_once 'Zend/Http/Client/Adapter/Exception.php'; |
||
| 139 | throw new Zend_Http_Client_Adapter_Exception( |
||
| 140 | 'Trying to write but we are not connected' |
||
| 141 | ); |
||
| 142 | } |
||
| 143 | |||
| 144 | $host = $this->config['proxy_host']; |
||
| 145 | $port = $this->config['proxy_port']; |
||
| 146 | |||
| 147 | if ($this->connected_to[0] != "tcp://$host" |
||
| 148 | || $this->connected_to[1] != $port |
||
| 149 | ) { |
||
| 150 | require_once 'Zend/Http/Client/Adapter/Exception.php'; |
||
| 151 | throw new Zend_Http_Client_Adapter_Exception( |
||
| 152 | 'Trying to write but we are connected to the wrong proxy server' |
||
| 153 | ); |
||
| 154 | } |
||
| 155 | |||
| 156 | // Add Proxy-Authorization header |
||
| 157 | if ($this->config['proxy_user']) { |
||
| 158 | // Check to see if one already exists |
||
| 159 | $hasProxyAuthHeader = false; |
||
| 160 | foreach ($headers as $k => $v) { |
||
| 161 | if ((string) $k == 'proxy-authorization' |
||
| 162 | || preg_match("/^proxy-authorization:/i", $v) |
||
| 163 | ) { |
||
| 164 | $hasProxyAuthHeader = true; |
||
| 165 | break; |
||
| 166 | } |
||
| 167 | } |
||
| 168 | if (!$hasProxyAuthHeader) { |
||
| 169 | $headers[] = 'Proxy-authorization: ' |
||
| 170 | . Zend_Http_Client::encodeAuthHeader( |
||
| 171 | $this->config['proxy_user'], |
||
| 172 | $this->config['proxy_pass'], $this->config['proxy_auth'] |
||
| 173 | ); |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 177 | // if we are proxying HTTPS, preform CONNECT handshake with the proxy |
||
| 178 | if ($uri->getScheme() == 'https' && (!$this->negotiated)) { |
||
| 179 | $this->connectHandshake( |
||
| 180 | $uri->getHost(), $uri->getPort(), $http_ver, $headers |
||
| 181 | ); |
||
| 182 | $this->negotiated = true; |
||
| 183 | } |
||
| 184 | |||
| 185 | // Save request method for later |
||
| 186 | $this->method = $method; |
||
| 187 | |||
| 188 | // Build request headers |
||
| 189 | if ($this->negotiated) { |
||
| 190 | $path = $uri->getPath(); |
||
| 191 | if ($uri->getQuery()) { |
||
| 192 | $path .= '?' . $uri->getQuery(); |
||
| 193 | } |
||
| 194 | $request = "$method $path HTTP/$http_ver\r\n"; |
||
| 195 | } else { |
||
| 196 | $request = "$method $uri HTTP/$http_ver\r\n"; |
||
| 197 | } |
||
| 198 | |||
| 199 | // Add all headers to the request string |
||
| 200 | foreach ($headers as $k => $v) { |
||
| 201 | if (is_string($k)) $v = "$k: $v"; |
||
| 202 | $request .= "$v\r\n"; |
||
| 203 | } |
||
| 204 | |||
| 205 | if(is_resource($body)) { |
||
| 206 | $request .= "\r\n"; |
||
| 207 | } else { |
||
| 208 | // Add the request body |
||
| 209 | $request .= "\r\n" . $body; |
||
| 210 | } |
||
| 211 | |||
| 212 | // Send the request |
||
| 213 | if (!@fwrite($this->socket, $request)) { |
||
| 214 | require_once 'Zend/Http/Client/Adapter/Exception.php'; |
||
| 215 | throw new Zend_Http_Client_Adapter_Exception( |
||
| 216 | 'Error writing request to proxy server' |
||
| 217 | ); |
||
| 218 | } |
||
| 219 | |||
| 220 | if(is_resource($body)) { |
||
| 221 | if(stream_copy_to_stream($body, $this->socket) == 0) { |
||
| 222 | require_once 'Zend/Http/Client/Adapter/Exception.php'; |
||
| 223 | throw new Zend_Http_Client_Adapter_Exception( |
||
| 224 | 'Error writing request to server' |
||
| 225 | ); |
||
| 226 | } |
||
| 227 | } |
||
| 228 | |||
| 229 | return $request; |
||
| 230 | } |
||
| 344 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.