urlShortener = $urlShortener; } protected function configure(): void { $this ->setName(self::NAME) ->setAliases(self::ALIASES) ->setDescription('Returns the long URL behind a short code') ->addArgument('shortCode', InputArgument::REQUIRED, 'The short code to parse'); } protected function interact(InputInterface $input, OutputInterface $output): void { $shortCode = $input->getArgument('shortCode'); if (! empty($shortCode)) { return; } $io = new SymfonyStyle($input, $output); $shortCode = $io->ask('A short code was not provided. Which short code do you want to parse?'); if (! empty($shortCode)) { $input->setArgument('shortCode', $shortCode); } } protected function execute(InputInterface $input, OutputInterface $output): ?int { $io = new SymfonyStyle($input, $output); $shortCode = $input->getArgument('shortCode'); try { $url = $this->urlShortener->shortCodeToUrl($shortCode); $output->writeln(sprintf('Long URL: %s', $url->getLongUrl())); return ExitCodes::EXIT_SUCCESS; } catch (InvalidShortCodeException $e) { $io->error(sprintf('Provided short code "%s" has an invalid format.', $shortCode)); return ExitCodes::EXIT_FAILURE; } catch (EntityDoesNotExistException $e) { $io->error(sprintf('Provided short code "%s" could not be found.', $shortCode)); return ExitCodes::EXIT_FAILURE; } } }