Removed more functional-php usages

This commit is contained in:
Alejandro Celaya
2023-11-30 14:34:21 +01:00
parent 549c6605f0
commit bff4bd12ae
20 changed files with 156 additions and 91 deletions

View File

@@ -6,7 +6,6 @@ namespace Shlinkio\Shlink\Core\ShortUrl\Model;
use Shlinkio\Shlink\Core\Model\DeviceType;
use function Functional\group;
use function trim;
final class DeviceLongUrlPair
@@ -25,27 +24,20 @@ final class DeviceLongUrlPair
* * The first one is a list of mapped instances for those entries in the map with non-null value
* * The second is a list of DeviceTypes which have been provided with value null
*
* @param array<string, string> $map
* @param array<string, string | null> $map
* @return array{array<string, self>, DeviceType[]}
*/
public static function fromMapToChangeSet(array $map): array
{
$toRemove = []; // TODO Use when group is removed
$toKeep = []; // TODO Use when group is removed
$typesWithNullUrl = group($map, static fn (?string $longUrl) => $longUrl === null ? 'remove' : 'keep');
$deviceTypesToRemove = [];
foreach ($typesWithNullUrl['remove'] ?? [] as $deviceType => $_) {
$deviceTypesToRemove[] = DeviceType::from($deviceType);
}
$pairsToKeep = [];
/**
* @var string $deviceType
* @var string $longUrl
*/
foreach ($typesWithNullUrl['keep'] ?? [] as $deviceType => $longUrl) {
$pairsToKeep[$deviceType] = self::fromRawTypeAndLongUrl($deviceType, $longUrl);
$deviceTypesToRemove = [];
foreach ($map as $deviceType => $longUrl) {
if ($longUrl === null) {
$deviceTypesToRemove[] = DeviceType::from($deviceType);
} else {
$pairsToKeep[$deviceType] = self::fromRawTypeAndLongUrl($deviceType, $longUrl);
}
}
return [$pairsToKeep, $deviceTypesToRemove];

View File

@@ -10,10 +10,10 @@ use Shlinkio\Shlink\Core\Model\DeviceType;
use function array_keys;
use function array_values;
use function Functional\every;
use function is_array;
use function Shlinkio\Shlink\Core\contains;
use function Shlinkio\Shlink\Core\enumValues;
use function Shlinkio\Shlink\Core\every;
class DeviceLongUrlsValidator extends AbstractValidator
{