FileWriter::write()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 4
nop 2
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 4
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Writer;
5
6
final class FileWriter implements WriteInterface
7
{
8
    const CONFIG_FILE_NAME = 'ConfigProvider.php';
9
10
    /**
11
     * @var string
12
     */
13
    private $baseDir;
14
15 1
    public function __construct(string $baseDir)
16
    {
17 1
        $this->baseDir = $baseDir;
18 1
    }
19
20 1
    public function write(string $content, string $fileName): void
21
    {
22 1
        $fullName = rtrim($this->baseDir, '/') . '/' . $fileName;
23
24 1
        $dir = dirname($fullName);
25
26 1
        if (!file_exists($dir)) {
27 1
            mkdir($dir, 0755, true);
28
        }
29 1
        if (!file_exists($fullName) || basename($fullName) === self::CONFIG_FILE_NAME) {
30 1
            file_put_contents($fullName, $content);
31
        }
32 1
    }
33
}
34