SetupCommand::generateAssetsFolder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Rawilk\LaravelModules\Commands\Other;
4
5
use Illuminate\Console\Command;
6
7
class SetupCommand extends Command
8
{
9
    /** @var string */
10
    protected $signature = 'module:setup';
11
12
    /** @var string */
13
    protected $description = 'Setup module folders for first use.';
14
15
    public function handle(): void
16
    {
17
        $this->generateModulesFolder();
18
19
        $this->generateAssetsFolder();
20
    }
21
22
    private function generateAssetsFolder(): void
23
    {
24
        $this->generateDirectory(
25
            $this->laravel['modules']->config('paths.assets'),
26
            'Assets directory created successfully!',
27
            'Assets directory already exists!'
28
        );
29
    }
30
31
    private function generateDirectory(string $dir, string $success, string $error): void
32
    {
33
        if (! $this->laravel['files']->isDirectory($dir)) {
34
            $this->laravel['files']->makeDirectory($dir, 0755, true, true);
35
36
            $this->info($success);
37
38
            return;
39
        }
40
41
        $this->error($error);
42
    }
43
44
    private function generateModulesFolder(): void
45
    {
46
        $this->generateDirectory(
47
            $this->laravel['modules']->config('paths.modules'),
48
            'Modules directory created successfully!',
49
            'Modules directory already exists!'
50
        );
51
    }
52
}
53