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

FactoryRegistryGenerator::getFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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