Passed
Push — master ( 481714...398263 )
by Chema
01:30 queued 13s
created

ConsoleFactory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 59
ccs 0
cts 22
cp 0
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A createCommandArgumentsParser() 0 4 1
A getTemplateByFilenameMap() 0 6 1
A getConsoleCommands() 0 3 1
A createFileContentGenerator() 0 5 1
A createDirectoryIo() 0 3 1
A createCacheClearer() 0 5 1
A createFilenameSanitizer() 0 3 1
A createFileContentIo() 0 3 1
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