From 664dc333acd9d367865eb1026c46dfb8a213f026 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 2 Nov 2018 11:08:20 +0100 Subject: [PATCH] Used select_keys function in place of custom pick function --- .../src/Command/ShortUrl/GetVisitsCommand.php | 4 ++-- module/Common/functions/functions.php | 18 +----------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php b/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php index caf9c4b7..e2451406 100644 --- a/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php +++ b/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php @@ -15,7 +15,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Zend\I18n\Translator\TranslatorInterface; use function array_map; -use function Shlinkio\Shlink\Common\pick; +use function Functional\select_keys; class GetVisitsCommand extends Command { @@ -92,7 +92,7 @@ class GetVisitsCommand extends Command $rows = array_map(function (Visit $visit) { $rowData = $visit->jsonSerialize(); $rowData['country'] = $visit->getVisitLocation()->getCountryName(); - return pick($rowData, ['referer', 'date', 'userAgent', 'country']); + return select_keys($rowData, ['referer', 'date', 'userAgent', 'country']); }, $visits); $io->table([ $this->translator->translate('Referer'), diff --git a/module/Common/functions/functions.php b/module/Common/functions/functions.php index f84957dc..cccd70be 100644 --- a/module/Common/functions/functions.php +++ b/module/Common/functions/functions.php @@ -3,10 +3,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common; -use const ARRAY_FILTER_USE_KEY; -use const JSON_ERROR_NONE; -use function array_filter; -use function Functional\contains; use function getenv; use function json_decode as spl_json_decode; use function json_last_error; @@ -14,6 +10,7 @@ use function json_last_error_msg; use function sprintf; use function strtolower; use function trim; +use const JSON_ERROR_NONE; /** * Gets the value of an environment variable. Supports boolean, empty and null. @@ -49,19 +46,6 @@ function env($key, $default = null) return trim($value); } -/** - * Returns only the keys in keysToPick from provided array - * - * @param array $array - * @param array $keysToPick - */ -function pick(array $array, array $keysToPick): array -{ - return array_filter($array, function (string $key) use ($keysToPick) { - return contains($keysToPick, $key); - }, ARRAY_FILTER_USE_KEY); -} - /** * @throws Exception\InvalidArgumentException */