-
Notifications
You must be signed in to change notification settings - Fork 3
fix: seeder stub and model generation #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php | ||
|
|
||
| namespace RonasIT\Support\Exceptions; | ||
|
|
||
| use Exception; | ||
|
|
||
| class IncorrectClassPathException extends Exception | ||
| { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| use Illuminate\Support\Str; | ||
| use RonasIT\Support\Events\WarningEvent; | ||
| use RonasIT\Support\Exceptions\ClassNotExistsException; | ||
| use RonasIT\Support\Exceptions\IncorrectClassPathException; | ||
| use Throwable; | ||
| use ReflectionMethod; | ||
| use ReflectionClass; | ||
|
|
@@ -84,15 +85,21 @@ public function __construct() | |
| $this->paths = config('entity-generator.paths'); | ||
| } | ||
|
|
||
| protected function getOrCreateNamespace(string $path): string | ||
| protected function getOrCreateNamespace(string $configPath): string | ||
| { | ||
| $path = $this->paths[$path]; | ||
| $path = $this->paths[$configPath]; | ||
| $pathParts = explode('/', $path); | ||
|
|
||
| if (Str::endsWith(Arr::last($pathParts), '.php')) { | ||
| array_pop($pathParts); | ||
| } | ||
|
|
||
| foreach ($pathParts as $part) { | ||
| if (!$this->isFolderHasCorrectCase($part, $configPath)) { | ||
| throw new IncorrectClassPathException("Incorrect path to {$configPath}, {$part} folder must start with a capital letter, please specify the path according to the PSR."); | ||
| } | ||
| } | ||
|
|
||
| $namespace = array_map(function (string $part) { | ||
| return ucfirst($part); | ||
| }, $pathParts); | ||
|
|
@@ -106,6 +113,22 @@ protected function getOrCreateNamespace(string $path): string | |
| return implode('\\', $namespace); | ||
| } | ||
|
|
||
| protected function isFolderHasCorrectCase(string $folder, string $configPath): bool | ||
| { | ||
| $lowerCaseDirectoriesMap = [ | ||
| 'migrations' => 'database/migrations', | ||
| 'factories' => 'database/factories', | ||
| 'seeders' => 'database/seeders', | ||
| 'database_seeder' => 'database/seeders', | ||
| 'tests' => 'tests', | ||
| 'routes' => 'routes', | ||
| ]; | ||
|
|
||
| $directory = Arr::get($lowerCaseDirectoriesMap, $configPath); | ||
|
||
|
|
||
| return $folder === 'app' || preg_match('/^[A-Z]/', $folder) || Str::contains($directory, $folder); | ||
DenTray marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| abstract public function generate(): void; | ||
|
|
||
| protected function classExists($path, $name): bool | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.