Issues (38)

src/Console/MakeModuleCommand.php (7 issues)

1
<?php
2
3
namespace neilherbertuk\modules\Console;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\App;
7
use neilherbertuk\modules\Traits\MakeController;
8
use neilherbertuk\modules\Traits\MakeModule;
9
use neilherbertuk\modules\Traits\MakeRoutes;
10
11
class MakeModuleCommand extends Command
12
{
13
14
    use MakeModule, MakeController, MakeRoutes;
15
16
    /**
17
     * The name and signature of the console command.
18
     *
19
     * @var string
20
     */
21
    protected $signature = 'make:module
0 ignored issues
show
Protected member variable "signature" must contain a leading underscore
Loading history...
22
                    {module? : Name of module}
23
                    {filename? : Name of file to create}
24
                    {--create : Creates scaffold for new module}
25
                    {--controller : Creates a controller}' .
26
//                    {--migration : Creates a migration}
27
//                    {--model : Creates a model}
28
                    '{--webroute : Creates a web route file}
29
                    {--apiroute : Creates an API route file}
30
                    {--resource}';
31
32
    /**
33
     * The console command description.
34
     *
35
     * @var string
36
     */
37
    protected $description = 'Scaffold for laravel modules';
0 ignored issues
show
Protected member variable "description" must contain a leading underscore
Loading history...
38
39
    /**
40
     * Create a new command instance.
41
     *
42
     */
43
    public function __construct()
44
    {
45
        parent::__construct();
46
    }
47
48
    /**
49
     * Execute the console command.
50
     *
51
     * @return mixed
52
     */
53
    public function handle()
54
    {
55
        // Get user input - Module Name and Filename
56
        $module = $this->argument('module');
57
        $filename = $this->argument('filename');
58
59
        // Has a Module Name been provided?
60
        if ($this->isModuleNameGiven($module)) {
61
62
            $this->info("Module Name: $module");
63
64
            // Create Module
65
            if ($this->option('create')) {
66
                $this->createModule($module);
67
                return;
68
            }
69
70
            // Create Individual Module Files
71
72
            // Create Web Routes File
73
            if ($this->option('webroute')) {
74
                // Create web.php routes file
75
                $this->createWebRoutesFile($module);
76
                return;
77
            }
78
79
            // Create API Routes File
80
            if ($this->option('apiroute')) {
81
                // Create api.php routes file
82
                $this->createApiRoutesFile($module);
83
                return;
84
            }
85
86
            // Has a File Name been given?
87
            if($this->isFileNameGiven($filename)){
0 ignored issues
show
Expected 1 space after IF keyword; 0 found
Loading history...
88
89
                // Create Controller
90
                if($this->option('controller')) {
0 ignored issues
show
Expected 1 space after IF keyword; 0 found
Loading history...
91
                    $this->createController($module, $filename);
92
                    return;
93
                }
94
            }
95
96
        }
97
98
        // Show Usage
99
        $this->showUsage();
100
    }
101
102
    /**
103
     *
104
     */
105
    protected function showUsage()
106
    {
107
        $this->info($this->getDescription());
108
        $this->warn('Usage: ');
109
        $this->line('   make:module ModuleName [--] [FileName]');
110
        $this->line('');
111
        $this->warn('Arguments:');
112
        $this->line('   ModuleName - The name of the module to perform command on');
113
        $this->line('   FileName - Required for some options - The file name to use if required by an option');
0 ignored issues
show
This line exceeds maximum limit of 100 characters; contains 111 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...
114
        $this->line('');
115
        $this->warn('Options:');
116
        $this->info('   --create                - Creates the folder structure and web routes file for a module');
0 ignored issues
show
This line exceeds maximum limit of 100 characters; contains 114 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...
117
        $this->info('   --controller [FileName] [--plain] - Creates a controller for the module given - add'.
0 ignored issues
show
This line exceeds maximum limit of 100 characters; contains 109 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...
118
         ' --plain to create an empty controller.');
119
//        $this->info('   --migration [FileName]  - Creates a migration for the module given');
120
//        $this->info('   --model [FileName]      - Creates a model for the module given');
121
        $this->info('   --webroute              - Creates a web routes file for the module given');
122
        $this->info('   --apiroute              - Creates a web routes file for the module given');
123
    }
124
125
    /**
126
     * @param $module
127
     * @return bool
128
     */
129
    protected function isModuleNameGiven($module)
130
    {
131
        return !empty($module);
132
    }
133
134
    /**
135
     * @param $filename
136
     * @return bool
137
     */
138
    protected function isFileNameGiven($filename)
139
    {
140
        return !empty($filename);
141
    }
142
}