setName(self::NAME) ->setDescription('Returns the detailed visits information for provided short code') ->addArgument('shortCode', InputArgument::REQUIRED, 'The short code which visits we want to get.') ->addOption('domain', 'd', InputOption::VALUE_REQUIRED, 'The domain for the short code.'); } protected function getStartDateDesc(string $optionName): string { return sprintf('Allows to filter visits, returning only those older than "%s".', $optionName); } protected function getEndDateDesc(string $optionName): string { return sprintf('Allows to filter visits, returning only those newer than "%s".', $optionName); } 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 use?'); if (! empty($shortCode)) { $input->setArgument('shortCode', $shortCode); } } protected function execute(InputInterface $input, OutputInterface $output): ?int { $identifier = ShortUrlIdentifier::fromCli($input); $startDate = $this->getStartDateOption($input, $output); $endDate = $this->getEndDateOption($input, $output); $paginator = $this->visitsHelper->visitsForShortUrl( $identifier, new VisitsParams(buildDateRange($startDate, $endDate)), ); $rows = map($paginator->getCurrentPageResults(), function (Visit $visit) { $rowData = $visit->jsonSerialize(); $rowData['country'] = ($visit->getVisitLocation() ?? new UnknownVisitLocation())->getCountryName(); return select_keys($rowData, ['referer', 'date', 'userAgent', 'country']); }); ShlinkTable::default($output)->render(['Referer', 'Date', 'User agent', 'Country'], $rows); return ExitCodes::EXIT_SUCCESS; } }