FileWriter::setDirectory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Glooby\Debug\Writer;
4
5
use Glooby\Debug\Exception\WriterException;
6
7
/**
8
 * @author Emil Kilhage
9
 */
10
class FileWriter implements WriterInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    private $directory;
16
17
    /**
18
     * @param string $directory
19
     */
20
    public function setDirectory($directory)
21
    {
22
        $this->directory = $directory;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function write($name, $output)
29
    {
30
        $filePath = sprintf('%s/%s', $this->directory, $name);
31
32
        if (file_exists($filePath)) {
33
            throw WriterException::fileExistException($filePath);
34
        }
35
36
        $result = file_put_contents($filePath, $output);
37
38
        if (false === $result) {
39
            throw WriterException::writeFailureException($filePath);
40
        }
41
    }
42
}
43