Completed
Push — master ( 81ce9d...1672d9 )
by Oleg
03:54
created

FileWriter::__construct()   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
namespace SlayerBirden\DFCodeGeneration\Writer;
5
6
class FileWriter implements WriteInterface
7
{
8
    /**
9
     * @var string
10
     */
11
    private $baseDir;
12
    /**
13
     * @var FileNameProviderInterface
14
     */
15
    private $fileNameProvider;
16
17 1
    public function __construct(string $baseDir, FileNameProviderInterface $fileNameProvider)
18
    {
19 1
        $this->baseDir = $baseDir;
20 1
        $this->fileNameProvider = $fileNameProvider;
21 1
    }
22
23 1
    public function write(string $content): void
24
    {
25 1
        $fullName = rtrim($this->baseDir, '/') . '/' . $this->fileNameProvider->getFileName($content);
26
27 1
        $dir = dirname($fullName);
28
29 1
        if (!file_exists($dir)) {
30 1
            mkdir($dir, 0755, true);
31
        }
32 1
        file_put_contents($fullName, $content);
33 1
    }
34
}
35