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
{
const NAME = 'shortcode:process-previews';
public const NAME = 'short-code:process-previews';
private const ALIASES = ['shortcode:process-previews'];
/**
* @var PreviewGeneratorInterface
@ -40,9 +41,11 @@ class GeneratePreviewCommand extends Command
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(
'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;
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));

View file

@ -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,9 +47,11 @@ class GenerateShortcodeCommand extends Command
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('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);
$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;

View file

@ -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)) {

View file

@ -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,7 +47,9 @@ class ListShortcodesCommand extends Command
protected function configure(): void
{
$this->setName(self::NAME)
$this
->setName(self::NAME)
->setAliases(self::ALIASES)
->setDescription($this->translator->translate('List all short URLs'))
->addOption(
'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);
$page = (int) $input->getOption('page');

View file

@ -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,9 +34,11 @@ class ResolveUrlCommand extends Command
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'))
->addArgument(
'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');
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');