Conditions | 10 |
Paths | 9 |
Total Lines | 55 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
86 | public static function compareDirectories($dir1, $dir2, $recursive = false, $ignores = []) |
||
87 | { |
||
88 | // Open the first folder. Return if fails to open. |
||
89 | |||
90 | if (! is_resource($dirHandler = @opendir($dir1))) { |
||
91 | return; |
||
92 | } |
||
93 | |||
94 | // Check if the second folder exists. |
||
95 | |||
96 | if (! is_dir($dir2)) { |
||
97 | return; |
||
98 | } |
||
99 | |||
100 | // Now, compare the folders. |
||
101 | |||
102 | while (($file = readdir($dirHandler)) !== false) { |
||
103 | |||
104 | // Check if this file should be ignored. |
||
105 | |||
106 | $filesToIgnore = array_merge($ignores, ['.', '..']); |
||
107 | |||
108 | if (self::isIgnoredFile($file, $filesToIgnore)) { |
||
109 | continue; |
||
110 | } |
||
111 | |||
112 | // Get paths of the resources to compare. |
||
113 | |||
114 | $source = $dir1.DIRECTORY_SEPARATOR.$file; |
||
115 | $target = $dir2.DIRECTORY_SEPARATOR.$file; |
||
116 | |||
117 | // If the resources to compare are files, check that both files are |
||
118 | // equals. |
||
119 | |||
120 | if (is_file($source) && ! self::compareFiles($source, $target)) { |
||
121 | return false; |
||
122 | } |
||
123 | |||
124 | // If the resources to compare are folders, recursively compare the |
||
125 | // folders. |
||
126 | |||
127 | $isDir = is_dir($source) && $recursive; |
||
128 | |||
129 | if ($isDir && ! (bool) self::compareDirectories($source, $target, $recursive, $ignores)) { |
||
130 | return false; |
||
131 | } |
||
132 | } |
||
133 | |||
134 | // Close the opened folder. |
||
135 | |||
136 | closedir($dirHandler); |
||
137 | |||
138 | // At this point all the resources compared are equals. |
||
139 | |||
140 | return true; |
||
141 | } |
||
191 | } |