Passed
Push — master ( 481714...398263 )
by Chema
01:30 queued 13s
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\Cache\CacheClearer;
8
use Gacela\Console\Domain\Cache\DirectoryIoInterface;
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\DirectoryIo;
17
use Gacela\Console\Infrastructure\FileContentIo;
18
use Gacela\Framework\AbstractFactory;
19
use Symfony\Component\Console\Command\Command;
20
21
/**
22
 * @method ConsoleConfig getConfig()
23
 */
24
final class ConsoleFactory extends AbstractFactory
25
{
26
    /**
27
     * @return list<Command>
28
     *
29
     * @psalm-suppress MixedReturnTypeCoercion
30
     */
31
    public function getConsoleCommands(): array
32
    {
33
        return (array)$this->getProvidedDependency(ConsoleDependencyProvider::COMMANDS);
34
    }
35
36
    public function createCommandArgumentsParser(): CommandArgumentsParserInterface
37
    {
38
        return new CommandArgumentsParser(
39
            $this->getConfig()->getComposerJsonContentAsArray()
40
        );
41
    }
42
43
    public function createFilenameSanitizer(): FilenameSanitizerInterface
44
    {
45
        return new FilenameSanitizer();
46
    }
47
48
    public function createFileContentGenerator(): FileContentGeneratorInterface
49
    {
50
        return new FileContentGenerator(
51
            $this->createFileContentIo(),
52
            $this->getTemplateByFilenameMap()
53
        );
54
    }
55
56
    public function createCacheClearer(): CacheClearer
57
    {
58
        return new CacheClearer(
59
            $this->getConfig()->getCacheDir(),
60
            $this->createDirectoryIo()
61
        );
62
    }
63
64
    private function createFileContentIo(): FileContentIoInterface
65
    {
66
        return new FileContentIo();
67
    }
68
69
    /**
70
     * @return array<string,string>
71
     */
72
    private function getTemplateByFilenameMap(): array
73
    {
74
        /** @var array<string,string> $map */
75
        $map = $this->getProvidedDependency(ConsoleDependencyProvider::TEMPLATE_BY_FILENAME_MAP);
76
77
        return $map;
78
    }
79
80
    private function createDirectoryIo(): DirectoryIoInterface
81
    {
82
        return new DirectoryIo();
83
    }
84
}
85