1919use RonasIT \Support \Generators \TranslationsGenerator ;
2020use RonasIT \Support \Generators \SeederGenerator ;
2121use Illuminate \Contracts \Events \Dispatcher as EventDispatcher ;
22+ use UnexpectedValueException ;
2223
2324/**
2425 * @property ControllerGenerator $controllerGenerator
3536 */
3637class MakeEntityCommand extends Command
3738{
39+ const CRUD_OPTIONS = [
40+ 'C ' , 'R ' , 'U ' , 'D '
41+ ];
42+
3843 /**
3944 * The name and signature of the console command.
4045 *
@@ -180,12 +185,8 @@ protected function classExists($path, $name)
180185
181186 protected function validateInput ()
182187 {
183- if ($ this ->option ('only-api ' )) {
184- $ modelName = $ this ->argument ('name ' );
185- if (!$ this ->classExists ('services ' , "{$ modelName }Service " )) {
186- throw new ClassNotExistsException ('Cannot create API without entity. ' );
187- }
188- }
188+ $ this ->validateOnlyApiOption ();
189+ $ this ->validateCrudOptions ();
189190 }
190191
191192 protected function generate ()
@@ -233,7 +234,7 @@ protected function runGeneration($generator)
233234
234235 protected function getCrudOptions ()
235236 {
236- return $ this ->validateCrudOptions ( );
237+ return str_split ( $ this ->option ( ' methods ' ) );
237238 }
238239
239240 protected function getRelations ()
@@ -260,14 +261,22 @@ protected function getFields()
260261
261262 protected function validateCrudOptions ()
262263 {
263- $ crudOptions = str_split ( $ this ->option ( ' methods ' ) );
264+ $ crudOptions = $ this ->getCrudOptions ( );
264265
265266 foreach ($ crudOptions as $ crudOption ) {
266- if (!in_array ($ crudOption , EntityGenerator ::CRUD_OPTIONS )) {
267- throw new \ UnexpectedValueException ("Invalid method {$ crudOption }. " );
267+ if (!in_array ($ crudOption , MakeEntityCommand ::CRUD_OPTIONS )) {
268+ throw new UnexpectedValueException ("Invalid method {$ crudOption }. " );
268269 }
269270 }
271+ }
270272
271- return $ crudOptions ;
273+ protected function validateOnlyApiOption ()
274+ {
275+ if ($ this ->option ('only-api ' )) {
276+ $ modelName = $ this ->argument ('name ' );
277+ if (!$ this ->classExists ('services ' , "{$ modelName }Service " )) {
278+ throw new ClassNotExistsException ('Cannot create API without entity. ' );
279+ }
280+ }
272281 }
273282}
0 commit comments