Conditions | 5 |
Paths | 2 |
Total Lines | 56 |
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 |
||
104 | private function request($options = []) |
||
105 | { |
||
106 | $curl = curl_init(); |
||
107 | $caPathOrFile = CaBundle::getSystemCaRootBundlePath(); |
||
108 | // Set default cURL options |
||
109 | curl_setopt_array($curl, [ |
||
110 | CURLOPT_AUTOREFERER => true, |
||
111 | CURLOPT_CONNECTTIMEOUT => 30, |
||
112 | CURLOPT_ENCODING => 'identity', |
||
113 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_NONE, |
||
114 | CURLOPT_IPRESOLVE => CURL_IPRESOLVE_WHATEVER, |
||
115 | CURLOPT_SSL_VERIFYHOST => 2, |
||
116 | CURLOPT_SSL_VERIFYPEER => true, |
||
117 | CURLOPT_TIMEOUT => 120, |
||
118 | CURLOPT_USERAGENT => self::CURL_USER_AGENT, |
||
119 | (is_dir($caPathOrFile) || |
||
120 | ( |
||
121 | is_link($caPathOrFile) && |
||
122 | is_dir(readlink($caPathOrFile)) |
||
123 | ) |
||
124 | ) ? CURLOPT_CAPATH : CURLOPT_CAINFO => $caPathOrFile |
||
125 | ]); |
||
126 | // Apply custom cURL options |
||
127 | curl_setopt_array($curl, $options); |
||
128 | // Initialize the header parser |
||
129 | $this->headerParser = new Parser\HeaderParser($curl); |
||
130 | // Make sure these cURL options stays untouched |
||
131 | curl_setopt_array($curl, [ |
||
132 | CURLOPT_FAILONERROR => false, |
||
133 | CURLOPT_FOLLOWLOCATION => true, |
||
134 | CURLOPT_FTPSSLAUTH => CURLFTPAUTH_DEFAULT, |
||
135 | CURLOPT_HEADER => false, |
||
136 | CURLOPT_HEADERFUNCTION => [$this->headerParser, 'curlCallback'], |
||
137 | CURLOPT_HTTPAUTH => CURLAUTH_BASIC, |
||
138 | CURLOPT_MAXREDIRS => self::MAX_REDIRECTS, |
||
139 | CURLOPT_NOBODY => false, |
||
140 | CURLOPT_PROTOCOLS => CURLPROTO_FTP | CURLPROTO_FTPS | CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_SFTP, |
||
141 | CURLOPT_REDIR_PROTOCOLS => CURLPROTO_FTP | CURLPROTO_FTPS | CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_SFTP, |
||
142 | CURLOPT_RETURNTRANSFER => true, |
||
143 | CURLOPT_URL => $this->base . self::PATH, |
||
144 | CURLOPT_USERPWD => 'anonymous:anonymous@', |
||
145 | ]); |
||
146 | // Execute cURL request |
||
147 | if (($this->rawContents = curl_exec($curl)) === false) { |
||
148 | // Request failed |
||
149 | return false; |
||
150 | } |
||
151 | $this->time = time(); |
||
152 | $this->rawStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); // also works with FTP status codes |
||
153 | $uriParser = new UriParser(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL)); |
||
154 | $this->effective = $uriParser->base(); |
||
155 | curl_close($curl); |
||
156 | $this->rawEncoding = $this->headerParser->getCharset(); |
||
157 | $this->rawMaxAge = $this->headerParser->getMaxAge(); |
||
158 | return true; |
||
159 | } |
||
160 | |||
237 |