Skip to content

Commit

Permalink
makes Bus generic in Commands classes
Browse files Browse the repository at this point in the history
  • Loading branch information
overclokk committed May 31, 2024
1 parent 383c46f commit e80b048
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/Application/Commands/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class InfoCommand extends Command

public const NAME = 'info';

private \ItalyStrap\Bus\Bus $bus;
private \ItalyStrap\Bus\HandlerInterface $handler;

public function __construct(
\ItalyStrap\Bus\Bus $bus
\ItalyStrap\Bus\HandlerInterface $handler
) {
$this->bus = $bus;
$this->handler = $handler;
parent::__construct();
}

Expand All @@ -41,7 +41,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$message = new InfoMessage($rootFolder);

try {
return (int)$this->bus->handle($message);
return (int)$this->handler->handle($message);
} catch (\Exception $exception) {
$output->writeln('<error>Error: ' . $exception->getMessage() . '</error>');
return Command::FAILURE;
Expand Down
8 changes: 4 additions & 4 deletions src/Application/Commands/ValidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class ValidateCommand extends Command

private \Symfony\Component\EventDispatcher\EventDispatcher $subscriber;

private \ItalyStrap\Bus\Bus $bus;
private \ItalyStrap\Bus\HandlerInterface $handler;

public function __construct(
\Symfony\Component\EventDispatcher\EventDispatcher $subscriber,
\ItalyStrap\Bus\Bus $bus
\ItalyStrap\Bus\HandlerInterface $handler
) {
$this->subscriber = $subscriber;
$this->bus = $bus;
$this->handler = $handler;
parent::__construct();
}

Expand Down Expand Up @@ -100,7 +100,7 @@ static function (ValidatedFails $event) use ($output): void {
$message = new ValidateMessage($rootFolder, $schemaPath, (bool)$input->getOption('force'));

try {
return (int)$this->bus->handle($message);
return (int)$this->handler->handle($message);
} catch (\Exception $exception) {
$output->writeln('<error>Error: ' . $exception->getMessage() . '</error>');
return Command::FAILURE;
Expand Down
4 changes: 2 additions & 2 deletions src/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function run(): int
$application->add($injector->make(DumpCommand::class));
/** @psalm-suppress InvalidArgument */
$application->add($injector->make(ValidateCommand::class, [
'+bus' => static function (string $named_param, Injector $injector): Bus {
'+handler' => static function (string $named_param, Injector $injector): Bus {
$bus = new Bus(
$injector->make(Validate::class)
);
Expand All @@ -62,7 +62,7 @@ public function run(): int
},
]));
$application->add($injector->make(InfoCommand::class, [
'+bus' => static fn(string $named_param, Injector $injector): Bus => new Bus(
'+handler' => static fn(string $named_param, Injector $injector): Bus => new Bus(
$injector->make(Info::class)
),
]));
Expand Down

0 comments on commit e80b048

Please sign in to comment.