MakeModule::createModelsFolder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 */ 
15
               info("Creating a new Module");
Loading history...
15
16
        if (is_dir(base_path('app/Modules/' . $module))) {
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 */ 
18
                   error("$module already exists. If you really want to create this module, please delete the following folder: " . base_path('app/Modules/' . $module));
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 169 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
18
            return;
19
        }
20
21
        // Create all module's folders
22
        $this->info("Creating folder structure");
23
        $this->createModuleFolders($module);
24
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
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 */ 
31
                   createApiRoutesFile($module);
Loading history...
31
        }
32
33
        // Web Routes File
34
        if ($this->option('webroute') || !$this->option('apiroute')) {
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 */ 
36
                   createWebRoutesFile($module);
Loading history...
36
        }
37
38
        $this->info('Done');
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 */ 
48
               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
}