CreateViewCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 9.4285
1
<?php
2
namespace Bantenprov\YankesInfoKamar\Commands;
3
4
use Illuminate\Console\Command;
5
use Illuminate\Support\Facades\Config;
6
use Symfony\Component\Console\Input\InputOption;
7
use Symfony\Component\Console\Input\InputArgument;
8
use File;
9
10
class CreateViewCommand extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'bantenprov:create-view {extends=layout.app : extend to }';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Create view interface';
25
26
    /**
27
     * Create a new command instance.
28
     *
29
     * @return void
30
     */
31
32
    protected $stubsKelas = [
33
        'kelas' => [
34
            'index.blade.stub',
35
            'show.blade.stub',
36
            'create.blade.stub',
37
            'edit.blade.stub'
38
        ]
39
    ];
40
41
    protected $stubsRuang = [
42
        'ruang' => [
43
          'index.blade.stub',
44
          'show.blade.stub',
45
          'create.blade.stub',
46
          'edit.blade.stub'
47
        ]
48
    ];
49
50
51
    protected $stubsBed = [
52
        'bed' => [
53
          'index.blade.stub',
54
          'show.blade.stub',
55
          'create.blade.stub',
56
          'edit.blade.stub'
57
        ]
58
    ];
59
60
61
62
    public function __construct()
63
    {
64
        parent::__construct();
65
66
    }
67
68
    protected function strReplaceKelas($fileName)
69
    {
70
        $extend = $this->argument('extends');
71
        return str_replace('[%extend_to%]',$extend,File::get(__DIR__.'/../stubs/Views/kelas/'.$fileName));
72
    }
73
74
    protected function strReplaceRuang($fileName)
75
    {
76
        $extend = $this->argument('extends');
77
        return str_replace('[%extend_to%]',$extend,File::get(__DIR__.'/../stubs/Views/ruang/'.$fileName));
78
    }
79
80
    protected function strReplaceBed($fileName)
81
    {
82
        $extend = $this->argument('extends');
83
        return str_replace('[%extend_to%]',$extend,File::get(__DIR__.'/../stubs/Views/bed/'.$fileName));
84
    }
85
86
    protected function kelasViewCreate()
87
    {
88
89
        foreach($this->stubsKelas['kelas'] as $stub)
90
        {
91
            File::put(base_path('resources/views/kelas/').str_replace('stub','php',$stub),$this->strReplaceKelas($stub));
92
        }
93
94
    }
95
96
    protected function ruangViewCreate()
97
    {
98
99
        foreach($this->stubsRuang['ruang'] as $stub)
100
        {
101
            File::put(base_path('resources/views/ruang/').str_replace('stub','php',$stub),$this->strReplaceRuang($stub));
102
        }
103
104
    }
105
106
    protected function bedViewCreate()
107
    {
108
109
        foreach($this->stubsBed['bed'] as $stub)
110
        {
111
            File::put(base_path('resources/views/bed/').str_replace('stub','php',$stub),$this->strReplaceBed($stub));
112
        }
113
114
    }
115
116
117
118
    public function handle()
119
    {
120
121
        File::makeDirectory(base_path('resources/views/kelas'));
122
        File::makeDirectory(base_path('resources/views/ruang'));
123
        File::makeDirectory(base_path('resources/views/bed'));
124
125
        $this->kelasViewCreate();
126
        $this->ruangViewCreate();
127
        $this->bedViewCreate();
128
        $this->info('Create view success');
129
    }
130
}
131