Generator::generate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0185
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Database\Business\Model\Config;
6
7
8
use Xervice\Database\Business\Exception\DatabaseConfigException;
9
use Xervice\Database\Business\Model\Config\Converter\ConverterInterface;
10
11
class Generator implements GeneratorInterface
12
{
13
    /**
14
     * @var array
15
     */
16
    private $config;
17
18
    /**
19
     * @var string
20
     */
21
    private $confDir;
22
23
    /**
24
     * @var ConverterInterface
25
     */
26
    private $converter;
27
28
    /**
29
     * Generator constructor.
30
     *
31
     * @param array $config
32
     * @param string $confDir
33
     * @param ConverterInterface $converter
34
     */
35 1
    public function __construct(array $config, string $confDir, ConverterInterface $converter)
36
    {
37 1
        $this->config = $config;
38 1
        $this->confDir = $confDir;
39 1
        $this->converter = $converter;
40 1
    }
41
42
    /**
43
     * @throws \Xervice\Database\Business\Exception\DatabaseConfigException
44
     */
45 1
    public function generate(): void
46
    {
47 1
        if (!is_dir($this->confDir)) {
48
            throw new DatabaseConfigException('Config path not exist: ' . $this->confDir);
49
        }
50 1
        file_put_contents(
51 1
            $this->confDir . '/propel.json',
52 1
            $this->converter->convert($this->config)
53
        );
54 1
    }
55
}
56