Completed
Pull Request — master (#13)
by Victor
01:57
created

FileSystemHandler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 3
cbo 5
dl 0
loc 68
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getPath() 0 4 1
A readable() 0 4 1
A writable() 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
use LazyEight\DiTesto\Interfaces\FileSystem\FileSystemPathInterface;
7
use LazyEight\DiTesto\Interfaces\FileSystem\FileSystemReaderInterface;
8
use LazyEight\DiTesto\Interfaces\FileSystem\FileSystemWriterInterface;
9
10
class FileSystemHandler implements FileSystemHandlerInterface
11
{
12
    /**
13
     * @var FileSystemPathInterface
14
     */
15
    private $path;
16
17
    /**
18
     * @var FileSystemReaderInterface
19
     */
20
    private $fileReader;
21
22
    /**
23
     * @var FileSystemWriterInterface
24
     */
25
    private $fileWriter;
26
27
    /**
28
     * FileSystemHandler constructor.
29
     * @param string $path
30
     */
31 1
    public function __construct(string $path)
32
    {
33 1
        $this->path = new FileSystemPath($path);
34 1
        $this->fileReader = new FileSystemReader($this->path);
35 1
        $this->fileWriter = new FileSystemWriter($this->path);
36 1
    }
37
38
    /**
39
     * @return FileSystemPath
40
     */
41 1
    public function getPath(): FileSystemPathInterface
42
    {
43 1
        return clone $this->path;
44
    }
45
46
    /**
47
     * @inheritDoc
48
     */
49 2
    public function readable(): bool
50
    {
51 2
        return $this->fileReader->isReadable();
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57 2
    public function writable(): bool
58
    {
59 2
        return $this->fileWriter->isWritable();
60
    }
61
62
    /**
63
     * @inheritDoc
64
     */
65 2
    public function read(): string
66
    {
67 2
        return $this->fileReader->read();
68
    }
69
70
    /**
71
     * @inheritDoc
72
     */
73 2
    public function write(string $content)
74
    {
75 2
        $this->fileWriter->write($content);
76 1
    }
77
}
78