@@ -12,6 +12,8 @@ class MakeEnum extends BaseCommand
12
12
{
13
13
use CustomMySqlQueries;
14
14
15
+ private const OBJECT_NAME = 'Enum ' ;
16
+
15
17
/**
16
18
* The name and signature of the console command.
17
19
*
@@ -32,20 +34,15 @@ class MakeEnum extends BaseCommand
32
34
public function handle (): void
33
35
{
34
36
$ this ->setArguments ();
35
- $ columns = $ this ->getAllColumnsInTable ($ this ->tableName );
36
-
37
- $ this ->checkEmpty ($ columns , $ this ->tableName );
38
-
37
+ $ columns = $ this ->getColumnsOf ($ this ->tableName );
39
38
$ enums = $ this ->extractEnumsFromColumns ($ columns );
40
39
41
40
$ attributeStub = file_get_contents ($ this ->enumStubPath . 'attribute.stub ' );
42
41
43
42
foreach ($ enums as $ enumName => $ enum ) {
44
43
$ filenameWithPath = $ this ->relativeEnumsPath . $ enumName . '.php ' ;
45
44
46
- $ this ->checkDirectory ($ this ->enumNamespace );
47
- $ this ->checkClassExist ($ this ->relativeEnumsPath , $ enumName , 'Enum ' );
48
-
45
+ $ this ->checkAndPrepare ($ enumName );
49
46
$ baseContent = $ this ->getBaseCreator ($ columns , $ attributeStub , $ enum , $ enumName )
50
47
->createClass ($ filenameWithPath , $ this );
51
48
@@ -73,7 +70,7 @@ public function extractEnumsFromColumns(Collection $columns): array
73
70
$ this ->checkDelete (
74
71
$ this ->relativeEnumsPath . $ enumClassName . '.php ' ,
75
72
$ enumClassName ,
76
- ' Enum '
73
+ self :: OBJECT_NAME
77
74
);
78
75
}
79
76
@@ -85,7 +82,7 @@ private function getEnumClassName(mixed $_column): string
85
82
$ tableName = ucfirst (Str::camel ($ _column ->TABLE_NAME ));
86
83
$ columnName = $ _column ->COLUMN_NAME ;
87
84
88
- return Str::studly (Str::singular ($ tableName ) . '_ ' . $ columnName ) . ' Enum ' ;
85
+ return Str::studly (Str::singular ($ tableName ) . '_ ' . $ columnName ) . self :: OBJECT_NAME ;
89
86
}
90
87
91
88
private function extractEnumValues ($ columnType ): array
@@ -108,4 +105,26 @@ private function getBaseCreator(Collection $columns, bool|string $attributeStub,
108
105
109
106
return new BaseCreator ($ enumCreator );
110
107
}
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
+ }
111
130
}
0 commit comments