@@ -11,6 +11,8 @@ class MakeMySqlRepository extends BaseCommand
11
11
{
12
12
use CustomMySqlQueries;
13
13
14
+ private const OBJECT_NAME = 'MySql Repository ' ;
15
+
14
16
/**
15
17
* The name and signature of the console command.
16
18
*
@@ -30,22 +32,52 @@ class MakeMySqlRepository extends BaseCommand
30
32
protected $ description = 'Create a new MySql repository class ' ;
31
33
32
34
33
- /**
34
- * Execute the console command.
35
- *
36
- * @return int
37
- */
38
35
public function handle (): void
39
36
{
40
37
$ this ->setArguments ();
41
- $ filenameWithPath = $ this ->relativeMysqlRepositoryPath . $ this ->mysqlRepositoryName . '.php ' ;
42
- $ this ->checkDelete ($ filenameWithPath , $ this ->mysqlRepositoryName , "MySql Repository " );
38
+
39
+ $ filenameWithPath = $ this ->getFileNameWithPath (
40
+ $ this ->relativeMysqlRepositoryPath ,
41
+ $ this ->mysqlRepositoryName
42
+ );
43
+
44
+ $ this ->checkAndPrepare ($ filenameWithPath );
45
+
46
+ $ this ->finalized (
47
+ $ filenameWithPath ,
48
+ $ this ->mysqlRepositoryName ,
49
+ $ this ->generateBaseContent ($ filenameWithPath )
50
+ );
51
+ }
52
+
53
+
54
+ private function getFileNameWithPath (string $ relativePath , string $ sectionName ): string
55
+ {
56
+ return $ relativePath . $ sectionName . '.php ' ;
57
+ }
58
+
59
+
60
+ private function checkAndPrepare (string $ filenameWithPath )
61
+ {
62
+ $ this ->checkDelete ($ filenameWithPath , $ this ->mysqlRepositoryName , self ::OBJECT_NAME );
43
63
$ this ->checkDirectory ($ this ->relativeMysqlRepositoryPath );
44
- $ this ->checkClassExist ($ this ->repositoryNamespace , $ this ->mysqlRepositoryName , " MySql Repository " );
45
- $ columns = $ this -> getAllColumnsInTable ( $ this -> tableName );
46
- $ this -> checkEmpty ( $ columns , $ this -> tableName );
64
+ $ this ->checkClassExist ($ this ->repositoryNamespace , $ this ->mysqlRepositoryName , self :: OBJECT_NAME );
65
+ }
66
+
47
67
48
- $ mysqlRepoCreator = new CreatorMySqlRepository ($ columns ,
68
+ private function getColumnsOf (string $ tableName ): Collection
69
+ {
70
+ $ columns = $ this ->getAllColumnsInTable ($ tableName );
71
+ $ this ->checkEmpty ($ columns , $ tableName );
72
+
73
+ return $ columns ;
74
+ }
75
+
76
+
77
+ private function generateBaseContent (string $ filenameWithPath ): string
78
+ {
79
+ $ mysqlRepoCreator = new CreatorMySqlRepository (
80
+ $ this ->getColumnsOf ($ this ->tableName ),
49
81
$ this ->tableName ,
50
82
$ this ->entityName ,
51
83
$ this ->entityVariableName ,
@@ -58,9 +90,7 @@ public function handle(): void
58
90
$ this ->mysqlRepositoryStubsPath ,
59
91
$ this ->detectForeignKeys
60
92
);
61
- $ creator = new BaseCreator ($ mysqlRepoCreator );
62
- $ baseContent = $ creator ->createClass ($ filenameWithPath , $ this );
63
93
64
- $ this -> finalized ($ filenameWithPath , $ this -> mysqlRepositoryName , $ baseContent );
94
+ return ( new BaseCreator ( $ mysqlRepoCreator ))-> createClass ($ filenameWithPath , $ this );
65
95
}
66
96
}
0 commit comments