@@ -31,9 +31,11 @@ public function getNameSpace(): string
3131
3232 public function createUses (): array
3333 {
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+ ];
3739 }
3840
3941 public function getClassName (): string
@@ -70,25 +72,34 @@ public function createFunctions(): array
7072 $ foreignGetterFunctions .= $ this ->writeForeignGetter ($ foreignGetterStub , $ _foreignKey ->VARIABLE_NAME , $ _foreignKey ->ENTITY_DATA_TYPE );
7173 }
7274 }
75+
7376 $ functions = [];
7477 $ functions ['toArray ' ] = str_replace (['{{ Getters }} ' ], [$ getters ], $ getterFunStub );
7578 $ functions ['toArray ' ] = str_replace (['{{ EntityVariableName }} ' ], [$ this ->entityVariableName ], $ functions ['toArray ' ]);
7679 $ functions ['toArrayWithForeignKeys ' ] = str_replace (['{{ ForeignGetterFunctions }} ' ], [$ foreignGetterFunctions ], $ foreignFunStub );
7780 $ functions ['toArrayWithForeignKeys ' ] = str_replace (['{{ EntityVariableName }} ' ], [$ this ->entityVariableName ], $ functions ['toArrayWithForeignKeys ' ]);
81+
7882 return $ functions ;
7983 }
8084
81- public function writeGetter (string $ getterStub , string $ columnName , string $ attributeName )
85+ public function writeGetter (string $ getterStub , string $ columnName , string $ attributeName ): array | string
8286 {
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 );
8693 }
8794
88- public function writeForeignGetter (string $ foreignGetterStub , string $ columnName , string $ attributeName )
95+ public function writeForeignGetter (string $ foreignGetterStub , string $ columnName , string $ attributeName ): array | string
8996 {
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 );
93104 }
94105}
0 commit comments