mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Improved public API in VisitLocation entity, reducing anemic model
This commit is contained in:
@@ -3,7 +3,9 @@ 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 getenv;
|
||||
use function in_array;
|
||||
use function json_decode as spl_json_decode;
|
||||
@@ -52,6 +54,19 @@ function contains($needle, array $haystack): bool
|
||||
return in_array($needle, $haystack, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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($key, $keysToPick);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception\InvalidArgumentException
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user