Skip to content

Commit 7c906b1

Browse files
committed
Fix MakeFactory Command to Properly Add Setters Functions
1 parent 4e59112 commit 7c906b1

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

src/Commands/MakeFactory.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,13 @@ public function handle(): int
8181
$setterStub = file_get_contents($factoryStubsPath.'setter.stub');
8282

8383
// Initialize Class
84+
$setterFunctions = '';
8485
foreach ($columns as $_column) {
85-
$baseContent = substr_replace($baseContent,
86-
$this->writeSetter($setterStub, $_column->COLUMN_NAME),
87-
-53, 0);
86+
$setterFunctions .= $this->writeSetter($setterStub, $_column->COLUMN_NAME);
8887
}
8988

90-
$baseContent = str_replace(['{{ EntityName }}', '{{ EntityNamespace }}', '{{ FactoryName }}', '{{ FactoryNamespace }}', '{{ EntityVariableName }}'],
91-
[$entityName, $entityNamespace, $factoryName, $factoryNamespace, $entityVariableName],
89+
$baseContent = str_replace(['{{ SetterFunctions }}', '{{ EntityName }}', '{{ EntityNamespace }}', '{{ FactoryName }}', '{{ FactoryNamespace }}', '{{ EntityVariableName }}'],
90+
[$setterFunctions, $entityName, $entityNamespace, $factoryName, $factoryNamespace, $entityVariableName],
9291
$baseContent);
9392

9493
file_put_contents($filenameWithPath, $baseContent);

stubs/PHP7.0/repository.factory.class.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class {{ FactoryName }} extends Factory
1515
{
1616
${{ EntityVariableName }} = new {{ EntityName }}();
1717

18-
18+
{{ SetterFunctions }}
1919
return ${{ EntityVariableName }};
2020
}
2121
}

stubs/PHP7.4/repository.factory.class.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class {{ FactoryName }} extends Factory
1515
{
1616
${{ EntityVariableName }} = new {{ EntityName }}();
1717

18-
18+
{{ SetterFunctions }}
1919
return ${{ EntityVariableName }};
2020
}
2121
}

stubs/PHP8.0/repository.factory.class.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class {{ FactoryName }} extends Factory
1515
{
1616
${{ EntityVariableName }} = new {{ EntityName }}();
1717

18-
18+
{{ SetterFunctions }}
1919
return ${{ EntityVariableName }};
2020
}
2121
}

0 commit comments

Comments
 (0)