diff --git a/composer.json b/composer.json index f857860..cff6e9a 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,14 @@ "test-coverage": "vendor/bin/pest --coverage" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin-laravel": true, + "pestphp/pest-plugin": true, + "phpstan/extension-installer": true, + "phpstan/phpstan-deprecation-rules": true, + "phpstan/phpstan-phpunit": true + } }, "extra": { "laravel": { diff --git a/src/Console/MakePresenterCommand.php b/src/Console/MakePresenterCommand.php new file mode 100644 index 0000000..fe1211c --- /dev/null +++ b/src/Console/MakePresenterCommand.php @@ -0,0 +1,69 @@ +files->exists($this->getPath($this->qualifyClass($rawName))); + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getStub() + { + return $this->resolveStubPath('/stubs/presenter.stub'); + } + + /** + * Resolve the fully-qualified path to the stub. + * + * @param string $stub + * @return string + */ + protected function resolveStubPath($stub) + { + return file_exists($customPath = $this->laravel->basePath(trim($stub, '/'))) + ? $customPath + : __DIR__ . $stub; + } + + /** + * Get the default namespace for the class. + * + * @param string $rootNamespace + * @return string + */ + protected function getDefaultNamespace($rootNamespace) + { + $configNamespace = config('laravel-presenter.presenter_namespace'); + + return is_null($configNamespace) + ? $rootNamespace . '\Presenters' + : $configNamespace; + } +} diff --git a/src/Console/PresenterMakeCommand.php b/src/Console/PresenterMakeCommand.php index df0ad88..0ce722a 100644 --- a/src/Console/PresenterMakeCommand.php +++ b/src/Console/PresenterMakeCommand.php @@ -4,66 +4,13 @@ use Illuminate\Console\GeneratorCommand; -class PresenterMakeCommand extends GeneratorCommand +class PresenterMakeCommand extends MakePresenterCommand { public $name = 'presenter:make'; - - public $description = 'create a new presenter class'; - - /** - * The type of class being generated. - * - * @var string - */ - protected $type = 'Presenter'; - - /** - * Determine if the class already exists. - * - * @param string $rawName - * @return bool - */ - protected function alreadyExists($rawName) + + protected function configure() { - return class_exists($rawName) || - $this->files->exists($this->getPath($this->qualifyClass($rawName))); - } - - /** - * Get the stub file for the generator. - * - * @return string - */ - protected function getStub() - { - return $this->resolveStubPath('/stubs/presenter.stub'); - } - - /** - * Resolve the fully-qualified path to the stub. - * - * @param string $stub - * @return string - */ - protected function resolveStubPath($stub) - { - return file_exists($customPath = $this->laravel->basePath(trim($stub, '/'))) - ? $customPath - : __DIR__ . $stub; - } - - /** - * Get the default namespace for the class. - * - * @param string $rootNamespace - * @return string - */ - protected function getDefaultNamespace($rootNamespace) - { - $configNamespace = config('laravel-presenter.presenter_namespace'); - - return is_null($configNamespace) - ? $rootNamespace . '\Presenters' - : $configNamespace; + $this->setHidden(true); } + } diff --git a/src/LaravelPresenterServiceProvider.php b/src/LaravelPresenterServiceProvider.php index e9582a4..91efd84 100644 --- a/src/LaravelPresenterServiceProvider.php +++ b/src/LaravelPresenterServiceProvider.php @@ -2,7 +2,10 @@ namespace Coderflex\LaravelPresenter; -use Coderflex\LaravelPresenter\Console\PresenterMakeCommand; +use Coderflex\LaravelPresenter\Console\{ + PresenterMakeCommand, + MakePresenterCommand +}; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -18,6 +21,7 @@ public function configurePackage(Package $package): void $package ->name('laravel-presenter') ->hasConfigFile('laravel-presenter') + ->hasCommand(MakePresenterCommand::class) ->hasCommand(PresenterMakeCommand::class); } } diff --git a/tests/PresentersTest.php b/tests/PresentersTest.php index ef60cec..61c82b2 100644 --- a/tests/PresentersTest.php +++ b/tests/PresentersTest.php @@ -16,6 +16,12 @@ ->assertExitCode(0); })->group('Presenter Command'); + +it('can create new presenter class with the alias command', function () { + $this->artisan('make:presenter UserPresenter') + ->assertExitCode(0); +})->group('Presenter Command'); + it('presents user full name', function () { $user = new User([ 'first_name' => 'John',