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

ConsoleFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 10
c 2
b 0
f 0
dl 0
loc 45
rs 10
ccs 13
cts 15
cp 0.8667

6 Methods

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