ServerFileSystem   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 96.3%

Importance

Changes 0
Metric Value
dl 0
loc 46
c 0
b 0
f 0
wmc 11
lcom 0
cbo 0
rs 10
ccs 26
cts 27
cp 0.963

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getFilesInDirectory() 0 21 5
B deleteFilesInDirectoryRecursively() 0 21 6
1
<?php
2
3
namespace Partnermarketing\FileSystemBundle\ServerFileSystem;
4
5
use DirectoryIterator;
6
7
class ServerFileSystem
8
{
9 4
    public static function getFilesInDirectory($dir)
10
    {
11 4
        $iterator = new DirectoryIterator($dir);
12 4
        $files = [];
13
14 4
        foreach ($iterator as $file) {
15 4
            if ($file->getFilename() === '.' || $file->getFilename() === '..') {
16 4
                continue;
17
            }
18
19 4
            if (is_dir($file->getPathname())) {
20 3
                $files = array_merge($files, self::getFilesInDirectory($file->getPathname()));
21 3
            } else {
22 4
                $files[] = realpath($file->getPathname());
23
            }
24 4
        }
25
26 4
        sort($files);
27
28 4
        return $files;
29
    }
30
31 1
    public static function deleteFilesInDirectoryRecursively($dir)
32
    {
33 1
        if (!is_dir($dir)) {
34
            return;
35
        }
36
37 1
        $iterator = new DirectoryIterator($dir);
38
39 1
        foreach ($iterator as $file) {
40 1
            if ($file->getFilename() === '.' || $file->getFilename() === '..') {
41 1
                continue;
42
            }
43
44 1
            if (is_dir($file->getPathname())) {
45 1
                self::deleteFilesInDirectoryRecursively($file->getPathname());
46 1
                rmdir($file->getPathname());
47 1
            } else {
48 1
                unlink($file->getPathname());
49
            }
50 1
        }
51 1
    }
52
}
53