Completed
Push — dev ( 7a8390...88ee09 )
by Marc
02:14
created

ModalConfigGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 52
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 18 2
A renderTemplate() 0 7 2
A getStub() 0 3 1
1
<?php
2
3
namespace Mascame\Artificer\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Foundation\Inspiring;
7
8
class ModalConfigGenerator extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'artificer:model {name}';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Display an inspiring quote';
23
24
    /**
25
     * Execute the console command.
26
     *
27
     * @return mixed
28
     */
29
    public function handle()
30
    {
31
        $name = $this->argument('name');
32
        $fileName = $name . '.php';
33
        $filePath = config_path('admin/models/') . $fileName;
34
35
        if (\File::exists($filePath)) {
36
            $this->error('File ' . $filePath . ' already exists.');
37
            return;
38
        }
39
40
        $template = \File::get($this->getStub());
41
42
        $render = $this->renderTemplate($template, compact('name'));
43
44
        // Todo: use the artificers admin path (support path change)
45
        \File::put($filePath, $render);
46
    }
47
48
    protected function renderTemplate($template, $data) {
49
        foreach ($data as $key => $value) {
50
            $template = str_replace('{{ '. $key .' }}', $value, $template);
51
        }
52
53
        return $template;
54
    }
55
56
    protected function getStub() {
57
        return __DIR__ . '/../../stubs/ModelConfig.php';
58
    }
59
}
60