Completed
Push — master ( 993468...5fd9a9 )
by Markus
12s queued 10s
created

FactoryRegistryGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 42
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTemplateName() 0 3 1
A generate() 0 12 1
A getFile() 0 3 1
1
<?php
2
3
namespace Jellyfish\Transfer\Generator;
4
5
class FactoryRegistryGenerator extends AbstractGenerator implements FactoryRegistryGeneratorInterface
6
{
7
    protected const FILE_NAME = 'factory-registry';
8
    protected const TEMPLATE_NAME = 'factory-registry.twig';
9
10
    /**
11
     * @param \Jellyfish\Transfer\Definition\ClassDefinitionInterface[] $classDefinitionMap
12
     *
13
     * @return \Jellyfish\Transfer\Generator\FactoryRegistryGeneratorInterface
14
     *
15
     * @throws \Twig\Error\LoaderError
16
     * @throws \Twig\Error\RuntimeError
17
     * @throws \Twig\Error\SyntaxError
18
     */
19
    public function generate(array $classDefinitionMap): FactoryRegistryGeneratorInterface
20
    {
21
        $file = $this->getFile();
22
        $fileContent = $this->twig->render($this->getTemplateName(), [
23
            'classDefinitionMap' => $classDefinitionMap
24
        ]);
25
26
        $this->createDirectories($this->targetDirectory);
27
28
        $this->filesystem->writeToFile($this->targetDirectory . $file, $fileContent);
29
30
        return $this;
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    protected function getFile(): string
37
    {
38
        return static::FILE_NAME . static::FILE_EXTENSION;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    protected function getTemplateName(): string
45
    {
46
        return static::TEMPLATE_NAME;
47
    }
48
}
49