Passed
Push — feature/change-cache-to-profil... ( 160b60...1b58b5 )
by Chema
03:24
created

ConsoleFactory::createCacheClearer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
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
    public function createCommandArgumentsParser(): CommandArgumentsParserInterface
34
    {
35
        return new CommandArgumentsParser(
36
            $this->getConfig()->getComposerJsonContentAsArray()
37
        );
38
    }
39
40
    public function createFilenameSanitizer(): FilenameSanitizerInterface
41
    {
42
        return new FilenameSanitizer();
43
    }
44
45
    public function createFileContentGenerator(): FileContentGeneratorInterface
46
    {
47
        return new FileContentGenerator(
48
            $this->createFileContentIo(),
49
            $this->getTemplateByFilenameMap()
50
        );
51
    }
52
53
    private function createFileContentIo(): FileContentIoInterface
54
    {
55
        return new FileContentIo();
56
    }
57
58
    /**
59
     * @psalm-suppress MixedReturnTypeCoercion
60
     *
61
     * @return array<string,string>
62
     */
63
    private function getTemplateByFilenameMap(): array
64
    {
65
        return (array)$this->getProvidedDependency(ConsoleDependencyProvider::TEMPLATE_BY_FILENAME_MAP);
66
    }
67
}
68