Completed
Push — master ( 889e09...1ab9ef )
by Denis
01:15
created

MakeViewCommand::path()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Ngtfkx\Laradeck\Commands;
4
5
use Illuminate\Console\Command;
6
7
class MakeViewCommand extends Command
8
{
9
    protected $signature = 'laradeck:view {name} {--force}';
10
11
    protected $description = 'Make view';
12
13
    public function __construct()
14
    {
15
        parent::__construct();
16
    }
17
18
    public function handle()
19
    {
20
        $view = $this->argument('name');
21
22
        $force = $this->option('force');
23
24
        $path = $this->path($view);
25
26
        $content = $this->content();
27
28
        $this->create($path, $content, $force);
29
    }
30
31
    protected function path(string $view): string
32
    {
33
        $path = resource_path('views' . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $view) . '.blade.php');
34
35
        $directory = dirname($path);
36
37
        if (!is_dir($directory)) {
38
            \File::makeDirectory($directory, 0755, true);
39
        }
40
41
        return $path;
42
    }
43
44
    protected function content(): string
45
    {
46
        $content = '';
47
48
        return $content;
49
    }
50
51
    protected function create(string $path, string $content, bool $force)
52
    {
53
        if ($force || !file_exists($path)) {
54
            \File::put($path, $content);
55
            $this->info('View created successfully.');
56
        } else {
57
            $this->error('View already exists!');
58
        }
59
    }
60
}
61