refactor(support): centralize ID-array normalization in toIntIds()
Consolidates the scattered `array_values(array_unique(array_map('intval',
$x)))` + manual positive-filter pattern behind a single lenient helper
`toIntIds(mixed $value): array` in core/Support/helpers/array.php.
- `RepositoryArrayHelper::sanitizePositiveIds()` now delegates (keeps
strict array-input contract + existing tests intact).
- Drops two private duplicates: `UserProfileViewService::normalizeIds()`
and `AddressBookService::normalizeIds()`.
- Replaces 12 inline occurrences across admin action pages with the
helper, cutting boilerplate by 3-5 lines per site.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -798,14 +798,8 @@ foreach ($tenants as $tenant) {
|
||||
? $customFieldScalarPosted[$scalarPostedKey]
|
||||
: null;
|
||||
$multiPostedRaw = $customFieldMultiPosted[$scalarPostedKey] ?? null;
|
||||
$multiPosted = is_array($multiPostedRaw)
|
||||
? array_values(array_unique(array_map('intval', $multiPostedRaw)))
|
||||
: [];
|
||||
$multiPosted = array_values(array_filter($multiPosted, static fn (int $id): bool => $id > 0));
|
||||
$currentOptionIds = is_array($currentValue['option_ids'] ?? null)
|
||||
? array_values(array_unique(array_map('intval', $currentValue['option_ids'])))
|
||||
: [];
|
||||
$currentOptionIds = array_values(array_filter($currentOptionIds, static fn (int $id): bool => $id > 0));
|
||||
$multiPosted = is_array($multiPostedRaw) ? toIntIds($multiPostedRaw) : [];
|
||||
$currentOptionIds = toIntIds($currentValue['option_ids'] ?? null);
|
||||
$valueText = array_key_exists('value_text', $currentValue) ? (string) ($currentValue['value_text'] ?? '') : '';
|
||||
$valueBool = array_key_exists('value_bool', $currentValue) && $currentValue['value_bool'] !== null
|
||||
? (string) ((int) $currentValue['value_bool'])
|
||||
|
||||
Reference in New Issue
Block a user