Completed
Push — master ( 49c7da...61b9c9 )
by Victor
13s
created

FileSystemHandler   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 0
dl 0
loc 78
ccs 0
cts 39
cp 0
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A exists() 0 4 1
A isReadable() 0 4 1
A isWritable() 0 8 3
A getPathName() 0 4 1
A getFilename() 0 4 1
A getSize() 0 4 1
A getType() 0 4 1
A read() 0 4 1
A write() 0 4 1
1
<?php
2
3
namespace LazyEight\DiTesto\FileSystem;
4
5
use LazyEight\DiTesto\Interfaces\FileSystem\FileSystemHandlerInterface;
6
7
class FileSystemHandler implements FileSystemHandlerInterface
8
{
9
    /**
10
     * @inheritDoc
11
     */
12
    public function exists(string $path): bool
13
    {
14
        return file_exists($path);
15
    }
16
17
    /**
18
     * @inheritDoc
19
     */
20
    public function isReadable(string $path): bool
21
    {
22
        return is_readable($path);
23
    }
24
25
    /**
26
     * @inheritDoc
27
     */
28
    public function isWritable(string $path): bool
29
    {
30
        if (!$this->exists($path) && is_writable($this->getPathName($path))) {
31
            return true;
32
        }
33
34
        return is_writable($path);
35
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40
    public function getPathName(string $path): string
41
    {
42
        return dirname($path);
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    public function getFilename(string $path): string
49
    {
50
        return basename($path);
51
    }
52
53
    /**
54
     * @inheritDoc
55
     */
56
    public function getSize(string $path): int
57
    {
58
        return filesize($path);
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64
    public function getType(string $path): string
65
    {
66
        return mime_content_type($path);
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function read(string $path): string
73
    {
74
        return file_get_contents($path);
75
    }
76
77
    /**
78
     * @inheritDoc
79
     */
80
    public function write(string $path, string $content)
81
    {
82
        file_put_contents($path, $content);
83
    }
84
}
85