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

ConsoleFactory::createAppModuleCreator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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