Skip to content

Commit 68f996c

Browse files
committed
refactor: move path-to-namespace logic to helper
1 parent 0332cb1 commit 68f996c

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/Generators/EntityGenerator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,9 @@ protected function prepareRelations(): array
300300

301301
return $result;
302302
}
303+
304+
protected function pathToNamespace(string $name): string
305+
{
306+
return Str::replace('/', '\\', $name);
307+
}
303308
}

src/Generators/ModelGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ protected function shouldImportRelation(string $relation): bool
193193
protected function generateClassNamespace(string $className, ?string $folder = null): string
194194
{
195195
$path = $this->getNamespace('models', $folder);
196-
$psrPath = Str::replace('/', '\\', $className);
196+
$psrPath = $this->pathToNamespace($className);
197197

198198
return "{$path}\\{$psrPath}";
199199
}

src/Generators/NovaTestGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected function doesNovaResourceExists(): bool
120120

121121
foreach ($possibleNovaModelNames as $modelName) {
122122
if ($this->classExists('nova', $modelName)) {
123-
$this->novaModelName = Str::replace('/', '\\', $modelName);
123+
$this->novaModelName = $this->pathToNamespace($modelName);
124124

125125
return true;
126126
}

0 commit comments

Comments
 (0)