| 1 | <?php |
||
| 2 | |||
| 3 | namespace Telkins\Validation\Console\Commands; |
||
| 4 | |||
| 5 | use Illuminate\Support\Str; |
||
| 6 | use Illuminate\Console\GeneratorCommand; |
||
| 7 | use Symfony\Component\Console\Input\InputOption; |
||
| 8 | |||
| 9 | abstract class AbstractMakeRuleSet extends GeneratorCommand |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * The console command name. |
||
| 13 | * |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | protected $name; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * The console command description. |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $description; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * The type of class being generated. |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $type; |
||
| 31 | |||
| 32 | protected $stub; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Get the stub file for the generator. |
||
| 36 | * |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | protected function getStub() |
||
| 40 | { |
||
| 41 | return $this->stub; |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Get the default namespace for the class. |
||
| 46 | * |
||
| 47 | * @param string $rootNamespace |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | protected function getDefaultNamespace($rootNamespace) |
||
| 51 | { |
||
| 52 | if ($this->isCustomNamespace()) { |
||
| 53 | return $rootNamespace; |
||
| 54 | } |
||
| 55 | |||
| 56 | return "$rootNamespace\\Rules\\{$this->type}s"; |
||
| 57 | } |
||
| 58 | |||
| 59 | protected function getOptions() |
||
| 60 | { |
||
| 61 | return [ |
||
| 62 | ['force', null, InputOption::VALUE_NONE, 'Create the class even if the rule set already exists'], |
||
| 63 | ]; |
||
| 64 | } |
||
| 65 | |||
| 66 | protected function isCustomNamespace(): bool |
||
| 67 | { |
||
| 68 | return Str::contains($this->argument('name'), '/'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 69 | } |
||
| 70 | } |
||
| 71 |