diff --git a/src/Console/FactoryMakeCommand.php b/src/Console/FactoryMakeCommand.php index 9881272..03c6368 100644 --- a/src/Console/FactoryMakeCommand.php +++ b/src/Console/FactoryMakeCommand.php @@ -11,71 +11,31 @@ namespace ATehnix\LaravelStubs\Console; use Illuminate\Database\Console\Factories\FactoryMakeCommand as BaseFactoryMakeCommand; -use Illuminate\Support\Str; class FactoryMakeCommand extends BaseFactoryMakeCommand { use Modulable; /** - * The Laravel application instance. - * - * @var \Illuminate\Foundation\Application - */ - protected $laravel; - - /** - * Build the class with the given name. - * - * @param string $name - * @return string - * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException - */ - protected function buildClass($name) - { - $model = $this->option('model') - ? $this->parseModel($this->option('model')) - : 'Model'; - - $stub = $this->files->get($this->getStub()); - $stub = $this->replaceNamespace($stub, $name)->replaceClass($stub, $name); - - return str_replace( - 'DummyModel', $model, $stub - ); - } - - /** - * Get the fully-qualified model class name. + * Get the stub file for the generator. * - * @param string $model * @return string */ - protected function parseModel($model) + protected function getStub() { - $model = trim(str_replace('/', '\\', $model), '\\'); - - $namespace = - trim($this->laravel->getNamespace(), '\\') - . $this->getModuleNamespace() - . config('stubs.namespaces.model') . '\\'; - - if (!Str::startsWith($model, $namespace)) { - $model = $namespace . $model; - } + $stub = config('stubs.path') . '/factory.stub'; - return $model; + return file_exists($stub) ? $stub : parent::getStub(); } /** - * Get the stub file for the generator. + * Get the default namespace for the class. * + * @param string $rootNamespace * @return string */ - protected function getStub() + protected function getDefaultNamespace($rootNamespace) { - $stub = config('stubs.path') . '/factory.stub'; - - return file_exists($stub) ? $stub : parent::getStub(); + return $rootNamespace . $this->getModuleNamespace() . config('stubs.namespaces.model'); } }