Mahmoud-Italy /
Larafast-fastApi
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Larafast\Fastapi\Console\Commands; |
||||
| 4 | |||||
| 5 | use Illuminate\Support\Str; |
||||
| 6 | use Larafast\Fastapi\Console\Contracts\GeneratorCommand; |
||||
| 7 | use Symfony\Component\Console\Input\InputOption; |
||||
| 8 | |||||
| 9 | class RequestMakeCommand extends GeneratorCommand |
||||
| 10 | { |
||||
| 11 | /** |
||||
| 12 | * The console command name. |
||||
| 13 | * |
||||
| 14 | * @var string |
||||
| 15 | */ |
||||
| 16 | protected $name = 'fastApi:request'; |
||||
| 17 | |||||
| 18 | /** |
||||
| 19 | * The console command description. |
||||
| 20 | * |
||||
| 21 | * @var string |
||||
| 22 | */ |
||||
| 23 | protected $description = 'Create a new form request class'; |
||||
| 24 | |||||
| 25 | /** |
||||
| 26 | * The type of class being generated. |
||||
| 27 | * |
||||
| 28 | * @var string |
||||
| 29 | */ |
||||
| 30 | protected $type = 'Request'; |
||||
| 31 | |||||
| 32 | /** |
||||
| 33 | * Get the stub file for the generator. |
||||
| 34 | * |
||||
| 35 | * @return string |
||||
| 36 | */ |
||||
| 37 | protected function getStub() |
||||
| 38 | { |
||||
| 39 | if (!$this->option('type') || $this->option('type') == 'store') { |
||||
| 40 | return config('fastApi.stubs_dir') . '/request.stub'; |
||||
| 41 | } |
||||
| 42 | |||||
| 43 | return config('fastApi.stubs_dir') . '/request.update.stub'; |
||||
| 44 | } |
||||
| 45 | |||||
| 46 | protected function buildClass($name) |
||||
| 47 | { |
||||
| 48 | $replace = []; |
||||
| 49 | if ($model = $this->option('model')) { |
||||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||||
| 50 | $model = Str::studly(class_basename($this->option('model'))); |
||||
|
0 ignored issues
–
show
It seems like
$this->option('model') can also be of type string[]; however, parameter $class of class_basename() does only seem to accept object|string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 51 | $slug = Str::slug(str_to_words($model), '_'); |
||||
| 52 | $replace['$modelSlug$'] = $slug; |
||||
| 53 | $replace['$modelTable$'] = Str::plural($slug, 2); |
||||
| 54 | } |
||||
| 55 | |||||
| 56 | return str_replace( |
||||
| 57 | array_keys($replace), array_values($replace), parent::buildClass($name) |
||||
| 58 | ); |
||||
| 59 | } |
||||
| 60 | |||||
| 61 | /** |
||||
| 62 | * Get the default namespace for the class. |
||||
| 63 | * |
||||
| 64 | * @param string $rootNamespace |
||||
| 65 | * |
||||
| 66 | * @return string |
||||
| 67 | */ |
||||
| 68 | protected function getDefaultNamespace($rootNamespace) |
||||
| 69 | { |
||||
| 70 | return $rootNamespace . '\Http\Requests'; |
||||
| 71 | } |
||||
| 72 | |||||
| 73 | /** |
||||
| 74 | * Get the console command options. |
||||
| 75 | * |
||||
| 76 | * @return array |
||||
| 77 | */ |
||||
| 78 | protected function getOptions() |
||||
| 79 | { |
||||
| 80 | return [ |
||||
| 81 | ['model', 'm', InputOption::VALUE_REQUIRED, 'The given model.'], |
||||
| 82 | ['type', 't', InputOption::VALUE_OPTIONAL, 'Type of request. Values can be store or update'], |
||||
| 83 | ]; |
||||
| 84 | } |
||||
| 85 | } |
||||
| 86 |