Passed
Push — master ( 9aeaca...cc05b4 )
by Mike
03:00
created

FileWriter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 34
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 4
A writeToFile() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\DataProvider\Generator;
6
7
8
use Xervice\DataProvider\Generator\Exception\GenerateDirectoryNotWriteable;
9
10
class FileWriter implements FileWriterInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    private $generatedPath;
16
17
    /**
18
     * FileWriter constructor.
19
     *
20
     * @param string $path
21
     *
22
     * @throws \Xervice\DataProvider\Generator\Exception\GenerateDirectoryNotWriteable
23
     */
24 2
    public function __construct(string $path)
25
    {
26 2
        $this->generatedPath = $path;
27
        if (
28 2
            !is_writable($this->generatedPath)
29 2
            && !mkdir($this->generatedPath, '0777', true)
30 2
            && !is_dir($this->generatedPath)
31
        ) {
32
            throw new GenerateDirectoryNotWriteable($this->generatedPath);
33
        }
34 2
    }
35
36
    /**
37
     * @param $filename
38
     * @param $content
39
     */
40 2
    public function writeToFile($filename, $content): void
41
    {
42 2
        file_put_contents($this->generatedPath . '/' . $filename, '<?php
43 2
declare(strict_types=1);' . PHP_EOL . $content);
44 2
    }
45
46
47
}