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

FileWriter::writeToFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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