FileWriter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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