Passed
Push — feature/refactor-code-generato... ( fb1bf5 )
by Chema
04:20
created

ConsoleConfig   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 10
c 1
b 0
f 0
dl 0
loc 42
rs 10
ccs 14
cts 15
cp 0.9333

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getFactoryMakerTemplate() 0 3 1
A getCommandTemplateContent() 0 3 1
A getDependencyProviderMakerTemplate() 0 3 1
A getComposerJsonContentAsArray() 0 8 2
A getConfigMakerTemplate() 0 3 1
A getFacadeMakerTemplate() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Console;
6
7
use Gacela\Framework\AbstractConfig;
8
use JsonException;
9
use LogicException;
10
11
final class ConsoleConfig extends AbstractConfig
12
{
13 1
    public function getFacadeMakerTemplate(): string
14
    {
15 1
        return $this->getCommandTemplateContent('facade-maker.txt');
16
    }
17
18 1
    public function getFactoryMakerTemplate(): string
19
    {
20 1
        return $this->getCommandTemplateContent('factory-maker.txt');
21
    }
22
23 1
    public function getConfigMakerTemplate(): string
24
    {
25 1
        return $this->getCommandTemplateContent('config-maker.txt');
26
    }
27
28 1
    public function getDependencyProviderMakerTemplate(): string
29
    {
30 1
        return $this->getCommandTemplateContent('dependency-provider-maker.txt');
31
    }
32
33
    /**
34
     * @psalm-suppress MixedReturnTypeCoercion
35
     *
36
     * @throws JsonException
37
     *
38
     * @return array{autoload: array{psr-4: array<string,string>}}
39
     */
40 10
    public function getComposerJsonContentAsArray(): array
41
    {
42 10
        $filename = $this->getAppRootDir() . '/composer.json';
43 10
        if (!file_exists($filename)) {
44
            throw new LogicException("composer.json file not found but it is required. Not found in '{$filename}'");
45
        }
46
47 10
        return (array)json_decode((string)file_get_contents($filename), true, 512, JSON_THROW_ON_ERROR);
48
    }
49
50 1
    private function getCommandTemplateContent(string $filename): string
51
    {
52 1
        return (string)file_get_contents(__DIR__ . '/Infrastructure/Template/Command/' . $filename);
53
    }
54
}
55