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

FileWriter::writeFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 6
1
<?php
2
3
namespace LazyEight\DiTesto;
4
5
use LazyEight\DiTesto\Exceptions\IOException;
6
use LazyEight\DiTesto\Interfaces\FileInterface;
7
use LazyEight\DiTesto\Interfaces\FileSystem\FileSystemHandlerInterface;
8
use LazyEight\DiTesto\Interfaces\FileWriterInterface;
9
use LazyEight\DiTesto\Interfaces\WritableFileInterface;
10
11
class FileWriter implements FileWriterInterface
12
{
13
    public function writeFile(FileInterface $file, FileSystemHandlerInterface $fileSystemHandler)
14
    {
15
        if (!$fileSystemHandler->isWritable($file->getPath())) {
16
            throw new IOException("Error, can't write to the file. The file not exists or is not writable.");
17
        }
18
19
        $fileSystemHandler->write($file->getPath(), $file->getRawContent());
20
    }
21
}
22