Passed
Push — feature/add-config-files ( 837ed6...2054b6 )
by Jesús
11:11 queued 06:36
created

CodeGeneratorConfig::getFactoryMakerTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\CodeGenerator;
6
7
use Gacela\Framework\AbstractConfig;
8
use JsonException;
9
use LogicException;
10
11
final class CodeGeneratorConfig extends AbstractConfig
12
{
13
    public function getFacadeMakerTemplate(): string
14
    {
15
        return $this->getCommandTemplateContent('facade-maker.txt');
16
    }
17
18
    public function getFactoryMakerTemplate(): string
19
    {
20
        return $this->getCommandTemplateContent('factory-maker.txt');
21
    }
22
23
    public function getConfigMakerTemplate(): string
24
    {
25
        return $this->getCommandTemplateContent('config-maker.txt');
26
    }
27
28
    public function getDependencyProviderMakerTemplate(): string
29
    {
30
        return $this->getCommandTemplateContent('dependency-provider-maker.txt');
31
    }
32
33
    /**
34
     * @throws JsonException
35
     *
36
     * @return array{autoload: array{psr-4: array<string,string>}}
37
     */
38
    public function getComposerJsonContentAsArray(): array
39
    {
40
        $filename = $this->getAppRootDir() . '/composer.json';
41
        if (!file_exists($filename)) {
42
            throw new LogicException('composer.json file not found but it is required');
43
        }
44
45
        /** @var array{autoload: array{psr-4: array<string,string>}} $json */
46
        $json = (array)json_decode((string)file_get_contents($filename), true, 512, JSON_THROW_ON_ERROR);
47
48
        return $json;
49
    }
50
51
    private function getCommandTemplateContent(string $filename): string
52
    {
53
        return (string)file_get_contents(__DIR__ . '/Infrastructure/Template/Command/' . $filename);
54
    }
55
}
56