protected function execute(InputInterface $input, OutputInterface $output) { try { $userId = new UserId($input->getArgument('id')); $newEmail = new EmailAddress($input->getArgument('email')); $command = new ChangeUserEmail($userId, $newEmail); $this->getCommandBus()->handle($command); } catch (\Exception $e) { if ($e instanceof UserNotFoundException || $e instanceof InvalidEmailAddressException || $e instanceof InvalidValueForUserIdException) { $output->writeln($e->getMessage()); return 1; } } $output->writeln(sprintf('Change email command for user %d executed successfully.', $userId->id())); return 0; }