@@ -12,6 +12,8 @@ class MakeEnum extends BaseCommand
1212{
1313 use CustomMySqlQueries;
1414
15+ private const OBJECT_NAME = 'Enum ' ;
16+
1517 /**
1618 * The name and signature of the console command.
1719 *
@@ -32,20 +34,15 @@ class MakeEnum extends BaseCommand
3234 public function handle (): void
3335 {
3436 $ this ->setArguments ();
35- $ columns = $ this ->getAllColumnsInTable ($ this ->tableName );
36-
37- $ this ->checkEmpty ($ columns , $ this ->tableName );
38-
37+ $ columns = $ this ->getColumnsOf ($ this ->tableName );
3938 $ enums = $ this ->extractEnumsFromColumns ($ columns );
4039
4140 $ attributeStub = file_get_contents ($ this ->enumStubPath . 'attribute.stub ' );
4241
4342 foreach ($ enums as $ enumName => $ enum ) {
4443 $ filenameWithPath = $ this ->relativeEnumsPath . $ enumName . '.php ' ;
4544
46- $ this ->checkDirectory ($ this ->enumNamespace );
47- $ this ->checkClassExist ($ this ->relativeEnumsPath , $ enumName , 'Enum ' );
48-
45+ $ this ->checkAndPrepare ($ enumName );
4946 $ baseContent = $ this ->getBaseCreator ($ columns , $ attributeStub , $ enum , $ enumName )
5047 ->createClass ($ filenameWithPath , $ this );
5148
@@ -73,7 +70,7 @@ public function extractEnumsFromColumns(Collection $columns): array
7370 $ this ->checkDelete (
7471 $ this ->relativeEnumsPath . $ enumClassName . '.php ' ,
7572 $ enumClassName ,
76- ' Enum '
73+ self :: OBJECT_NAME
7774 );
7875 }
7976
@@ -85,7 +82,7 @@ private function getEnumClassName(mixed $_column): string
8582 $ tableName = ucfirst (Str::camel ($ _column ->TABLE_NAME ));
8683 $ columnName = $ _column ->COLUMN_NAME ;
8784
88- return Str::studly (Str::singular ($ tableName ) . '_ ' . $ columnName ) . ' Enum ' ;
85+ return Str::studly (Str::singular ($ tableName ) . '_ ' . $ columnName ) . self :: OBJECT_NAME ;
8986 }
9087
9188 private function extractEnumValues ($ columnType ): array
@@ -108,4 +105,26 @@ private function getBaseCreator(Collection $columns, bool|string $attributeStub,
108105
109106 return new BaseCreator ($ enumCreator );
110107 }
108+
109+ /**
110+ * @param string $table
111+ * @return Collection
112+ */
113+ public function getColumnsOf (string $ table ): Collection
114+ {
115+ $ columns = $ this ->getAllColumnsInTable ($ table );
116+ $ this ->checkEmpty ($ columns , $ table );
117+
118+ return $ columns ;
119+ }
120+
121+ /**
122+ * @param int|string $enumName
123+ * @return void
124+ */
125+ public function checkAndPrepare (int |string $ enumName ): void
126+ {
127+ $ this ->checkDirectory ($ this ->enumNamespace );
128+ $ this ->checkClassExist ($ this ->relativeEnumsPath , $ enumName , self ::OBJECT_NAME );
129+ }
111130}
0 commit comments