Skip to content

Commit 34ed458

Browse files
committed
refactor: code
refs: #49
1 parent 56efba7 commit 34ed458

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/Generators/EntityGenerator.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ abstract class EntityGenerator
2424
'boolean-required', 'boolean', 'timestamp-required', 'timestamp', 'json'
2525
];
2626

27+
const LOVER_CASE_DIRECTORIES_MAP = [
28+
'migrations' => 'database/migrations',
29+
'factories' => 'database/factories',
30+
'seeders' => 'database/seeders',
31+
'database_seeder' => 'database/seeders',
32+
'tests' => 'tests',
33+
'routes' => 'routes',
34+
];
35+
2736
protected $paths = [];
2837
protected $model;
2938
protected $fields;
@@ -115,18 +124,11 @@ protected function getOrCreateNamespace(string $configPath): string
115124

116125
protected function isFolderHasCorrectCase(string $folder, string $configPath): bool
117126
{
118-
$lowerCaseDirectoriesMap = [
119-
'migrations' => 'database/migrations',
120-
'factories' => 'database/factories',
121-
'seeders' => 'database/seeders',
122-
'database_seeder' => 'database/seeders',
123-
'tests' => 'tests',
124-
'routes' => 'routes',
125-
];
126-
127-
$directory = Arr::get($lowerCaseDirectoriesMap, $configPath);
128-
129-
return $folder === 'app' || preg_match('/^[A-Z]/', $folder) || Str::contains($directory, $folder);
127+
$directory = Arr::get(self::LOVER_CASE_DIRECTORIES_MAP, $configPath);
128+
129+
$firstFolderChar = substr($folder, 0, 1);
130+
131+
return $folder === 'app' || (ucfirst($firstFolderChar) === $firstFolderChar) || Str::contains($directory, $folder);
130132
}
131133

132134
abstract public function generate(): void;

0 commit comments

Comments
 (0)