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