diff --git a/README.md b/README.md index 1c85d84..cd23e50 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,9 @@ for [PhpStorm](https://www.jetbrains.com/phpstorm/): # This will create a `app/Feeds/UserFeed.php` file php artisan make:feed User +# This will create a `app/Feeds/UserFeed.php` and `app/Feeds/Items/UserFeedItem.php` files +php artisan make:feed User --with-item + # This will create a `app/Feeds/Items/UserFeedItem.php` file php artisan make:feed-item User ``` diff --git a/src/Console/Commands/FeedItemMakeCommand.php b/src/Console/Commands/FeedItemMakeCommand.php index 366da94..d15746b 100644 --- a/src/Console/Commands/FeedItemMakeCommand.php +++ b/src/Console/Commands/FeedItemMakeCommand.php @@ -9,8 +9,6 @@ use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputOption; -use function str_replace; - #[AsCommand('make:feed-item', 'Create a new feed item')] class FeedItemMakeCommand extends GeneratorCommand { @@ -18,15 +16,6 @@ class FeedItemMakeCommand extends GeneratorCommand protected $type = 'FeedItem'; - protected function buildClass($name): string - { - return str_replace( - ['DummyUser'], - $this->userProviderModel(), - parent::buildClass($name) - ); - } - protected function getStub(): string { return __DIR__ . '/../../../stubs/feed_item.stub'; diff --git a/src/Console/Commands/FeedMakeCommand.php b/src/Console/Commands/FeedMakeCommand.php index 7c8cd48..e6f9921 100644 --- a/src/Console/Commands/FeedMakeCommand.php +++ b/src/Console/Commands/FeedMakeCommand.php @@ -16,6 +16,26 @@ class FeedMakeCommand extends GeneratorCommand protected $type = 'Feed'; + public function handle(): void + { + parent::handle(); + + if ($this->option('with-item')) { + $this->makeFeedItem( + $this->argument('name'), + (bool) $this->option('force') + ); + } + } + + protected function makeFeedItem(string $name, bool $force): void + { + $this->call(FeedItemMakeCommand::class, [ + 'name' => $name, + '--force' => $force, + ]); + } + protected function getStub(): string { return __DIR__ . '/../../../stubs/feed.stub'; @@ -29,6 +49,7 @@ protected function getDefaultNamespace($rootNamespace): string protected function getOptions(): array { return [ + ['with-item', 'wi', InputOption::VALUE_NONE, 'Create the class with feed item'], ['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the feed already exists'], ]; } diff --git a/tests/.pest/snapshots/Unit/Console/MakeTest/make_with_item.snap b/tests/.pest/snapshots/Unit/Console/MakeTest/make_with_item.snap new file mode 100644 index 0000000..3856e2e --- /dev/null +++ b/tests/.pest/snapshots/Unit/Console/MakeTest/make_with_item.snap @@ -0,0 +1,34 @@ + [ + 'id' => $this->model->id, + + 'updated_at' => $this->model->updated_at->toDateTimeString(), + + 'verified' => ! empty($this->model->email_verified_at), + ], + + 'name' => [ + '@cdata' => '