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

AbstractGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A createDirectories() 0 9 2
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