FileWriter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 25
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A write() 0 11 4
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