diff --git a/composer.json b/composer.json index eac0afc..493e7b5 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "require": { "php": "^8.0.0", "rareloop/lumberjack-core": "^5.0.1||^6.0.0", - "symfony/console": "^4.1", + "symfony/console": "^5.0 || ^6.0 || ^7.0", "icanboogie/inflector": "^2.0", "statamic/stringy": "^3.1.1" }, @@ -26,4 +26,4 @@ "Rareloop\\Hatchet\\Test\\": "tests" } } -} \ No newline at end of file +} diff --git a/src/Commands/Command.php b/src/Commands/Command.php index 4360f3e..db58e92 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -23,10 +23,6 @@ public function __construct(Application $app) } else { parent::__construct($this->name); } - - if (isset($this->description)) { - $this->setDescription($this->description); - } } protected function configureFromSignature() diff --git a/src/Commands/ControllerMake.php b/src/Commands/ControllerMake.php index d58ec6e..0e5ca82 100644 --- a/src/Commands/ControllerMake.php +++ b/src/Commands/ControllerMake.php @@ -12,7 +12,7 @@ class ControllerMake extends MakeFromStubCommand protected $description = 'Create a Controller'; - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $name = $input->getArgument('name'); @@ -20,5 +20,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $stub = str_replace('DummyController', $name, $stub); $this->createFile('app/Http/Controllers/'.$name.'.php', $stub); + return self::SUCCESS; } } diff --git a/src/Commands/ExceptionMake.php b/src/Commands/ExceptionMake.php index 0bc4e4e..986c375 100644 --- a/src/Commands/ExceptionMake.php +++ b/src/Commands/ExceptionMake.php @@ -3,16 +3,17 @@ namespace Rareloop\Hatchet\Commands; use Rareloop\Hatchet\Commands\MakeFromStubCommand; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'make:exception {name : The class name of the Exception}', + description: 'Create a Exception' +)] class ExceptionMake extends MakeFromStubCommand { - protected $signature = 'make:exception {name : The class name of the Exception}'; - - protected $description = 'Create a Exception'; - - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $name = $input->getArgument('name'); diff --git a/src/Commands/PostTypeMake.php b/src/Commands/PostTypeMake.php index 5db8ad2..e2b95c0 100644 --- a/src/Commands/PostTypeMake.php +++ b/src/Commands/PostTypeMake.php @@ -4,6 +4,7 @@ use ICanBoogie\Inflector; use Rareloop\Hatchet\Commands\MakeFromStubCommand; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -12,13 +13,13 @@ use Symfony\Component\Console\Question\Question; use function Stringy\create as s; +#[AsCommand( + name: 'make:posttype {name : The class name of the PostType (singular)}', + description: 'Create a PostType' +)] class PostTypeMake extends MakeFromStubCommand { - protected $signature = 'make:posttype {name : The class name of the PostType (singular)}'; - - protected $description = 'Create a PostType'; - - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $singular = $input->getArgument('name'); $plural = Inflector::get('en')->pluralize($singular); diff --git a/src/Commands/RouteList.php b/src/Commands/RouteList.php index 4272d70..63d0948 100644 --- a/src/Commands/RouteList.php +++ b/src/Commands/RouteList.php @@ -4,17 +4,19 @@ use Rareloop\Hatchet\Commands\Command; use Rareloop\Router\Router; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'route:list', + description: 'List all registered routes' +)] class RouteList extends Command { - protected $signature = 'route:list'; - protected $description = 'List all registered routes'; - - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $router = $this->app->get(Router::class); diff --git a/src/Commands/ServiceProviderMake.php b/src/Commands/ServiceProviderMake.php index 9076bee..3ddd1b2 100644 --- a/src/Commands/ServiceProviderMake.php +++ b/src/Commands/ServiceProviderMake.php @@ -3,16 +3,17 @@ namespace Rareloop\Hatchet\Commands; use Rareloop\Hatchet\Commands\MakeFromStubCommand; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'make:provider {name : The class name of the ServiceProvider}', + description: 'Create a ServiceProvider', +)] class ServiceProviderMake extends MakeFromStubCommand { - protected $signature = 'make:provider {name : The class name of the ServiceProvider}'; - - protected $description = 'Create a ServiceProvider'; - - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $name = $input->getArgument('name'); diff --git a/src/Commands/ViewModelMake.php b/src/Commands/ViewModelMake.php index 7e73a21..e0fde4a 100644 --- a/src/Commands/ViewModelMake.php +++ b/src/Commands/ViewModelMake.php @@ -3,16 +3,17 @@ namespace Rareloop\Hatchet\Commands; use Rareloop\Hatchet\Commands\MakeFromStubCommand; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'make:viewmodel {name : The class name of the View Model}', + description: 'Create a ViewModel', +)] class ViewModelMake extends MakeFromStubCommand { - protected $signature = 'make:viewmodel {name : The class name of the View Model}'; - - protected $description = 'Create a ViewModel'; - - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $name = $input->getArgument('name'); diff --git a/tests/Unit/CommandTest.php b/tests/Unit/CommandTest.php index c381248..127c36d 100644 --- a/tests/Unit/CommandTest.php +++ b/tests/Unit/CommandTest.php @@ -12,7 +12,7 @@ class CommandTest extends TestCase { - use \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; + use MockeryPHPUnitIntegration; /** @test */ public function can_create_a_command_with_a_name() @@ -55,9 +55,10 @@ class CommandWithSignature extends Command protected $signature = 'test:command {name} {--option}'; } +#[AsCommand( + name: 'test:command', + description: 'testing123' +)] class CommandWithDescription extends Command { - protected $name = 'test:command'; - - protected $description = 'testing123'; } diff --git a/tests/Unit/HatchetTest.php b/tests/Unit/HatchetTest.php index 72794b9..809719d 100644 --- a/tests/Unit/HatchetTest.php +++ b/tests/Unit/HatchetTest.php @@ -83,5 +83,7 @@ protected function configure() $this->setName('test:command'); } - protected function execute(InputInterface $input, OutputInterface $output) {} + protected function execute(InputInterface $input, OutputInterface $output): int { + return false; + } } diff --git a/tests/Unit/RegisterCommandsTest.php b/tests/Unit/RegisterCommandsTest.php index 39cf774..1df3e15 100644 --- a/tests/Unit/RegisterCommandsTest.php +++ b/tests/Unit/RegisterCommandsTest.php @@ -44,5 +44,5 @@ protected function configure() $this->setName('test:command'); } - protected function execute(InputInterface $input, OutputInterface $output) {} + protected function execute(InputInterface $input, OutputInterface $output): int {} }