Used select_keys function in place of custom pick function

This commit is contained in:
Alejandro Celaya 2018-11-02 11:08:20 +01:00
parent 521f6f2b18
commit 664dc333ac
2 changed files with 3 additions and 19 deletions

View File

@ -15,7 +15,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
use Zend\I18n\Translator\TranslatorInterface; use Zend\I18n\Translator\TranslatorInterface;
use function array_map; use function array_map;
use function Shlinkio\Shlink\Common\pick; use function Functional\select_keys;
class GetVisitsCommand extends Command class GetVisitsCommand extends Command
{ {
@ -92,7 +92,7 @@ class GetVisitsCommand extends Command
$rows = array_map(function (Visit $visit) { $rows = array_map(function (Visit $visit) {
$rowData = $visit->jsonSerialize(); $rowData = $visit->jsonSerialize();
$rowData['country'] = $visit->getVisitLocation()->getCountryName(); $rowData['country'] = $visit->getVisitLocation()->getCountryName();
return pick($rowData, ['referer', 'date', 'userAgent', 'country']); return select_keys($rowData, ['referer', 'date', 'userAgent', 'country']);
}, $visits); }, $visits);
$io->table([ $io->table([
$this->translator->translate('Referer'), $this->translator->translate('Referer'),

View File

@ -3,10 +3,6 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Common; 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 getenv;
use function json_decode as spl_json_decode; use function json_decode as spl_json_decode;
use function json_last_error; use function json_last_error;
@ -14,6 +10,7 @@ use function json_last_error_msg;
use function sprintf; use function sprintf;
use function strtolower; use function strtolower;
use function trim; use function trim;
use const JSON_ERROR_NONE;
/** /**
* Gets the value of an environment variable. Supports boolean, empty and null. * Gets the value of an environment variable. Supports boolean, empty and null.
@ -49,19 +46,6 @@ function env($key, $default = null)
return trim($value); 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 * @throws Exception\InvalidArgumentException
*/ */