@@ -13,6 +13,8 @@ class MakeEntity extends BaseCommand
1313{
1414 use CustomMySqlQueries;
1515
16+ private const OBJECT_NAME = 'Entity ' ;
17+
1618 /**
1719 * The name and signature of the console command.
1820 *
@@ -39,28 +41,65 @@ public function handle(): void
3941 $ this ->setArguments ();
4042 $ filenameWithPath = $ this ->relativeEntitiesPath . $ this ->entityName . '.php ' ;
4143
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 );
4846
4947 foreach ($ columns as $ _column ) {
5048 $ _column ->COLUMN_NAME = Str::camel ($ _column ->COLUMN_NAME );
5149 }
5250
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 ,
5487 $ this ->detectForeignKeys ,
5588 $ this ->tableName ,
5689 $ this ->entityName ,
5790 $ this ->entityNamespace ,
5891 $ this ->entityStubsPath
5992 );
60- $ creator = new BaseCreator ($ entityCreator );
61- $ baseContent = $ creator ->createClass ($ filenameWithPath , $ this );
62-
63- $ this ->finalized ($ filenameWithPath , $ this ->entityName , $ baseContent );
93+ }
6494
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 );
65104 }
66105}
0 commit comments