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

FilesManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
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
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
}