Conditions | 14 |
Paths | 93 |
Total Lines | 48 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 210 |
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 |
||
143 | private static function httpRequest($url, $user, $pass) |
||
144 | { |
||
145 | if (self::$cacheDir) { |
||
146 | $cacheFile = self::$cacheDir . '/feed.' . md5($url) . '.xml'; |
||
147 | if (@filemtime($cacheFile) + self::$cacheExpire > time()) { |
||
148 | return file_get_contents($cacheFile); |
||
149 | } |
||
150 | } |
||
151 | |||
152 | if (extension_loaded('curl')) { |
||
153 | $curl = curl_init(); |
||
154 | curl_setopt($curl, CURLOPT_URL, $url); |
||
155 | if ($user !== NULL || $pass !== NULL) { |
||
156 | curl_setopt($curl, CURLOPT_USERPWD, "$user:$pass"); |
||
157 | } |
||
158 | curl_setopt($curl, CURLOPT_HEADER, FALSE); |
||
159 | curl_setopt($curl, CURLOPT_TIMEOUT, 20); |
||
160 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // no echo, just return result |
||
161 | if (!ini_get('open_basedir')) { |
||
162 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); // sometime is useful :) |
||
163 | } |
||
164 | $result = curl_exec($curl); |
||
165 | $ok = curl_errno($curl) === 0 && curl_getinfo($curl, CURLINFO_HTTP_CODE) === 200; |
||
166 | |||
167 | } elseif ($user === NULL && $pass === NULL) { |
||
168 | $result = file_get_contents($url); |
||
169 | $ok = is_string($result); |
||
170 | |||
171 | } else { |
||
172 | throw new FeedException('PHP extension CURL is not loaded.'); |
||
173 | } |
||
174 | |||
175 | if (!$ok) { |
||
176 | if (isset($cacheFile)) { |
||
177 | $result = @file_get_contents($cacheFile); |
||
178 | if (is_string($result)) { |
||
179 | return $result; |
||
180 | } |
||
181 | } |
||
182 | throw new FeedException('Cannot load channel.'); |
||
183 | } |
||
184 | |||
185 | if (isset($cacheFile)) { |
||
186 | file_put_contents($cacheFile, $result); |
||
187 | } |
||
188 | |||
189 | return $result; |
||
190 | } |
||
191 | |||
208 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.