BaseGenerator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 68
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 3
A setData() 0 4 1
A create() 0 8 1
A getTemplatePath() 0 4 1
A getDirectories() 0 4 1
1
<?php namespace Packedge\Workbench\Generators;
2
3
use Illuminate\Filesystem\Filesystem;
4
use Mustache_Engine;
5
6
class BaseGenerator
7
{
8
    /**
9
     * @var Filesystem
10
     */
11
    protected $filesystem;
12
    /**
13
     * @var Mustache_Engine
14
     */
15
    protected $mustache;
16
    /**
17
     * @var array
18
     */
19
    protected $data = [];
20
    /**
21
     * @var string
22
     */
23
    protected $templatePath;
24
    /**
25
     * @var string
26
     */
27
    protected $outputPath;
28
    /**
29
     * @param Filesystem $filesystem
30
     * @param Mustache_Engine $mustache
31
     */
32 36
    public function __construct(Filesystem $filesystem = null, Mustache_Engine $mustache = null)
33
    {
34 36
        $this->filesystem = $filesystem ?: new Filesystem;
35 36
        $this->mustache = $mustache ?: new Mustache_Engine;
36 36
    }
37
38
    /**
39
     * @param array $vars
40
     */
41 6
    public function setData(array $vars)
42
    {
43 6
        $this->data = array_merge($this->data, $vars);
44 6
    }
45
46
    /**
47
     * @param $packagePath
48
     * @throws \Illuminate\Filesystem\FileNotFoundException
49
     */
50 6
    public function create($packagePath)
51
    {
52 6
        $template = $this->filesystem->get($this->getTemplatePath());
53
54 6
        $output = $this->mustache->render($template, $this->data);
55
56 6
        $this->filesystem->put($packagePath . '/' . $this->outputPath, $output);
57 6
    }
58
59 6
    protected function getTemplatePath()
60
    {
61 6
        return realpath(__DIR__ . '/../../templates/') . '/' . $this->templatePath;
62
    }
63
64
    /**
65
     * Provides an array of directories to be made in the package directory.
66
     *
67
     * @return array
68
     */
69 9
    public function getDirectories()
70
    {
71 9
        return [];
72
    }
73
}