FileWriter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setDirectory() 0 4 1
A write() 0 14 3
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