AbstractGenerator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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