Passed
Push — master ( f27ff6...85ae0d )
by Paweł
01:57
created

FilesManager::removeDirRecursive()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 15
rs 9.9666
1
<?php
2
3
namespace pjpawel\LightApi\Component;
4
5
use FilesystemIterator;
6
use RecursiveDirectoryIterator;
7
use RecursiveIteratorIterator;
8
9
class FilesManager
10
{
11
12
    public function removeDirRecursive(string $dirPath): void
13
    {
14
        $files = new RecursiveIteratorIterator(
15
            new RecursiveDirectoryIterator($dirPath, FilesystemIterator::SKIP_DOTS),
16
            RecursiveIteratorIterator::CHILD_FIRST
17
        );
18
19
        foreach ($files as $file) {
20
            if ($file->isDir) {
21
                $this->removeDirRecursive($file->getRealPath());
22
            } else {
23
                unlink($file->getRealPath());
24
            }
25
        }
26
        rmdir($dirPath);
27
    }
28
29
}