Fixed coding styles

This commit is contained in:
Alejandro Celaya 2021-04-11 10:50:35 +02:00
parent 5d0f306bcc
commit a896fbbb90

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\CLI\Command\ShortUrl; namespace Shlinkio\Shlink\CLI\Command\ShortUrl;
use closure;
use Shlinkio\Shlink\CLI\Command\Util\AbstractWithDateRangeCommand; use Shlinkio\Shlink\CLI\Command\Util\AbstractWithDateRangeCommand;
use Shlinkio\Shlink\CLI\Util\ExitCodes; use Shlinkio\Shlink\CLI\Util\ExitCodes;
use Shlinkio\Shlink\CLI\Util\ShlinkTable; use Shlinkio\Shlink\CLI\Util\ShlinkTable;
@ -24,11 +23,9 @@ use Symfony\Component\Console\Style\SymfonyStyle;
use function array_keys; use function array_keys;
use function array_pad; use function array_pad;
use function count;
use function explode; use function explode;
use function Functional\map; use function Functional\map;
use function is_null; use function implode;
use function join;
use function sprintf; use function sprintf;
class ListShortUrlsCommand extends AbstractWithDateRangeCommand class ListShortUrlsCommand extends AbstractWithDateRangeCommand
@ -128,32 +125,33 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand
$endDate = $this->getEndDateOption($input, $output); $endDate = $this->getEndDateOption($input, $output);
$orderBy = $this->processOrderBy($input); $orderBy = $this->processOrderBy($input);
$transformerLookup = fn (string $key): callable =>
$transformerLookup = fn (string $key): closure fn (ShortUrl $shortUrl) => $this->transformer->transform($shortUrl)[$key];
=> fn (ShortUrl $shortUrl)
=> $this->transformer->transform($shortUrl)[$key];
$columnMap = [ $columnMap = [
'Short Code' => $transformerLookup('shortCode'), 'Short Code' => $transformerLookup('shortCode'),
'Title' => $transformerLookup('title'), 'Title' => $transformerLookup('title'),
'Short URL' => $transformerLookup('shortUrl'), 'Short URL' => $transformerLookup('shortUrl'),
'Long URL' => $transformerLookup('longUrl'), 'Long URL' => $transformerLookup('longUrl'),
'Date created' => $transformerLookup('dateCreated'), 'Date created' => $transformerLookup('dateCreated'),
'Visits count' => $transformerLookup('visitsCount'), 'Visits count' => $transformerLookup('visitsCount'),
]; ];
if ($this->getOptionWithDeprecatedFallback($input, 'show-tags')) { if ($this->getOptionWithDeprecatedFallback($input, 'show-tags')) {
$columnMap['Tags'] = fn (ShortUrl $shortUrl): string $columnMap['Tags'] = static fn (ShortUrl $shortUrl): string => implode(
=> join(', ', map($shortUrl->getTags(), fn (Tag $tag): string => (string) $tag)); ', ',
map($shortUrl->getTags(), fn (Tag $tag): string => (string) $tag),
);
} }
if ($input->getOption('show-api-key')) { if ($input->getOption('show-api-key')) {
$columnMap['API Key'] = fn (ShortUrl $shortUrl): string => (string) $shortUrl->authorApiKey(); $columnMap['API Key'] = static fn (ShortUrl $shortUrl): string => (string) $shortUrl->authorApiKey();
} }
if ($input->getOption('show-api-key-name')) { if ($input->getOption('show-api-key-name')) {
$columnMap['API Key Name'] = fn (ShortUrl $shortUrl): ?string => ! is_null($shortUrl->authorApiKey()) $columnMap['API Key Name'] = static function (ShortUrl $shortUrl): ?string {
? $shortUrl->authorApiKey()->name() $apiKey = $shortUrl->authorApiKey();
: null;
}
return $apiKey !== null ? $apiKey->name() : null;
};
}
$data = [ $data = [
ShortUrlsParamsInputFilter::SEARCH_TERM => $searchTerm, ShortUrlsParamsInputFilter::SEARCH_TERM => $searchTerm,
@ -192,19 +190,13 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand
): Paginator { ): Paginator {
$shortUrls = $this->shortUrlService->listShortUrls($params); $shortUrls = $this->shortUrlService->listShortUrls($params);
$rows = map($shortUrls, fn (ShortUrl $shortUrl) $rows = map($shortUrls, fn (ShortUrl $shortUrl) => map($columnMap, fn (callable $call) => $call($shortUrl)));
=> map($columnMap, fn (callable $call)
=> $call($shortUrl)));
ShlinkTable::fromOutput($output) ShlinkTable::fromOutput($output)->render(
->render( array_keys($columnMap),
array_keys($columnMap), $rows,
$rows, $all ? null : $this->formatCurrentPageMessage($shortUrls, 'Page %s of %s'),
$all ? null : $this->formatCurrentPageMessage( );
$shortUrls,
'Page %s of %s',
),
);
return $shortUrls; return $shortUrls;
} }