FileContentIo   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 24
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mkdir() 0 16 4
A filePutContents() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Console\Infrastructure;
6
7
use Gacela\Console\Domain\FileContent\FileContentIoInterface;
8
use Override;
9
use RuntimeException;
10
11
use function sprintf;
12
13
/**
14
 * @codeCoverageIgnore
15
 */
16
final class FileContentIo implements FileContentIoInterface
17
{
18
    #[Override]
19
    public function mkdir(string $directory): void
20
    {
21
        if (is_dir($directory)) {
22
            return;
23
        }
24
25
        if (mkdir($directory)) {
26
            return;
27
        }
28
29
        if (is_dir($directory)) {
30
            return;
31
        }
32
33
        throw new RuntimeException(sprintf('Directory "%s" was not created', $directory));
34
    }
35
36
    #[Override]
37
    public function filePutContents(string $path, string $fileContent): void
38
    {
39
        file_put_contents($path, $fileContent);
40
    }
41
}
42