LocalFileSystem   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 19
lcom 0
cbo 1
dl 0
loc 90
ccs 44
cts 44
cp 1
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A dirExistsRaw() 0 4 2
A linkExistsRaw() 0 4 2
A fileExistsRaw() 0 4 2
A getFileCreationTimestampRaw() 0 4 1
A readFileRaw() 0 4 1
A writeFileRaw() 0 4 1
A copyFileRaw() 0 4 1
A deleteFileRaw() 0 4 1
A createLinkRaw() 0 4 1
A getLinkTargetRaw() 0 4 1
A createDirRaw() 0 6 1
A deleteDirRaw() 0 15 3
A readDirRaw() 0 11 2
1
<?php
2
3
namespace Hgraca\FileSystem;
4
5
use DirectoryIterator;
6
use RecursiveDirectoryIterator;
7
use RecursiveIteratorIterator;
8
9
class LocalFileSystem extends FileSystemAbstract
10
{
11 70
    protected function dirExistsRaw(string $path): bool
12
    {
13 70
        return file_exists($path) && is_dir($path);
14
    }
15
16 35
    protected function linkExistsRaw(string $path): bool
17
    {
18 35
        return file_exists($path) && is_link($path);
19
    }
20
21 38
    protected function fileExistsRaw(string $path): bool
22
    {
23 38
        return file_exists($path) && is_file($path);
24
    }
25
26 1
    protected function getFileCreationTimestampRaw(string $path): int
27
    {
28 1
        return filectime($path);
29
    }
30
31 8
    protected function readFileRaw(string $path): string
32
    {
33 8
        return file_get_contents($path);
34
    }
35
36 4
    protected function writeFileRaw(string $path, string $content)
37
    {
38 4
        file_put_contents($path, $content, LOCK_EX);
39 4
    }
40
41 4
    protected function copyFileRaw(string $sourcePath, string $destinationPath)
42
    {
43 4
        copy($sourcePath, $destinationPath);
44 4
    }
45
46 2
    protected function deleteFileRaw(string $path)
47
    {
48 2
        unlink($path);
49 2
    }
50
51 3
    protected function createLinkRaw(string $path, string $targetPath)
52
    {
53 3
        symlink($targetPath, $path);
54 3
    }
55
56 7
    protected function getLinkTargetRaw(string $path): string
57
    {
58 7
        return readlink($path);
59
    }
60
61 5
    public function createDirRaw(string $path)
62
    {
63 5
        $oldUmask = umask(0);
64 5
        mkdir($path, 0777, true);
65 5
        umask($oldUmask);
66 5
    }
67
68 70
    public function deleteDirRaw(string $path)
69
    {
70 70
        $it = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
71 70
        $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
72
73 70
        foreach ($files as $file) {
74 70
            if ($file->isDir()) {
75 70
                rmdir($file->getRealPath());
76
            } else {
77 70
                unlink($file->getPathname());
78
            }
79
        }
80
81 70
        rmdir($path);
82 70
    }
83
84
    /**
85
     * @return string[] The array with the file and dir names
86
     */
87 5
    public function readDirRaw(string $path): array
88
    {
89 5
        $iterator = new DirectoryIterator($path);
90
91 5
        $contents = [];
92 5
        foreach ($iterator as $fileInfo) {
93 5
            $contents[] = $fileInfo->getFilename();
94
        }
95
96 5
        return $contents;
97
    }
98
}
99