Passed
Push — feature/add-gacela-cli ( 2018fc )
by Chema
05:13 queued 15s
created

CodeGeneratorFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 10
c 3
b 0
f 0
dl 0
loc 35
ccs 0
cts 14
cp 0
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createCommandArgumentsParser() 0 4 1
A getTemplateByFilenameMap() 0 5 1
A createFileContentGenerator() 0 5 1
A createFileContentIo() 0 3 1
A createFilenameSanitizer() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\CodeGenerator;
6
7
use Gacela\CodeGenerator\Domain\CommandArguments\CommandArgumentsParser;
8
use Gacela\CodeGenerator\Domain\CommandArguments\CommandArgumentsParserInterface;
9
use Gacela\CodeGenerator\Domain\FileContent\FileContentGenerator;
10
use Gacela\CodeGenerator\Domain\FileContent\FileContentGeneratorInterface;
11
use Gacela\CodeGenerator\Domain\FileContent\FileContentIoInterface;
12
use Gacela\CodeGenerator\Domain\FilenameSanitizer\FilenameSanitizer;
13
use Gacela\CodeGenerator\Domain\FilenameSanitizer\FilenameSanitizerInterface;
14
use Gacela\CodeGenerator\Infrastructure\FileContentIo;
15
use Gacela\Framework\AbstractFactory;
16
17
/**
18
 * @method CodeGeneratorConfig getConfig()
19
 */
20
final class CodeGeneratorFactory extends AbstractFactory
21
{
22
    public function createCommandArgumentsParser(): CommandArgumentsParserInterface
23
    {
24
        return new CommandArgumentsParser(
25
            $this->getConfig()->getComposerJsonContentAsArray()
26
        );
27
    }
28
29
    public function createFilenameSanitizer(): FilenameSanitizerInterface
30
    {
31
        return new FilenameSanitizer();
32
    }
33
34
    public function createFileContentGenerator(): FileContentGeneratorInterface
35
    {
36
        return new FileContentGenerator(
37
            $this->createFileContentIo(),
38
            $this->getTemplateByFilenameMap()
39
        );
40
    }
41
42
    private function createFileContentIo(): FileContentIoInterface
43
    {
44
        return new FileContentIo();
45
    }
46
47
    /**
48
     * @return array<string,string>
49
     */
50
    private function getTemplateByFilenameMap(): array
51
    {
52
        /** @var array<string,string> $map */
53
        $map = $this->getProvidedDependency(CodeGeneratorDependencyProvider::TEMPLATE_BY_FILENAME_MAP);
54
        return $map;
55
    }
56
}
57