FactoryRegistryGenerator::getFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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