Conditions | 15 |
Paths | 154 |
Total Lines | 44 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
24 | public static function get($url, $file = null, $method = null) |
||
25 | { |
||
26 | if (true === $file) { |
||
27 | $file = basename($url); |
||
28 | } |
||
29 | if (null !== $file) { |
||
30 | if (is_dir($file)) { |
||
31 | $file = rtrim($file, '/') . '/' . basename($url); |
||
32 | } |
||
33 | $exists = file_exists($file); |
||
34 | if (!@touch($file)) { |
||
35 | return false; |
||
36 | } |
||
37 | if (!$exists) { |
||
38 | @unlink($file); |
||
|
|||
39 | } |
||
40 | } |
||
41 | |||
42 | if (in_array($method, self::$methods, true)) { |
||
43 | $check = "check_$method"; |
||
44 | $get = "get_$method"; |
||
45 | if (self::$check()) { |
||
46 | $content = self::$get($url); |
||
47 | } else { |
||
48 | return false; |
||
49 | } |
||
50 | } else { |
||
51 | foreach (self::$methods as $m) { |
||
52 | $check = "check_$m"; |
||
53 | $get = "get_$m"; |
||
54 | if (self::$check()) { |
||
55 | $content = self::$get($url); |
||
56 | if (((true !== $method) && ('all' != strtolower($method))) |
||
57 | || (false !== $content)) { |
||
58 | break; |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 | if (!isset($content)) { |
||
63 | return false; |
||
64 | } |
||
65 | } |
||
66 | |||
67 | return (null !== $file) ? @file_put_contents($file, $content) : $content; |
||
68 | } |
||
155 |
If you suppress an error, we recommend checking for the error condition explicitly: