Passed
Push — improve-list-modules-output ( e63970 )
by Chema
04:12
created

ConsoleFactory   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 66
ccs 29
cts 29
cp 1
rs 10
c 2
b 0
f 0
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A createCommandArgumentsParser() 0 4 1
A getTemplateByFilenameMap() 0 3 1
A getConsoleCommands() 0 3 1
A createFileContentGenerator() 0 5 1
A createRecursiveIterator() 0 5 1
A createAppModuleCreator() 0 3 1
A createAllAppModulesFinder() 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\AllAppModules\AllAppModulesFinder;
8
use Gacela\Console\Domain\AllAppModules\AppModuleCreator;
9
use Gacela\Console\Domain\CommandArguments\CommandArgumentsParser;
10
use Gacela\Console\Domain\CommandArguments\CommandArgumentsParserInterface;
11
use Gacela\Console\Domain\FileContent\FileContentGenerator;
12
use Gacela\Console\Domain\FileContent\FileContentGeneratorInterface;
13
use Gacela\Console\Domain\FileContent\FileContentIoInterface;
14
use Gacela\Console\Domain\FilenameSanitizer\FilenameSanitizer;
15
use Gacela\Console\Domain\FilenameSanitizer\FilenameSanitizerInterface;
16
use Gacela\Console\Infrastructure\FileContentIo;
17
use Gacela\Framework\AbstractFactory;
18
use Gacela\Framework\Gacela;
19
use RecursiveDirectoryIterator;
20
use RecursiveIteratorIterator;
21
use Symfony\Component\Console\Command\Command;
22
23
/**
24
 * @method ConsoleConfig getConfig()
25
 */
26
final class ConsoleFactory extends AbstractFactory
27
{
28
    /**
29
     * @return list<Command>
30
     *
31
     * @psalm-suppress MixedReturnTypeCoercion
32
     */
33 13
    public function getConsoleCommands(): array
34
    {
35 13
        return (array)$this->getProvidedDependency(ConsoleDependencyProvider::COMMANDS);
36
    }
37
38 12
    public function createCommandArgumentsParser(): CommandArgumentsParserInterface
39
    {
40 12
        return new CommandArgumentsParser(
41 12
            $this->getConfig()->getComposerJsonContentAsArray(),
42 12
        );
43
    }
44
45 9
    public function createFilenameSanitizer(): FilenameSanitizerInterface
46
    {
47 9
        return new FilenameSanitizer();
48
    }
49
50 10
    public function createFileContentGenerator(): FileContentGeneratorInterface
51
    {
52 10
        return new FileContentGenerator(
53 10
            $this->createFileContentIo(),
54 10
            $this->getTemplateByFilenameMap(),
55 10
        );
56
    }
57
58 5
    public function createAllAppModulesFinder(): AllAppModulesFinder
59
    {
60 5
        return new AllAppModulesFinder(
61 5
            $this->createRecursiveIterator(),
62 5
            $this->createAppModuleCreator(),
63 5
        );
64
    }
65
66 5
    private function createRecursiveIterator(): RecursiveIteratorIterator
67
    {
68 5
        return new RecursiveIteratorIterator(
69 5
            new RecursiveDirectoryIterator(Gacela::rootDir(), RecursiveDirectoryIterator::SKIP_DOTS),
70 5
            RecursiveIteratorIterator::LEAVES_ONLY,
71 5
        );
72
    }
73
74 10
    private function createFileContentIo(): FileContentIoInterface
75
    {
76 10
        return new FileContentIo();
77
    }
78
79
    /**
80
     * @psalm-suppress MixedReturnTypeCoercion
81
     *
82
     * @return array<string,string>
83
     */
84 10
    private function getTemplateByFilenameMap(): array
85
    {
86 10
        return (array)$this->getProvidedDependency(ConsoleDependencyProvider::TEMPLATE_BY_FILENAME_MAP);
87
    }
88
89 5
    private function createAppModuleCreator(): AppModuleCreator
90
    {
91 5
        return new AppModuleCreator();
92
    }
93
}
94