@@ -13,6 +13,8 @@ class MakeEntity extends BaseCommand
13
13
{
14
14
use CustomMySqlQueries;
15
15
16
+ private const OBJECT_NAME = 'Entity ' ;
17
+
16
18
/**
17
19
* The name and signature of the console command.
18
20
*
@@ -39,28 +41,65 @@ public function handle(): void
39
41
$ this ->setArguments ();
40
42
$ filenameWithPath = $ this ->relativeEntitiesPath . $ this ->entityName . '.php ' ;
41
43
42
- $ this ->checkDelete ($ filenameWithPath , $ this ->entityName , "Entity " );
43
- $ this ->checkDirectory ($ this ->relativeEntitiesPath );
44
- $ this ->checkClassExist ($ this ->entityNamespace , $ this ->entityName , "Entity " );
45
-
46
- $ columns = $ this ->getAllColumnsInTable ($ this ->tableName );
47
- $ this ->checkEmpty ($ columns , $ this ->tableName );
44
+ $ this ->checkAndPrepare ($ filenameWithPath );
45
+ $ columns = $ this ->getColumnsOf ($ this ->tableName );
48
46
49
47
foreach ($ columns as $ _column ) {
50
48
$ _column ->COLUMN_NAME = Str::camel ($ _column ->COLUMN_NAME );
51
49
}
52
50
53
- $ entityCreator = new CreatorEntity ($ columns ,
51
+ $ entityCreator = $ this ->getEntityCreator ($ columns );
52
+ $ baseContent = $ this ->getBaseContent ($ entityCreator , $ filenameWithPath );
53
+
54
+ $ this ->finalized ($ filenameWithPath , $ this ->entityName , $ baseContent );
55
+ }
56
+
57
+ /**
58
+ * @param string $tableName
59
+ * @return Collection
60
+ */
61
+ private function getColumnsOf (string $ tableName ): Collection
62
+ {
63
+ $ columns = $ this ->getAllColumnsInTable ($ tableName );
64
+ $ this ->checkEmpty ($ columns , $ tableName );
65
+
66
+ return $ columns ;
67
+ }
68
+
69
+ /**
70
+ * @param string $filenameWithPath
71
+ * @return void
72
+ */
73
+ private function checkAndPrepare (string $ filenameWithPath ): void
74
+ {
75
+ $ this ->checkDelete ($ filenameWithPath , $ this ->entityName , self ::OBJECT_NAME );
76
+ $ this ->checkDirectory ($ this ->relativeEntitiesPath );
77
+ $ this ->checkClassExist ($ this ->entityNamespace , $ this ->entityName , self ::OBJECT_NAME );
78
+ }
79
+
80
+ /**
81
+ * @param Collection $columns
82
+ * @return CreatorEntity
83
+ */
84
+ private function getEntityCreator (Collection $ columns ): CreatorEntity
85
+ {
86
+ return new CreatorEntity ($ columns ,
54
87
$ this ->detectForeignKeys ,
55
88
$ this ->tableName ,
56
89
$ this ->entityName ,
57
90
$ this ->entityNamespace ,
58
91
$ this ->entityStubsPath
59
92
);
60
- $ creator = new BaseCreator ($ entityCreator );
61
- $ baseContent = $ creator ->createClass ($ filenameWithPath , $ this );
62
-
63
- $ this ->finalized ($ filenameWithPath , $ this ->entityName , $ baseContent );
93
+ }
64
94
95
+ /**
96
+ * @param CreatorEntity $entityCreator
97
+ * @param string $filenameWithPath
98
+ * @return string
99
+ */
100
+ private function getBaseContent (CreatorEntity $ entityCreator , string $ filenameWithPath ): string
101
+ {
102
+ $ creator = new BaseCreator ($ entityCreator );
103
+ return $ creator ->createClass ($ filenameWithPath , $ this );
65
104
}
66
105
}
0 commit comments