BaseGenerator::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 4
nop 2
crap 3
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
}