Mercurial > packages > magicforger
comparison src/Generator/Controller/ControllerGenerator.php @ 21:f0b0d014e448 main-dev
Cleaning up code based on AI overlord review
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Wed, 26 Feb 2025 19:45:08 -0500 |
| parents | 19b7a8de0019 |
| children | ee8ef14e158d |
comparison
equal
deleted
inserted
replaced
| 20:81a76472ba21 | 21:f0b0d014e448 |
|---|---|
| 29 */ | 29 */ |
| 30 protected $type = 'Controller'; | 30 protected $type = 'Controller'; |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Execute the console command. | 33 * Execute the console command. |
| 34 * | |
| 35 * @return void | |
| 34 */ | 36 */ |
| 35 public function handle() | 37 public function handle(): void |
| 36 { | 38 { |
| 37 parent::handle(); | 39 parent::handle(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 /** | 42 /** |
| 41 * Get the stub file for the generator. | 43 * Get the stub file for the generator. |
| 42 * | 44 * |
| 43 * @return string | 45 * @return string |
| 44 */ | 46 */ |
| 45 protected function getStub() | 47 protected function getStub(): string |
| 46 { | 48 { |
| 47 return $this->resolveStubPath('/stubs/controller.stub'); | 49 return $this->resolveStubPath('/stubs/controller.stub'); |
| 48 } | 50 } |
| 49 | 51 |
| 50 /** | 52 /** |
| 51 * Resolve the fully-qualified path to the stub. | 53 * Resolve the fully-qualified path to the stub. |
| 52 * | 54 * |
| 53 * @param string $stub | 55 * @param string $stub |
| 54 * | |
| 55 * @return string | 56 * @return string |
| 56 */ | 57 */ |
| 57 protected function resolveStubPath($stub) | 58 protected function resolveStubPath(string $stub): string |
| 58 { | 59 { |
| 59 return is_file($customPath = $this->laravel->basePath(trim($stub, '/'))) | 60 $customPath = $this->laravel->basePath(trim($stub, '/')); |
| 60 ? $customPath | 61 |
| 61 : __DIR__.$stub; | 62 return is_file($customPath) ? $customPath : __DIR__ . $stub; |
| 62 } | 63 } |
| 63 | 64 |
| 64 protected function getClassName($name) | 65 /** |
| 66 * Get the path for the generated file. | |
| 67 * | |
| 68 * @param string|null $name | |
| 69 * @return string | |
| 70 */ | |
| 71 protected function getPath(?string $name = null): string | |
| 72 { | |
| 73 return str_replace( | |
| 74 ['App\\', '\\'], | |
| 75 ['app/', '/'], | |
| 76 $this->getControllerNamespace() . '/' . $this->controller_name($this->getTableInput()) . '.php' | |
| 77 ); | |
| 78 } | |
| 79 | |
| 80 /** | |
| 81 * Get the class name for the controller. | |
| 82 * | |
| 83 * @param string $name | |
| 84 * @return string | |
| 85 */ | |
| 86 protected function getClassName(string $name): string | |
| 65 { | 87 { |
| 66 return $this->controller_name($name); | 88 return $this->controller_name($name); |
| 67 } | 89 } |
| 68 | |
| 69 /** | |
| 70 * Get the stub file for the generator. | |
| 71 * | |
| 72 * @return string | |
| 73 */ | |
| 74 protected function getPath($name = null) | |
| 75 { | |
| 76 return str_replace(['App\\', '\\'], ['app/', '/'], $this->getControllerNamespace().'/'.$this->controller_name($this->getTableInput()).'.php'); | |
| 77 } | |
| 78 } | 90 } |
