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

FileSystemHandler::exists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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