Conditions | 7 |
Paths | 6 |
Total Lines | 21 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 7.2269 |
Changes | 0 |
1 | <?php |
||
30 | 57 | public function deleteDirectory(string $dir): bool |
|
31 | { |
||
32 | 57 | if (! is_dir($dir)) { |
|
33 | return true; |
||
34 | } |
||
35 | |||
36 | 57 | $files = scandir($dir); |
|
37 | |||
38 | 57 | if ($files === false) { |
|
39 | return false; |
||
40 | } |
||
41 | |||
42 | 57 | foreach ($files as $file) { |
|
43 | 57 | if ($file === '.' || $file === '..') { |
|
44 | 57 | continue; |
|
45 | } |
||
46 | 37 | $filePath = $dir . DIRECTORY_SEPARATOR . $file; |
|
47 | 37 | is_dir($filePath) ? $this->deleteDirectory($filePath) : unlink($filePath); |
|
48 | } |
||
49 | |||
50 | 57 | return rmdir($dir); |
|
51 | } |
||
53 |