Passed
Pull Request — master (#16)
by Daniel
02:13
created

AbstractGenerator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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