Passed
Push — master ( 9be91c...ccfb9c )
by Neil
02:21
created

MakeModule::createModule()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 27
Code Lines 11

Duplication

Lines 4
Ratio 14.81 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 11
c 1
b 0
f 0
nc 5
nop 1
dl 4
loc 27
rs 8.439
1
<?php
2
3
namespace neilherbertuk\modules\Traits;
4
5
use Illuminate\Support\Facades\App;
6
7
trait MakeModule
8
{
9
    /**
10
     * @param $module
11
     */
12
    protected function createModule($module)
13
    {
14
        $this->info('Creating a new Module');
0 ignored issues
show
Bug introduced by
It seems like info() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

14
        $this->/** @scrutinizer ignore-call */ info('Creating a new Module');
Loading history...
15
16 View Code Duplication
        if (is_dir(base_path('app/Modules/' . $module))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
            $this->error($module . " already exists. If you really want to create this module, please delete the following folder: " . base_path('app/Modules/' . $module));
0 ignored issues
show
Bug introduced by
It seems like error() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

17
            $this->/** @scrutinizer ignore-call */ error($module . " already exists. If you really want to create this module, please delete the following folder: " . base_path('app/Modules/' . $module));
Loading history...
18
            return;
19
        }
20
21
        // Create all module's folders
22
        $this->info('Creating folder structure');
0 ignored issues
show
Bug introduced by
It seems like info() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

22
        $this->/** @scrutinizer ignore-call */ info('Creating folder structure');
Loading history...
23
        $this->createModuleFolders($module);
24
25
26
        // Create routes file
27
28
        // API Routes File
29
        if ($this->option('apiroute')) {
0 ignored issues
show
Bug introduced by
It seems like option() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

29
        if ($this->/** @scrutinizer ignore-call */ option('apiroute')) {
Loading history...
30
            $this->createApiRoutesFile($module);
0 ignored issues
show
Bug introduced by
It seems like createApiRoutesFile() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

30
            $this->/** @scrutinizer ignore-call */ createApiRoutesFile($module);
Loading history...
31
        }
32
33
        // Web Routes File
34
        if ($this->option('webroute') || !$this->option('apiroute')) {
0 ignored issues
show
Bug introduced by
It seems like option() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

34
        if ($this->/** @scrutinizer ignore-call */ option('webroute') || !$this->option('apiroute')) {
Loading history...
35
            $this->createWebRoutesFile($module);
0 ignored issues
show
Bug introduced by
It seems like createWebRoutesFile() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

35
            $this->/** @scrutinizer ignore-call */ createWebRoutesFile($module);
Loading history...
36
        }
37
38
        $this->info('Done');
0 ignored issues
show
Bug introduced by
It seems like info() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

38
        $this->/** @scrutinizer ignore-call */ info('Done');
Loading history...
39
    }
40
41
    /**
42
     * @param $module
43
     */
44
    protected function createModuleFolders($module)
45
    {
46
        $this->createViewsFolder($module);
47
        $this->createControllersFolder($module);
0 ignored issues
show
Bug introduced by
It seems like createControllersFolder() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

47
        $this->/** @scrutinizer ignore-call */ createControllersFolder($module);
Loading history...
48
        $this->createDatabaseMigrationsFolder($module);
49
        $this->createModelsFolder($module);
50
    }
51
52
    /**
53
     * @param $module
54
     */
55
    protected function createModelsFolder($module)
56
    {
57
        $this->createFolderInModule($module, "Models");
58
    }
59
60
    /**
61
     * @param $module
62
     */
63
    protected function createDatabaseMigrationsFolder($module)
64
    {
65
        $this->createFolderInModule($module, "Database/Migrations");
66
    }
67
68
    /**
69
     * @param $module
70
     */
71
    protected function createViewsFolder($module)
72
    {
73
        $this->createFolderInModule($module, "Views");
74
    }
75
76
    /**
77
     * @param $module
78
     * @param $folder
79
     * @return bool
80
     */
81
    protected function createFolderInModule($module, $folder)
82
    {
83
        // Does Directory Exist?
84
        if (!is_dir(base_path() . "/app/Modules/" . $module . "/" . $folder)) {
85
            // Create directory
86
            return mkdir(base_path() . "/app/Modules/" . $module . "/" . $folder, 0755, true);
87
        }
88
        return false;
89
    }
90
}