scrnhq /
laravel-bakery
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Bakery\Console; |
||||
| 4 | |||||
| 5 | use Illuminate\Support\Str; |
||||
| 6 | use Illuminate\Console\GeneratorCommand; |
||||
| 7 | use Symfony\Component\Console\Input\InputOption; |
||||
| 8 | |||||
| 9 | class ModelSchemaCommand extends GeneratorCommand |
||||
| 10 | { |
||||
| 11 | /** |
||||
| 12 | * The name and signature of the console command. |
||||
| 13 | * |
||||
| 14 | * @var string |
||||
| 15 | */ |
||||
| 16 | protected $name = 'bakery:modelschema'; |
||||
| 17 | |||||
| 18 | /** |
||||
| 19 | * The console command description. |
||||
| 20 | * |
||||
| 21 | * @var string |
||||
| 22 | */ |
||||
| 23 | protected $description = 'Create a new model schema class'; |
||||
| 24 | |||||
| 25 | /** |
||||
| 26 | * The type of class being generated. |
||||
| 27 | * |
||||
| 28 | * @var string |
||||
| 29 | */ |
||||
| 30 | protected $type = 'ModelSchema'; |
||||
| 31 | |||||
| 32 | /** |
||||
| 33 | * Build the class with the given name. |
||||
| 34 | * |
||||
| 35 | * @param string $name |
||||
| 36 | * @return string |
||||
| 37 | */ |
||||
| 38 | public function buildClass($name) |
||||
| 39 | { |
||||
| 40 | $model = $this->option('model'); |
||||
| 41 | |||||
| 42 | if (is_null($model)) { |
||||
| 43 | $model = $this->rootNamespace().$this->argument('name'); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 44 | } elseif (! Str::startsWith($model, [$this->rootNamespace(), '\\'])) { |
||||
|
0 ignored issues
–
show
It seems like
$model can also be of type string[]; however, parameter $haystack of Illuminate\Support\Str::startsWith() does only seem to accept 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...
|
|||||
| 45 | $model = $this->rootNamespace().$model; |
||||
|
0 ignored issues
–
show
Are you sure
$model of type boolean|string|string[] can be used in concatenation?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 46 | } |
||||
| 47 | |||||
| 48 | return str_replace('DummyFullModel', $model, parent::buildClass($name)); |
||||
| 49 | } |
||||
| 50 | |||||
| 51 | /** |
||||
| 52 | * Get the stub file for the generator. |
||||
| 53 | * |
||||
| 54 | * @return string |
||||
| 55 | */ |
||||
| 56 | protected function getStub() |
||||
| 57 | { |
||||
| 58 | return __DIR__.'/stubs/modelschema.stub'; |
||||
| 59 | } |
||||
| 60 | |||||
| 61 | /** |
||||
| 62 | * Get the default namespace for the class. |
||||
| 63 | * |
||||
| 64 | * @param string $rootNamespace |
||||
| 65 | * @return string |
||||
| 66 | */ |
||||
| 67 | protected function getDefaultNamespace($rootNamespace) |
||||
| 68 | { |
||||
| 69 | return $rootNamespace.'\Bakery'; |
||||
| 70 | } |
||||
| 71 | |||||
| 72 | /** |
||||
| 73 | * Get the console command options. |
||||
| 74 | * |
||||
| 75 | * @return array |
||||
| 76 | */ |
||||
| 77 | protected function getOptions() |
||||
| 78 | { |
||||
| 79 | return [ |
||||
| 80 | ['model', 'm', InputOption::VALUE_REQUIRED, 'The model class being represented.'], |
||||
| 81 | ]; |
||||
| 82 | } |
||||
| 83 | } |
||||
| 84 |