Passed
Push — add-with-all-to-modules-list ( 82b81d...0edb38 )
by Chema
03:40
created

ConsoleFactory::createAppModuleCreator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
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\ClassResolver\Config\ConfigResolver;
19
use Gacela\Framework\ClassResolver\DependencyProvider\DependencyProviderResolver;
20
use Gacela\Framework\ClassResolver\Factory\FactoryResolver;
21
use Gacela\Framework\Gacela;
22
use RecursiveDirectoryIterator;
23
use RecursiveIteratorIterator;
24
use Symfony\Component\Console\Command\Command;
25
26
/**
27
 * @method ConsoleConfig getConfig()
28
 */
29
final class ConsoleFactory extends AbstractFactory
30
{
31
    /**
32
     * @return list<Command>
33
     *
34
     * @psalm-suppress MixedReturnTypeCoercion
35
     */
36 11
    public function getConsoleCommands(): array
37
    {
38 11
        return (array)$this->getProvidedDependency(ConsoleDependencyProvider::COMMANDS);
39
    }
40
41 12
    public function createCommandArgumentsParser(): CommandArgumentsParserInterface
42
    {
43 12
        return new CommandArgumentsParser(
44 12
            $this->getConfig()->getComposerJsonContentAsArray(),
45 12
        );
46
    }
47
48 9
    public function createFilenameSanitizer(): FilenameSanitizerInterface
49
    {
50 9
        return new FilenameSanitizer();
51
    }
52
53 10
    public function createFileContentGenerator(): FileContentGeneratorInterface
54
    {
55 10
        return new FileContentGenerator(
56 10
            $this->createFileContentIo(),
57 10
            $this->getTemplateByFilenameMap(),
58 10
        );
59
    }
60
61 7
    public function createAllAppModulesFinder(): AllAppModulesFinder
62
    {
63 7
        return new AllAppModulesFinder(
64 7
            $this->createRecursiveIterator(),
65 7
            $this->createAppModuleCreator(),
66 7
        );
67
    }
68
69 9
    public function createAppModuleCreator(): AppModuleCreator
70
    {
71 9
        return new AppModuleCreator(
72 9
            new FactoryResolver(),
73 9
            new ConfigResolver(),
74 9
            new DependencyProviderResolver(),
75 9
        );
76
    }
77
78 7
    private function createRecursiveIterator(): RecursiveIteratorIterator
79
    {
80 7
        return new RecursiveIteratorIterator(
81 7
            new RecursiveDirectoryIterator(Gacela::rootDir(), RecursiveDirectoryIterator::SKIP_DOTS),
82 7
            RecursiveIteratorIterator::LEAVES_ONLY,
83 7
        );
84
    }
85
86 10
    private function createFileContentIo(): FileContentIoInterface
87
    {
88 10
        return new FileContentIo();
89
    }
90
91
    /**
92
     * @psalm-suppress MixedReturnTypeCoercion
93
     *
94
     * @return array<string,string>
95
     */
96 10
    private function getTemplateByFilenameMap(): array
97
    {
98 10
        return (array)$this->getProvidedDependency(ConsoleDependencyProvider::TEMPLATE_BY_FILENAME_MAP);
99
    }
100
}
101