FileSystemHelper::exec()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpEpub\Util;
6
7
class FileSystemHelper
8
{
9 1
    public function fileExists(string $path): bool
10
    {
11 1
        return file_exists($path);
12
    }
13
14
    /**
15
     * @param array<int, mixed> $output
16
     */
17 1
    public function exec(string $command, array &$output, int &$returnVar): void
18
    {
19 1
        exec($command, $output, $returnVar);
20
    }
21
22 1
    public function fileSize(string $path): int|false
23
    {
24 1
        return filesize($path);
25
    }
26
27
    /**
28
     * Recursively deletes a directory and its contents.
29
     */
30 57
    public function deleteDirectory(string $dir): bool
31
    {
32 57
        if (! is_dir($dir)) {
33
            return true;
34
        }
35
36 57
        $files = scandir($dir);
37
38 57
        if ($files === false) {
39
            return false;
40
        }
41
42 57
        foreach ($files as $file) {
43 57
            if ($file === '.' || $file === '..') {
44 57
                continue;
45
            }
46 37
            $filePath = $dir . DIRECTORY_SEPARATOR . $file;
47 37
            is_dir($filePath) ? $this->deleteDirectory($filePath) : unlink($filePath);
48
        }
49
50 57
        return rmdir($dir);
51
    }
52
}
53