FilesManager::removeDirRecursive()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 2
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
use SplFileInfo;
9
10
class FilesManager
11
{
12
13
    public function removeDirRecursive(string $dirPath): void
14
    {
15
        /** @var SplFileInfo[] $files */
16
        $files = new RecursiveIteratorIterator(
17
            new RecursiveDirectoryIterator($dirPath, FilesystemIterator::SKIP_DOTS),
18
            RecursiveIteratorIterator::CHILD_FIRST
19
        );
20
        foreach ($files as $file) {
21
            if ($file->isDir()) {
22
                $this->removeDirRecursive($file->getRealPath());
23
            } else {
24
                unlink($file->getRealPath());
25
            }
26
        }
27
        rmdir($dirPath);
28
    }
29
30
}