From 4f2146dd9cb1f06f7989b3db999987138926908d Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 14 Sep 2018 19:38:52 +0200 Subject: [PATCH] Replaced commands namespace shortcode by short-code, using the old one as an alias --- .../Shortcode/GeneratePreviewCommand.php | 23 ++--- .../Shortcode/GenerateShortcodeCommand.php | 63 +++++++------- .../Command/Shortcode/GetVisitsCommand.php | 15 ++-- .../Shortcode/ListShortcodesCommand.php | 87 ++++++++++--------- .../Command/Shortcode/ResolveUrlCommand.php | 25 +++--- 5 files changed, 114 insertions(+), 99 deletions(-) diff --git a/module/CLI/src/Command/Shortcode/GeneratePreviewCommand.php b/module/CLI/src/Command/Shortcode/GeneratePreviewCommand.php index 6fa0a487..e777b331 100644 --- a/module/CLI/src/Command/Shortcode/GeneratePreviewCommand.php +++ b/module/CLI/src/Command/Shortcode/GeneratePreviewCommand.php @@ -14,7 +14,8 @@ use Zend\I18n\Translator\TranslatorInterface; class GeneratePreviewCommand extends Command { - const NAME = 'shortcode:process-previews'; + public const NAME = 'short-code:process-previews'; + private const ALIASES = ['shortcode:process-previews']; /** * @var PreviewGeneratorInterface @@ -40,17 +41,19 @@ class GeneratePreviewCommand extends Command parent::__construct(null); } - public function configure() + protected function configure(): void { - $this->setName(self::NAME) - ->setDescription( - $this->translator->translate( - 'Processes and generates the previews for every URL, improving performance for later web requests.' - ) - ); + $this + ->setName(self::NAME) + ->setAliases(self::ALIASES) + ->setDescription( + $this->translator->translate( + 'Processes and generates the previews for every URL, improving performance for later web requests.' + ) + ); } - public function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $page = 1; do { @@ -65,7 +68,7 @@ class GeneratePreviewCommand extends Command (new SymfonyStyle($input, $output))->success($this->translator->translate('Finished processing all URLs')); } - protected function processUrl($url, OutputInterface $output) + private function processUrl($url, OutputInterface $output): void { try { $output->write(\sprintf($this->translator->translate('Processing URL %s...'), $url)); diff --git a/module/CLI/src/Command/Shortcode/GenerateShortcodeCommand.php b/module/CLI/src/Command/Shortcode/GenerateShortcodeCommand.php index 08af7a86..bc0dc685 100644 --- a/module/CLI/src/Command/Shortcode/GenerateShortcodeCommand.php +++ b/module/CLI/src/Command/Shortcode/GenerateShortcodeCommand.php @@ -20,7 +20,8 @@ class GenerateShortcodeCommand extends Command { use ShortUrlBuilderTrait; - public const NAME = 'shortcode:generate'; + public const NAME = 'short-code:generate'; + private const ALIASES = ['shortcode:generate']; /** * @var UrlShortenerInterface @@ -46,36 +47,38 @@ class GenerateShortcodeCommand extends Command parent::__construct(null); } - public function configure() + protected function configure(): void { - $this->setName(self::NAME) - ->setDescription( - $this->translator->translate('Generates a short code for provided URL and returns the short URL') - ) - ->addArgument('longUrl', InputArgument::REQUIRED, $this->translator->translate('The long URL to parse')) - ->addOption( - 'tags', - 't', - InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, - $this->translator->translate('Tags to apply to the new short URL') - ) - ->addOption('validSince', 's', InputOption::VALUE_REQUIRED, $this->translator->translate( - 'The date from which this short URL will be valid. ' - . 'If someone tries to access it before this date, it will not be found.' - )) - ->addOption('validUntil', 'u', InputOption::VALUE_REQUIRED, $this->translator->translate( - 'The date until which this short URL will be valid. ' - . 'If someone tries to access it after this date, it will not be found.' - )) - ->addOption('customSlug', 'c', InputOption::VALUE_REQUIRED, $this->translator->translate( - 'If provided, this slug will be used instead of generating a short code' - )) - ->addOption('maxVisits', 'm', InputOption::VALUE_REQUIRED, $this->translator->translate( - 'This will limit the number of visits for this short URL.' - )); + $this + ->setName(self::NAME) + ->setAliases(self::ALIASES) + ->setDescription( + $this->translator->translate('Generates a short code for provided URL and returns the short URL') + ) + ->addArgument('longUrl', InputArgument::REQUIRED, $this->translator->translate('The long URL to parse')) + ->addOption( + 'tags', + 't', + InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, + $this->translator->translate('Tags to apply to the new short URL') + ) + ->addOption('validSince', 's', InputOption::VALUE_REQUIRED, $this->translator->translate( + 'The date from which this short URL will be valid. ' + . 'If someone tries to access it before this date, it will not be found.' + )) + ->addOption('validUntil', 'u', InputOption::VALUE_REQUIRED, $this->translator->translate( + 'The date until which this short URL will be valid. ' + . 'If someone tries to access it after this date, it will not be found.' + )) + ->addOption('customSlug', 'c', InputOption::VALUE_REQUIRED, $this->translator->translate( + 'If provided, this slug will be used instead of generating a short code' + )) + ->addOption('maxVisits', 'm', InputOption::VALUE_REQUIRED, $this->translator->translate( + 'This will limit the number of visits for this short URL.' + )); } - public function interact(InputInterface $input, OutputInterface $output) + protected function interact(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); $longUrl = $input->getArgument('longUrl'); @@ -91,7 +94,7 @@ class GenerateShortcodeCommand extends Command } } - public function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); $longUrl = $input->getArgument('longUrl'); @@ -140,7 +143,7 @@ class GenerateShortcodeCommand extends Command } } - private function getOptionalDate(InputInterface $input, string $fieldName) + private function getOptionalDate(InputInterface $input, string $fieldName): ?\DateTime { $since = $input->getOption($fieldName); return $since !== null ? new \DateTime($since) : null; diff --git a/module/CLI/src/Command/Shortcode/GetVisitsCommand.php b/module/CLI/src/Command/Shortcode/GetVisitsCommand.php index 27cf198d..b27b6962 100644 --- a/module/CLI/src/Command/Shortcode/GetVisitsCommand.php +++ b/module/CLI/src/Command/Shortcode/GetVisitsCommand.php @@ -15,7 +15,8 @@ use Zend\I18n\Translator\TranslatorInterface; class GetVisitsCommand extends Command { - const NAME = 'shortcode:visits'; + public const NAME = 'short-code:visits'; + private const ALIASES = ['shortcode:visits']; /** * @var VisitsTrackerInterface @@ -33,9 +34,11 @@ class GetVisitsCommand extends Command parent::__construct(); } - public function configure() + protected function configure(): void { - $this->setName(self::NAME) + $this + ->setName(self::NAME) + ->setAliases(self::ALIASES) ->setDescription( $this->translator->translate('Returns the detailed visits information for provided short code') ) @@ -58,7 +61,7 @@ class GetVisitsCommand extends Command ); } - public function interact(InputInterface $input, OutputInterface $output) + protected function interact(InputInterface $input, OutputInterface $output): void { $shortCode = $input->getArgument('shortCode'); if (! empty($shortCode)) { @@ -74,7 +77,7 @@ class GetVisitsCommand extends Command } } - public function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); $shortCode = $input->getArgument('shortCode'); @@ -101,7 +104,7 @@ class GetVisitsCommand extends Command ], $rows); } - protected function getDateOption(InputInterface $input, $key) + private function getDateOption(InputInterface $input, $key) { $value = $input->getOption($key); if (! empty($value)) { diff --git a/module/CLI/src/Command/Shortcode/ListShortcodesCommand.php b/module/CLI/src/Command/Shortcode/ListShortcodesCommand.php index 85caf840..fd9b0c8d 100644 --- a/module/CLI/src/Command/Shortcode/ListShortcodesCommand.php +++ b/module/CLI/src/Command/Shortcode/ListShortcodesCommand.php @@ -18,7 +18,8 @@ class ListShortcodesCommand extends Command { use PaginatorUtilsTrait; - const NAME = 'shortcode:list'; + public const NAME = 'short-code:list'; + private const ALIASES = ['shortcode:list']; /** * @var ShortUrlServiceInterface @@ -46,49 +47,51 @@ class ListShortcodesCommand extends Command protected function configure(): void { - $this->setName(self::NAME) - ->setDescription($this->translator->translate('List all short URLs')) - ->addOption( - 'page', - 'p', - InputOption::VALUE_OPTIONAL, - sprintf( - $this->translator->translate('The first page to list (%s items per page)'), - PaginableRepositoryAdapter::ITEMS_PER_PAGE - ), - 1 - ) - ->addOption( - 'searchTerm', - 's', - InputOption::VALUE_OPTIONAL, - $this->translator->translate( - 'A query used to filter results by searching for it on the longUrl and shortCode fields' - ) - ) - ->addOption( - 'tags', - 't', - InputOption::VALUE_OPTIONAL, - $this->translator->translate('A comma-separated list of tags to filter results') - ) - ->addOption( - 'orderBy', - 'o', - InputOption::VALUE_OPTIONAL, - $this->translator->translate( - 'The field from which we want to order by. Pass ASC or DESC separated by a comma' - ) - ) - ->addOption( - 'showTags', - null, - InputOption::VALUE_NONE, - $this->translator->translate('Whether to display the tags or not') - ); + $this + ->setName(self::NAME) + ->setAliases(self::ALIASES) + ->setDescription($this->translator->translate('List all short URLs')) + ->addOption( + 'page', + 'p', + InputOption::VALUE_OPTIONAL, + sprintf( + $this->translator->translate('The first page to list (%s items per page)'), + PaginableRepositoryAdapter::ITEMS_PER_PAGE + ), + 1 + ) + ->addOption( + 'searchTerm', + 's', + InputOption::VALUE_OPTIONAL, + $this->translator->translate( + 'A query used to filter results by searching for it on the longUrl and shortCode fields' + ) + ) + ->addOption( + 'tags', + 't', + InputOption::VALUE_OPTIONAL, + $this->translator->translate('A comma-separated list of tags to filter results') + ) + ->addOption( + 'orderBy', + 'o', + InputOption::VALUE_OPTIONAL, + $this->translator->translate( + 'The field from which we want to order by. Pass ASC or DESC separated by a comma' + ) + ) + ->addOption( + 'showTags', + null, + InputOption::VALUE_NONE, + $this->translator->translate('Whether to display the tags or not') + ); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); $page = (int) $input->getOption('page'); diff --git a/module/CLI/src/Command/Shortcode/ResolveUrlCommand.php b/module/CLI/src/Command/Shortcode/ResolveUrlCommand.php index 2bd87a89..b4a8394f 100644 --- a/module/CLI/src/Command/Shortcode/ResolveUrlCommand.php +++ b/module/CLI/src/Command/Shortcode/ResolveUrlCommand.php @@ -15,7 +15,8 @@ use Zend\I18n\Translator\TranslatorInterface; class ResolveUrlCommand extends Command { - const NAME = 'shortcode:parse'; + public const NAME = 'short-code:parse'; + private const ALIASES = ['shortcode:parse']; /** * @var UrlShortenerInterface @@ -33,18 +34,20 @@ class ResolveUrlCommand extends Command parent::__construct(null); } - public function configure() + protected function configure(): void { - $this->setName(self::NAME) - ->setDescription($this->translator->translate('Returns the long URL behind a short code')) - ->addArgument( - 'shortCode', - InputArgument::REQUIRED, - $this->translator->translate('The short code to parse') - ); + $this + ->setName(self::NAME) + ->setAliases(self::ALIASES) + ->setDescription($this->translator->translate('Returns the long URL behind a short code')) + ->addArgument( + 'shortCode', + InputArgument::REQUIRED, + $this->translator->translate('The short code to parse') + ); } - public function interact(InputInterface $input, OutputInterface $output) + protected function interact(InputInterface $input, OutputInterface $output): void { $shortCode = $input->getArgument('shortCode'); if (! empty($shortCode)) { @@ -60,7 +63,7 @@ class ResolveUrlCommand extends Command } } - public function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); $shortCode = $input->getArgument('shortCode');