Passed
Push — feature/custom-caching-dir ( f598fb )
by Chema
04:58
created

DirectoryUtil   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A removeDir() 0 21 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Feature\Util;
6
7
use FilesystemIterator;
8
use RecursiveDirectoryIterator;
9
use RecursiveIteratorIterator;
10
use Symfony\Component\Finder\SplFileInfo;
11
12
final class DirectoryUtil
13
{
14
    public static function removeDir(string $target): void
15
    {
16
        if (!is_dir($target)) {
17
            return;
18
        }
19
20
        $files = new RecursiveIteratorIterator(
21
            new RecursiveDirectoryIterator($target, FilesystemIterator::SKIP_DOTS),
22
            RecursiveIteratorIterator::CHILD_FIRST
23
        );
24
25
        /** @var SplFileInfo $file */
26
        foreach ($files as $file) {
27
            if (is_dir($file->getPathname())) {
28
                rmdir($file->getPathname());
29
            } else {
30
                unlink($file->getPathname());
31
            }
32
        }
33
34
        rmdir($target);
35
    }
36
}
37