$meta * @return array{odata_type?: string, etag?: string|null, scope_tag_ids?: list, assignment_target_count?: int|null, warnings?: list} */ public function sanitize(array $meta): array { $sanitized = []; $odataType = $meta['odata_type'] ?? null; if (is_string($odataType) && trim($odataType) !== '') { $sanitized['odata_type'] = trim($odataType); } $etag = $meta['etag'] ?? null; if ($etag === null || is_string($etag)) { $sanitized['etag'] = $etag === null ? null : trim($etag); } $scopeTagIds = $meta['scope_tag_ids'] ?? null; if (is_array($scopeTagIds)) { $sanitized['scope_tag_ids'] = $this->stringList($scopeTagIds); } $assignmentTargetCount = $meta['assignment_target_count'] ?? null; if (is_int($assignmentTargetCount)) { $sanitized['assignment_target_count'] = $assignmentTargetCount; } elseif (is_numeric($assignmentTargetCount)) { $sanitized['assignment_target_count'] = (int) $assignmentTargetCount; } elseif ($assignmentTargetCount === null) { $sanitized['assignment_target_count'] = null; } $warnings = $meta['warnings'] ?? null; if (is_array($warnings)) { $sanitized['warnings'] = $this->boundedStringList($warnings, 25, 200); } return array_filter( $sanitized, static fn (mixed $value): bool => $value !== null && $value !== [] && $value !== '' ); } /** * @param list $values * @return list */ private function stringList(array $values): array { $result = []; foreach ($values as $value) { if (! is_string($value)) { continue; } $value = trim($value); if ($value === '') { continue; } $result[] = $value; } return array_values(array_unique($result)); } /** * @param list $values * @return list */ private function boundedStringList(array $values, int $maxItems, int $maxLen): array { $items = []; foreach ($values as $value) { if (count($items) >= $maxItems) { break; } if (! is_string($value)) { continue; } $value = trim($value); if ($value === '') { continue; } $items[] = mb_substr($value, 0, $maxLen); } return array_values(array_unique($items)); } }