Replaced commands namespace shortcode by short-code, using the old one as an alias

This commit is contained in:
Alejandro Celaya 2018-09-14 19:38:52 +02:00
parent 5b9784cd9e
commit 4f2146dd9c
5 changed files with 114 additions and 99 deletions

View file

@ -14,7 +14,8 @@ use Zend\I18n\Translator\TranslatorInterface;
class GeneratePreviewCommand extends Command class GeneratePreviewCommand extends Command
{ {
const NAME = 'shortcode:process-previews'; public const NAME = 'short-code:process-previews';
private const ALIASES = ['shortcode:process-previews'];
/** /**
* @var PreviewGeneratorInterface * @var PreviewGeneratorInterface
@ -40,9 +41,11 @@ class GeneratePreviewCommand extends Command
parent::__construct(null); parent::__construct(null);
} }
public function configure() protected function configure(): void
{ {
$this->setName(self::NAME) $this
->setName(self::NAME)
->setAliases(self::ALIASES)
->setDescription( ->setDescription(
$this->translator->translate( $this->translator->translate(
'Processes and generates the previews for every URL, improving performance for later web requests.' 'Processes and generates the previews for every URL, improving performance for later web requests.'
@ -50,7 +53,7 @@ class GeneratePreviewCommand extends Command
); );
} }
public function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output): void
{ {
$page = 1; $page = 1;
do { do {
@ -65,7 +68,7 @@ class GeneratePreviewCommand extends Command
(new SymfonyStyle($input, $output))->success($this->translator->translate('Finished processing all URLs')); (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 { try {
$output->write(\sprintf($this->translator->translate('Processing URL %s...'), $url)); $output->write(\sprintf($this->translator->translate('Processing URL %s...'), $url));

View file

@ -20,7 +20,8 @@ class GenerateShortcodeCommand extends Command
{ {
use ShortUrlBuilderTrait; use ShortUrlBuilderTrait;
public const NAME = 'shortcode:generate'; public const NAME = 'short-code:generate';
private const ALIASES = ['shortcode:generate'];
/** /**
* @var UrlShortenerInterface * @var UrlShortenerInterface
@ -46,9 +47,11 @@ class GenerateShortcodeCommand extends Command
parent::__construct(null); parent::__construct(null);
} }
public function configure() protected function configure(): void
{ {
$this->setName(self::NAME) $this
->setName(self::NAME)
->setAliases(self::ALIASES)
->setDescription( ->setDescription(
$this->translator->translate('Generates a short code for provided URL and returns the short URL') $this->translator->translate('Generates a short code for provided URL and returns the short URL')
) )
@ -75,7 +78,7 @@ class GenerateShortcodeCommand extends Command
)); ));
} }
public function interact(InputInterface $input, OutputInterface $output) protected function interact(InputInterface $input, OutputInterface $output): void
{ {
$io = new SymfonyStyle($input, $output); $io = new SymfonyStyle($input, $output);
$longUrl = $input->getArgument('longUrl'); $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); $io = new SymfonyStyle($input, $output);
$longUrl = $input->getArgument('longUrl'); $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); $since = $input->getOption($fieldName);
return $since !== null ? new \DateTime($since) : null; return $since !== null ? new \DateTime($since) : null;

View file

@ -15,7 +15,8 @@ use Zend\I18n\Translator\TranslatorInterface;
class GetVisitsCommand extends Command class GetVisitsCommand extends Command
{ {
const NAME = 'shortcode:visits'; public const NAME = 'short-code:visits';
private const ALIASES = ['shortcode:visits'];
/** /**
* @var VisitsTrackerInterface * @var VisitsTrackerInterface
@ -33,9 +34,11 @@ class GetVisitsCommand extends Command
parent::__construct(); parent::__construct();
} }
public function configure() protected function configure(): void
{ {
$this->setName(self::NAME) $this
->setName(self::NAME)
->setAliases(self::ALIASES)
->setDescription( ->setDescription(
$this->translator->translate('Returns the detailed visits information for provided short code') $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'); $shortCode = $input->getArgument('shortCode');
if (! empty($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); $io = new SymfonyStyle($input, $output);
$shortCode = $input->getArgument('shortCode'); $shortCode = $input->getArgument('shortCode');
@ -101,7 +104,7 @@ class GetVisitsCommand extends Command
], $rows); ], $rows);
} }
protected function getDateOption(InputInterface $input, $key) private function getDateOption(InputInterface $input, $key)
{ {
$value = $input->getOption($key); $value = $input->getOption($key);
if (! empty($value)) { if (! empty($value)) {

View file

@ -18,7 +18,8 @@ class ListShortcodesCommand extends Command
{ {
use PaginatorUtilsTrait; use PaginatorUtilsTrait;
const NAME = 'shortcode:list'; public const NAME = 'short-code:list';
private const ALIASES = ['shortcode:list'];
/** /**
* @var ShortUrlServiceInterface * @var ShortUrlServiceInterface
@ -46,7 +47,9 @@ class ListShortcodesCommand extends Command
protected function configure(): void protected function configure(): void
{ {
$this->setName(self::NAME) $this
->setName(self::NAME)
->setAliases(self::ALIASES)
->setDescription($this->translator->translate('List all short URLs')) ->setDescription($this->translator->translate('List all short URLs'))
->addOption( ->addOption(
'page', 'page',
@ -88,7 +91,7 @@ class ListShortcodesCommand extends Command
); );
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output): void
{ {
$io = new SymfonyStyle($input, $output); $io = new SymfonyStyle($input, $output);
$page = (int) $input->getOption('page'); $page = (int) $input->getOption('page');

View file

@ -15,7 +15,8 @@ use Zend\I18n\Translator\TranslatorInterface;
class ResolveUrlCommand extends Command class ResolveUrlCommand extends Command
{ {
const NAME = 'shortcode:parse'; public const NAME = 'short-code:parse';
private const ALIASES = ['shortcode:parse'];
/** /**
* @var UrlShortenerInterface * @var UrlShortenerInterface
@ -33,9 +34,11 @@ class ResolveUrlCommand extends Command
parent::__construct(null); parent::__construct(null);
} }
public function configure() protected function configure(): void
{ {
$this->setName(self::NAME) $this
->setName(self::NAME)
->setAliases(self::ALIASES)
->setDescription($this->translator->translate('Returns the long URL behind a short code')) ->setDescription($this->translator->translate('Returns the long URL behind a short code'))
->addArgument( ->addArgument(
'shortCode', 'shortCode',
@ -44,7 +47,7 @@ class ResolveUrlCommand extends Command
); );
} }
public function interact(InputInterface $input, OutputInterface $output) protected function interact(InputInterface $input, OutputInterface $output): void
{ {
$shortCode = $input->getArgument('shortCode'); $shortCode = $input->getArgument('shortCode');
if (! empty($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); $io = new SymfonyStyle($input, $output);
$shortCode = $input->getArgument('shortCode'); $shortCode = $input->getArgument('shortCode');