Conditions | 11 |
Paths | 11 |
Total Lines | 39 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
78 | public static function rrmdir(string $source, bool $removeOnlyChildren = false): bool |
||
79 | { |
||
80 | if (empty($source) || file_exists($source) === false) { |
||
81 | return false; |
||
82 | } |
||
83 | |||
84 | if (is_file($source) || is_link($source)) { |
||
85 | clearstatcache(true, $source); |
||
86 | return unlink($source); |
||
87 | } |
||
88 | |||
89 | $files = new RecursiveIteratorIterator( |
||
90 | new RecursiveDirectoryIterator($source, FilesystemIterator::SKIP_DOTS), |
||
91 | RecursiveIteratorIterator::CHILD_FIRST |
||
92 | ); |
||
93 | |||
94 | foreach ($files as $fileInfo) { |
||
95 | /** |
||
96 | * @var SplFileInfo $fileInfo |
||
97 | */ |
||
98 | $realpath = $fileInfo->getRealPath(); |
||
99 | if ($realpath) { |
||
100 | if ($fileInfo->isDir()) { |
||
101 | if (self::rrmdir($fileInfo->getRealPath()) === false) { |
||
102 | return false; |
||
103 | } |
||
104 | } elseif (unlink($realpath) === false) { |
||
105 | return false; |
||
106 | } |
||
107 | } else { |
||
108 | return false; |
||
109 | } |
||
110 | } |
||
111 | |||
112 | if ($removeOnlyChildren === false) { |
||
113 | return rmdir($source); |
||
114 | } |
||
115 | |||
116 | return true; |
||
117 | } |
||
149 |