Generator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 36
ccs 0
cts 11
cp 0
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compile() 0 3 1
A make() 0 13 2
1
<?php namespace Way\Generators;
2
3
use Illuminate\Contracts\Filesystem\FileExistsException;
4
use Illuminate\Support\Facades\File;
5
use Way\Generators\Compilers\TemplateCompiler;
6
7
class Generator
8
{
9
    /**
10
     * Run the generator
11
     *
12
     * @param  string  $templatePath
13
     * @param  array  $templateData
14
     * @param  string  $filePathToGenerate
15
     * @throws FileExistsException
16
     */
17
    public function make(string $templatePath, array $templateData, string $filePathToGenerate)
18
    {
19
        // We first need to compile the template,
20
        // according to the data that we provide.
21
        $template = $this->compile($templatePath, $templateData, new TemplateCompiler);
22
23
        // Now that we have the compiled template,
24
        // we can actually generate the file.
25
        if (File::exists($filePathToGenerate)) {
26
            throw new FileExistsException();
27
        }
28
29
        File::put($filePathToGenerate, $template);
30
    }
31
32
    /**
33
     * Compile the file
34
     *
35
     * @param  string  $templatePath
36
     * @param  array  $data
37
     * @param  TemplateCompiler  $compiler
38
     * @return mixed
39
     */
40
    public function compile(string $templatePath, array $data, TemplateCompiler $compiler)
41
    {
42
        return $compiler->compile(File::get($templatePath), $data);
43
    }
44
}
45