Conditions | 12 |
Paths | 76 |
Total Lines | 37 |
Code Lines | 26 |
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 |
||
49 | static function url2fullPath($url) { |
||
50 | $url = self::normalize($url); |
||
51 | |||
52 | $uri = isset($_SERVER['SCRIPT_NAME']) |
||
53 | ? $_SERVER['SCRIPT_NAME'] : (isset($_SERVER['PHP_SELF']) |
||
54 | ? $_SERVER['PHP_SELF'] |
||
55 | : false); |
||
56 | |||
57 | $uri = self::normalize($uri); |
||
58 | |||
59 | if (substr($url, 0, 1) !== "/") { |
||
60 | if ($uri === false) return false; |
||
61 | $url = dirname($uri) . "/$url"; |
||
62 | } |
||
63 | |||
64 | if (isset($_SERVER['DOCUMENT_ROOT'])) { |
||
65 | return self::normalize(realpath($_SERVER['DOCUMENT_ROOT']) . "/$url"); |
||
66 | |||
67 | } else { |
||
68 | if ($uri === false) return false; |
||
69 | |||
70 | if (isset($_SERVER['SCRIPT_FILENAME'])) { |
||
71 | $scr_filename = self::normalize($_SERVER['SCRIPT_FILENAME']); |
||
72 | return self::normalize(substr($scr_filename, 0, -strlen($uri)) . "/$url"); |
||
73 | } |
||
74 | |||
75 | $count = count(explode('/', $uri)) - 1; |
||
76 | for ($i = 0, $chdir = ""; $i < $count; $i++) |
||
77 | $chdir .= "../"; |
||
78 | $chdir = self::normalize($chdir); |
||
79 | |||
80 | $dir = getcwd(); |
||
81 | if (($dir === false) || !@chdir($chdir)) |
||
82 | return false; |
||
83 | $rdir = getcwd(); |
||
84 | chdir($dir); |
||
85 | return ($rdir !== false) ? self::normalize($rdir . "/$url") : false; |
||
86 | } |
||
148 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.