Removed use of deprecated approach for ordering in ListShort

This commit is contained in:
Alejandro Celaya 2021-02-04 21:33:26 +01:00
parent 16873201e9
commit 4330a09793

View file

@ -21,8 +21,8 @@ use Symfony\Component\Console\Style\SymfonyStyle;
use function array_flip; use function array_flip;
use function array_intersect_key; use function array_intersect_key;
use function array_pad;
use function array_values; use function array_values;
use function count;
use function explode; use function explode;
use function implode; use function implode;
use function sprintf; use function sprintf;
@ -79,7 +79,8 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand
'order-by', 'order-by',
'o', 'o',
InputOption::VALUE_REQUIRED, InputOption::VALUE_REQUIRED,
'The field from which we want to order by. Pass ASC or DESC separated by a comma.', 'The field from which you want to order by. '
. 'Define ordering dir by passing ASC or DESC after "," or "-".',
) )
->addOptionWithDeprecatedFallback( ->addOptionWithDeprecatedFallback(
'show-tags', 'show-tags',
@ -178,17 +179,14 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand
return $result; return $result;
} }
/** private function processOrderBy(InputInterface $input): ?string
* @return array|string|null
*/
private function processOrderBy(InputInterface $input)
{ {
$orderBy = $this->getOptionWithDeprecatedFallback($input, 'order-by'); $orderBy = $this->getOptionWithDeprecatedFallback($input, 'order-by');
if (empty($orderBy)) { if (empty($orderBy)) {
return null; return null;
} }
$orderBy = explode(',', $orderBy); [$field, $dir] = array_pad(explode(',', $orderBy), 2, null);
return count($orderBy) === 1 ? $orderBy[0] : [$orderBy[0] => $orderBy[1]]; return $dir === null ? $field : sprintf('%s-%s', $field, $dir);
} }
} }