Skip to content

Commit 620041e

Browse files
committed
refactor: code
refs: #50
1 parent 31857aa commit 620041e

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/Generators/AbstractTestsGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ protected function generateFixture($fixtureName, $data): void
218218
protected function buildRelationsTree($models): array
219219
{
220220
foreach ($models as $model) {
221-
$relations = $this->getRelatedModels($model, 'Test');
221+
$relations = $this->getRelatedModels($model, $this->getTestClassName());
222222
$relationsWithFactories = $this->getModelsWithFactories($relations);
223223

224224
if (empty($relationsWithFactories)) {

src/Generators/EntityGenerator.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,23 @@ protected function throwFailureException($exceptionClass, $failureMessage, $reco
164164
throw new $exceptionClass("{$failureMessage} {$recommendedMessage}");
165165
}
166166

167-
protected function getRelatedModels(string $model, string $classType): array
167+
protected function getRelatedModels(string $model, string $creatableClass): array
168168
{
169-
$class = $this->getModelClass($model);
169+
$modelClass = $this->getModelClass($model);
170170

171-
if (!class_exists($class)) {
171+
if (!class_exists($modelClass)) {
172172
$this->throwFailureException(
173173
ClassNotExistsException::class,
174-
"Cannot create {$model}{$classType} cause {$model} Model does not exists.",
174+
"Cannot create {$creatableClass} cause {$model} Model does not exists.",
175175
"Create a {$model} Model by himself or run command 'php artisan make:entity {$model} --only-model'."
176176
);
177177
}
178178

179-
$instance = new $class();
179+
$instance = new $modelClass();
180180

181-
$publicMethods = (new ReflectionClass($class))->getMethods(ReflectionMethod::IS_PUBLIC);
181+
$publicMethods = (new ReflectionClass($modelClass))->getMethods(ReflectionMethod::IS_PUBLIC);
182182

183-
$methods = array_filter($publicMethods, fn ($method) => $method->class === $class && !$method->getParameters());
183+
$methods = array_filter($publicMethods, fn ($method) => $method->class === $modelClass && !$method->getParameters());
184184

185185
$relatedModels = [];
186186

src/Generators/FactoryGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected function prepareEmptyFactory(): void
112112
protected function checkExistRelatedModelsFactories(): bool
113113
{
114114
$modelFactoryContent = file_get_contents($this->paths['factory']);
115-
$relatedModels = $this->getRelatedModels($this->model, 'Factory');
115+
$relatedModels = $this->getRelatedModels($this->model, "{$this->model}Factory");
116116
$modelNamespace = $this->getOrCreateNamespace('models');
117117

118118
foreach ($relatedModels as $relatedModel) {

0 commit comments

Comments
 (0)