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
![]() |
|||||||
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
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
![]() |
|||||||
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
|
|||||||
25 | |||||||
26 | // Create routes file |
||||||
27 | |||||||
28 | // API Routes File |
||||||
29 | if ($this->option('apiroute')) { |
||||||
0 ignored issues
–
show
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
![]() |
|||||||
30 | $this->createApiRoutesFile($module); |
||||||
0 ignored issues
–
show
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
![]() |
|||||||
31 | } |
||||||
32 | |||||||
33 | // Web Routes File |
||||||
34 | if ($this->option('webroute') || !$this->option('apiroute')) { |
||||||
35 | $this->createWebRoutesFile($module); |
||||||
0 ignored issues
–
show
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
![]() |
|||||||
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
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
![]() |
|||||||
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 | } |