Passed
Push — Generators ( 1df58a...4d090d )
by Roy
04:17 queued 11s
created

CreateModuleCommand::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace LaravelModulize\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use LaravelModulize\Contracts\ModulizerRepositoryInterface;
8
9
class CreateModuleCommand extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'modulize:make:module {module}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Sets up the default folder structure for the module.';
24
25
    /**
26
     * Instance of the repository
27
     *
28
     * @var \LaravelModulize\Contracts\ModulizerRepositoryInterface
29
     */
30
    protected $repository;
31
32
    /**
33
     * Create a new command instance.
34
     *
35
     * @param \LaravelModulize\Contracts\ModulizerRepositoryInterface $repository
36
     * @return void
37
     */
38
    public function __construct(ModulizerRepositoryInterface $repository)
39
    {
40
        parent::__construct();
41
42
        $this->repository = $repository;
43
    }
44
45
    /**
46
     * Execute the console command.
47
     *
48
     * @return mixed
49
     */
50
    public function handle()
51
    {
52
        $module = $this->argument('module');
53
54
        $this->generateDirectives($module);
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type null and string[]; however, parameter $module of LaravelModulize\Console\...d::generateDirectives() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

54
        $this->generateDirectives(/** @scrutinizer ignore-type */ $module);
Loading history...
55
    }
56
57
    protected function generateDirectives(string $module)
58
    {
59
        $folders = config('modulizer.default_folders');
60
        $modulePath = $this->repository->getModulePath($module);
61
62
        foreach ($folders as $folder) {
63
            $this->makeFileTree($modulePath, $folder);
64
        }
65
    }
66
67
    protected function makeFileTree($path, $folders)
68
    {
69
        if(is_array($folders)) {
70
            if (is_string(key($folders))) {
71
                $folderName = key($folders);
72
                $path = "{$path}/{$folderName}";
73
            }
74
            foreach ($folders as $subFolders) {
75
                $this->makeFileTree($path, $subFolders);
76
            }
77
        } else {
78
            $this->repository->createDirectory("{$path}/{$folders}");
79
        }
80
    }
81
}
82