Issues (413)

app/Generators/Commands/EntityCommand.php (2 issues)

Severity
1
<?php
2
3
namespace Yeelight\Generators\Commands;
4
5
use Illuminate\Support\Collection;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputOption;
8
9
/**
10
 * Class EntityCommand
11
 *
12
 * @category Yeelight
13
 *
14
 * @package Yeelight\Generators\Commands
15
 *
16
 * @author Sheldon Lee <[email protected]>
17
 *
18
 * @license https://opensource.org/licenses/MIT MIT
19
 *
20
 * @link https://www.yeelight.com
21
 */
22
class EntityCommand extends CommandBase
23
{
24
    /**
25
     * The name of command.
26
     *
27
     * @var string
28
     */
29
    protected $name = 'yl:entity';
30
31
    /**
32
     * The description of command.
33
     *
34
     * @var string
35
     */
36
    protected $description = 'Create a new entity.';
37
38
    /**
39
     * $generators
40
     *
41
     * @var Collection
42
     */
43
    protected $generators = null;
44
45
    /**
46
     * Execute the command.
47
     *
48
     * @return void
49
     */
50
    public function fire()
51
    {
52
        $presenter = $this->option('presenter');
53
        if (is_null($presenter)
0 ignored issues
show
The condition is_null($presenter) is always false.
Loading history...
54
            && $this->confirm('Would you like to create a Presenter? [y|N]')
55
        ) {
56
            $presenter = 'yes';
57
        }
58
59
        if ($presenter == 'yes') {
60
            $this->call(
61
                'yl:presenter',
62
                [
63
                    'name' => $this->argument('name'),
64
                    '--force' => $this->option('force'),
65
                ]
66
            );
67
        }
68
69
        $validator = $this->option('validator');
70
        if (is_null($validator)
0 ignored issues
show
The condition is_null($validator) is always false.
Loading history...
71
            && $this->confirm('Would you like to create a Validator? [y|N]')
72
        ) {
73
            $validator = 'yes';
74
        }
75
76
        if ($validator == 'yes') {
77
            $this->call(
78
                'yl:validator',
79
                [
80
                    'name' => $this->argument('name'),
81
                    '--rules' => $this->option('rules'),
82
                    '--force' => $this->option('force'),
83
                ]
84
            );
85
        }
86
87
        if ($this->confirm('Would you like to create a Controller? [y|N]')) {
88
89
            // Generate a controller resource
90
            $this->call(
91
                'yl:controller',
92
                [
93
                    'name' => $this->argument('name'),
94
                    '--fields' => $this->option('fields'),
95
                    '--force' => $this->option('force'),
96
                ]
97
            );
98
        }
99
100
        if ($this->confirm('Would you like to create a API Controller? [y|N]')) {
101
102
            // Generate a api controller resource
103
            $this->call(
104
                'yl:api_controller',
105
                [
106
                    'name' => $this->argument('name'),
107
                    '--fields' => $this->option('fields'),
108
                    '--force' => $this->option('force'),
109
                ]
110
            );
111
        }
112
113
        if ($this->confirm('Would you like to create CURD views? [y|N]')) {
114
115
            // Generate a controller resource
116
            $this->call(
117
                'yl:views',
118
                [
119
                    'name' => $this->argument('name'),
120
                    '--fields' => $this->option('fields'),
121
                    '--force' => $this->option('force'),
122
                ]
123
            );
124
        }
125
126
        if ($this->confirm('Would you like to create language package? [y|N]')) {
127
128
            // Generate a controller resource
129
            $this->call(
130
                'yl:lang',
131
                [
132
                    'name' => $this->argument('name'),
133
                    '--fields' => $this->option('fields'),
134
                    '--force' => $this->option('force'),
135
                ]
136
            );
137
        }
138
139
        $this->call(
140
            'yl:repository',
141
            [
142
                'name' => $this->argument('name'),
143
                '--fillable' => $this->option('fillable'),
144
                '--rules' => $this->option('rules'),
145
                '--fields' => $this->option('fields'),
146
                '--validator' => $validator,
147
                '--presenter' => $presenter,
148
                '--force' => $this->option('force'),
149
            ]
150
        );
151
152
        $this->call(
153
            'yl:bindings',
154
            [
155
                'name' => $this->argument('name'),
156
                '--force' => $this->option('force'),
157
            ]
158
        );
159
    }
160
161
    /**
162
     * The array of command arguments.
163
     *
164
     * @return array
165
     */
166
    public function getArguments()
167
    {
168
        return [
169
            [
170
                'name',
171
                InputArgument::REQUIRED,
172
                'The name of class being generated.',
173
                null,
174
            ],
175
        ];
176
    }
177
178
    /**
179
     * The array of command options.
180
     *
181
     * @return array
182
     */
183
    public function getOptions()
184
    {
185
        return [
186
            [
187
                'fillable',
188
                null,
189
                InputOption::VALUE_OPTIONAL,
190
                'The fillable attributes.',
191
                null,
192
            ],
193
            [
194
                'rules',
195
                null,
196
                InputOption::VALUE_OPTIONAL,
197
                'The rules of validation attributes.',
198
                null,
199
            ],
200
            [
201
                'validator',
202
                null,
203
                InputOption::VALUE_OPTIONAL,
204
                'Adds validator reference to the repository.',
205
                null,
206
            ],
207
            [
208
                'presenter',
209
                null,
210
                InputOption::VALUE_OPTIONAL,
211
                'Adds presenter reference to the repository.',
212
                null,
213
            ],
214
            [
215
                'force',
216
                'f',
217
                InputOption::VALUE_NONE,
218
                'Force the creation if file already exists.',
219
                null,
220
            ],
221
        ];
222
    }
223
}
224