@@ -31,9 +31,11 @@ public function getNameSpace(): string
31
31
32
32
public function createUses (): array
33
33
{
34
- return ["use $ this ->entityNamespace \\$ this ->entityName ; " ,
35
- "use Eghamat24\DatabaseRepository\Models\Entity\Entity; " ,
36
- "use Eghamat24\DatabaseRepository\Models\Resources\Resource; " ];
34
+ return [
35
+ "use $ this ->entityNamespace \\$ this ->entityName ; " ,
36
+ 'use Eghamat24\DatabaseRepository\Models\Entity\Entity; ' ,
37
+ 'use Eghamat24\DatabaseRepository\Models\Resources\Resource; '
38
+ ];
37
39
}
38
40
39
41
public function getClassName (): string
@@ -70,25 +72,34 @@ public function createFunctions(): array
70
72
$ foreignGetterFunctions .= $ this ->writeForeignGetter ($ foreignGetterStub , $ _foreignKey ->VARIABLE_NAME , $ _foreignKey ->ENTITY_DATA_TYPE );
71
73
}
72
74
}
75
+
73
76
$ functions = [];
74
77
$ functions ['toArray ' ] = str_replace (['{{ Getters }} ' ], [$ getters ], $ getterFunStub );
75
78
$ functions ['toArray ' ] = str_replace (['{{ EntityVariableName }} ' ], [$ this ->entityVariableName ], $ functions ['toArray ' ]);
76
79
$ functions ['toArrayWithForeignKeys ' ] = str_replace (['{{ ForeignGetterFunctions }} ' ], [$ foreignGetterFunctions ], $ foreignFunStub );
77
80
$ functions ['toArrayWithForeignKeys ' ] = str_replace (['{{ EntityVariableName }} ' ], [$ this ->entityVariableName ], $ functions ['toArrayWithForeignKeys ' ]);
81
+
78
82
return $ functions ;
79
83
}
80
84
81
- public function writeGetter (string $ getterStub , string $ columnName , string $ attributeName )
85
+ public function writeGetter (string $ getterStub , string $ columnName , string $ attributeName ): array | string
82
86
{
83
- return str_replace (['{{ ColumnName }} ' , '{{ GetterName }} ' ],
84
- [$ columnName , ucfirst ($ attributeName )],
85
- $ getterStub );
87
+ $ replaceMapping = [
88
+ '{{ ColumnName }} ' => $ columnName ,
89
+ '{{ GetterName }} ' => ucfirst ($ attributeName ),
90
+ ];
91
+
92
+ return str_replace (array_keys ($ replaceMapping ), array_values ($ replaceMapping ), $ getterStub );
86
93
}
87
94
88
- public function writeForeignGetter (string $ foreignGetterStub , string $ columnName , string $ attributeName )
95
+ public function writeForeignGetter (string $ foreignGetterStub , string $ columnName , string $ attributeName ): array | string
89
96
{
90
- return str_replace (['{{ AttributeName }} ' , '{{ GetterName }} ' , '{{ AttributeType }} ' ],
91
- [Str::snake ($ columnName ), ucfirst ($ columnName ), ucfirst ($ attributeName )],
92
- $ foreignGetterStub );
97
+ $ replaceMapping = [
98
+ '{{ AttributeName }} ' => Str::snake ($ columnName ),
99
+ '{{ GetterName }} ' => ucfirst ($ columnName ),
100
+ '{{ AttributeType }} ' => ucfirst ($ attributeName )
101
+ ];
102
+
103
+ return str_replace (array_keys ($ replaceMapping ), array_values ($ replaceMapping ), $ foreignGetterStub );
93
104
}
94
105
}
0 commit comments