Passed
Push — master ( 4e0c2f...af0465 )
by Prateek
04:42 queued 02:26
created

View::generate()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 26
rs 9.7333
c 0
b 0
f 0
cc 3
nc 4
nop 0
1
<?php
2
namespace Prateekkarki\Laragen\Generators\Frontend;
3
4
use Prateekkarki\Laragen\Generators\BaseGenerator;
5
use Prateekkarki\Laragen\Generators\GeneratorInterface;
6
7
class View extends BaseGenerator implements GeneratorInterface
8
{
9
    public function generate()
10
    {
11
        $viewsToBeGenerated = ['index', 'show', '_list', '_show', '_empty']; // To be generated dynamically
12
13
        $generatedFiles = [];
14
        foreach ($viewsToBeGenerated as $view) {
15
            $viewTemplate = $this->buildTemplate('Views/' . $view, [
16
                '{{modelNameSingularLowercase}}' => $this->module->getModelNameSingularLowercase(),
17
                '{{modelNamePlural}}'            => $this->module->getModelNamePlural(),
18
                '{{moduleName}}'                 => $this->module->getModuleName()
19
            ]);
20
21
            $fullFilePath = $this->getPath("resources/views/" . $this->module->getModuleName()) . "/{$view}.blade.php";
22
            file_put_contents($fullFilePath, $viewTemplate);
23
            $generatedFiles[] =  $fullFilePath;
24
        }
25
26
        $layoutPath = $this->getPath("resources/views/laragen/layouts/") . "app.blade.php";
27
        if(!file_exists($layoutPath)){
28
29
            $viewTemplate = $this->buildTemplate('Views/layouts/app', []);
30
            file_put_contents($layoutPath, $viewTemplate);
31
            $generatedFiles[] =  $layoutPath;
32
        }
33
34
        return $generatedFiles;
35
    }
36
}
37