Conditions | 18 |
Paths | 46 |
Total Lines | 64 |
Lines | 12 |
Ratio | 18.75 % |
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 | #!/usr/bin/env php |
||
87 | function createsyms_rec(&$srcdir, &$dstdir, $path) { |
||
88 | global $silent; |
||
89 | global $verbose; |
||
90 | global $OK; |
||
91 | global $FAILED; |
||
92 | global $COLS; |
||
93 | |||
94 | $dh = @opendir($path); |
||
95 | |||
96 | while ($file = @readdir($dh)) { |
||
97 | if ($file != "." && $file != "..") { |
||
98 | $f = $path . $file; |
||
99 | if (is_file($f)) { |
||
100 | /* do not link backupfiles */ |
||
101 | if (!preg_match('/^.*~$/i', $f)) { |
||
102 | $targetpath = $dstdir . substr($path, strlen($srcdir)); |
||
103 | $target = $targetpath . $file; |
||
104 | |||
105 | if (!file_exists($targetpath)) { |
||
106 | makedir($targetpath); |
||
107 | } |
||
108 | |||
109 | if (@is_link($target)) { |
||
110 | unlink($target); |
||
111 | } |
||
112 | |||
113 | $symError = ""; |
||
114 | if (!is_file($target) ){ |
||
115 | ob_start(); |
||
116 | $symResult = symlink($f, $target); |
||
117 | if (!$symResult) { |
||
118 | $symError = str_replace("\n", "", ob_get_contents()); |
||
119 | } |
||
120 | ob_end_clean(); |
||
121 | |||
122 | if($symResult) { |
||
123 | if($verbose) { |
||
124 | echo str_pad("Creating link: " . basename($target), $COLS) . $OK."\n"; |
||
125 | } |
||
126 | View Code Duplication | } else { |
|
127 | if(!$silent) { |
||
128 | echo str_pad("Creating link: " . substr( $path, strlen($srcdir) ).basename($target), $COLS) . $FAILED; |
||
129 | echo " ($symError)\n"; |
||
130 | } |
||
131 | } |
||
132 | View Code Duplication | } else { |
|
133 | if(!$silent) { |
||
134 | echo str_pad("Creating link: " . substr( $path, strlen($srcdir) ).basename($target), $COLS) . $FAILED; |
||
135 | echo " (File already exists)\n"; |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | } else if (is_dir($f)) { |
||
140 | /* skip CVS directories */ |
||
141 | if ($file != "CVS" && $file != ".svn" && $file != ".git") { |
||
142 | $targetpath = $dstdir.substr("$path$file/", strlen($srcdir)); |
||
143 | makedir($targetpath); |
||
144 | createsyms_rec($srcdir,$dstdir,"$f/"); |
||
145 | } |
||
146 | } |
||
147 | } |
||
148 | } |
||
149 | @closedir($dh); |
||
150 | } |
||
151 | if(!$silent) { |
||
175 |