SetupCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fire() 0 6 1
A generateComponentsFolder() 0 7 1
A generateAssetsFolder() 0 7 1
A generateDirectory() 0 12 2
1
<?php
2
3
namespace Consigliere\Components\Commands;
4
5
use Illuminate\Console\Command as ComponentCommand;
6
7
class SetupCommand extends ComponentCommand
8
{
9
    /**
10
     * The console command name.
11
     *
12
     * @var string
13
     */
14
    protected $name = 'component:setup';
15
16
    /**
17
     * The console command description.
18
     *
19
     * @var string
20
     */
21
    protected $description = 'Setting up components folders for first use.';
22
23
    /**
24
     * Execute the console command.
25
     *
26
     * @return mixed
27
     */
28
    public function fire()
29
    {
30
        $this->generateComponentsFolder();
31
32
        $this->generateAssetsFolder();
33
    }
34
35
    /**
36
     * Generate the components folder.
37
     */
38
    public function generateComponentsFolder()
39
    {
40
        $this->generateDirectory($this->laravel['components']->config('paths.components'),
41
            'Components directory created successfully',
42
            'Components directory already exist'
43
        );
44
    }
45
46
    /**
47
     * Generate the assets folder.
48
     */
49
    public function generateAssetsFolder()
50
    {
51
        $this->generateDirectory($this->laravel['components']->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