AbstractGenerator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 1
b 0
f 0
dl 0
loc 54
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A createDirectories() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jellyfish\Transfer\Generator;
6
7
use Jellyfish\Filesystem\FilesystemInterface;
8
use Twig\Environment;
9
10
abstract class AbstractGenerator
11
{
12
    protected const FILE_EXTENSION = '.php';
13
14
    /**
15
     * @var \Jellyfish\Filesystem\FilesystemInterface
16
     */
17
    protected $filesystem;
18
19
    /**
20
     * @var \Twig\Environment
21
     */
22
    protected $twig;
23
24
    /**
25
     * @var string
26
     */
27
    protected $targetDirectory;
28
29
    /**
30
     * @param \Jellyfish\Filesystem\FilesystemInterface $filesystem
31
     * @param \Twig\Environment $twig
32
     * @param string $targetDirectory
33
     */
34
    public function __construct(
35
        FilesystemInterface $filesystem,
36
        Environment $twig,
37
        string $targetDirectory
38
    ) {
39
        $this->twig = $twig;
40
        $this->targetDirectory = $targetDirectory;
41
        $this->filesystem = $filesystem;
42
    }
43
44
    /**
45
     * @param string $path
46
     *
47
     * @return \Jellyfish\Transfer\Generator\AbstractGenerator
48
     */
49
    protected function createDirectories(string $path): AbstractGenerator
50
    {
51
        if ($this->filesystem->exists($path)) {
52
            return $this;
53
        }
54
55
        $this->filesystem->mkdir($path, 0775);
56
57
        return $this;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    abstract protected function getTemplateName(): string;
64
}
65