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