Completed
Push — master ( eca1e1...16b172 )
by Nicolas
13:25
created

SetupCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 70
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A generateDirectory() 0 12 2
A handle() 0 6 1
A generateModulesFolder() 0 8 1
A generateAssetsFolder() 0 8 1
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Illuminate\Console\Command;
6
7
class SetupCommand extends Command
8
{
9
    /**
10
     * The console command name.
11
     *
12
     * @var string
13
     */
14
    protected $name = 'module:setup';
15
16
    /**
17
     * The console command description.
18
     *
19
     * @var string
20
     */
21
    protected $description = 'Setting up modules folders for first use.';
22
23
    /**
24
     * Execute the console command.
25
     */
26
    public function handle()
27
    {
28
        $this->generateModulesFolder();
29
30
        $this->generateAssetsFolder();
31
    }
32
33
    /**
34
     * Generate the modules folder.
35
     */
36
    public function generateModulesFolder()
37
    {
38
        $this->generateDirectory(
39
            $this->laravel['modules']->config('paths.modules'),
40
            'Modules directory created successfully',
41
            'Modules directory already exist'
42
        );
43
    }
44
45
    /**
46
     * Generate the assets folder.
47
     */
48
    public function generateAssetsFolder()
49
    {
50
        $this->generateDirectory(
51
            $this->laravel['modules']->config('paths.assets'),
52
            'Assets directory created successfully',
53
            'Assets directory already exist'
54
        );
55
    }
56
57
    /**
58
     * Generate the specified directory by given $dir.
59
     *
60
     * @param $dir
61
     * @param $success
62
     * @param $error
63
     */
64
    protected function generateDirectory($dir, $success, $error)
65
    {
66
        if (!$this->laravel['files']->isDirectory($dir)) {
67
            $this->laravel['files']->makeDirectory($dir);
68
69
            $this->info($success);
70
71
            return;
72
        }
73
74
        $this->error($error);
75
    }
76
}
77