Passed
Push — add-command-list-modules ( fd1ae6 )
by Chema
11:55
created

ConsoleFactory::createRecursiveIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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