Improved public API in VisitLocation entity, reducing anemic model

This commit is contained in:
Alejandro Celaya
2018-10-28 15:13:45 +01:00
parent 084b1169d7
commit e046eddda9
7 changed files with 41 additions and 93 deletions

View File

@@ -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
*/