Conditions | 4 |
Paths | 4 |
Total Lines | 25 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | public function removeDir(string $target): array |
||
22 | { |
||
23 | if (!is_dir($target)) { |
||
24 | return []; |
||
25 | } |
||
26 | |||
27 | $files = new RecursiveIteratorIterator( |
||
28 | new RecursiveDirectoryIterator($target, FilesystemIterator::SKIP_DOTS), |
||
29 | RecursiveIteratorIterator::CHILD_FIRST |
||
30 | ); |
||
31 | |||
32 | $filenames = []; |
||
33 | /** @var SplFileInfo $file */ |
||
34 | foreach ($files as $file) { |
||
35 | if (is_dir($file->getPathname())) { |
||
36 | rmdir($file->getPathname()); |
||
37 | } else { |
||
38 | unlink($file->getPathname()); |
||
39 | $filenames[] = $file->getPathname(); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | rmdir($target); |
||
44 | |||
45 | return $filenames; |
||
46 | } |
||
48 |