FilesManager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 18
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A removeDirRecursive() 0 15 3
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
}