'Update now', 'no_fix' => 'No fix yet', ]; /** * The markers of the given resources (applications, services, standalone databases) with a constant number of * queries. Resources without a marker have no entry. * * @param Collection $resources * @return array Keyed by `ResourceScans::key()`. */ public static function for(Collection $resources): array { $resources = $resources->filter(fn ($resource): bool => $resource instanceof Model)->values(); if ($resources->isEmpty() || ! instanceSettings()->is_image_scanning_allowed) { return []; } $markers = []; foreach (SecurityStatus::storedMany($resources) as $key => $security) { $marker = self::marker($security); if ($marker !== null) { $markers[$key] = $marker; } } return $markers; } /** * The marker of one status. `tooltip` is the primary action sentence of update_now; `label` (the aria-label) * names the status and the action. * * @return array{status: string, text: string, label: string, tooltip: ?string}|null */ public static function marker(ResourceSecurity $security): ?array { $text = self::TEXTS[$security->status->value] ?? null; if ($text === null) { return null; } $action = $security->status === SecurityStatusType::UpdateNow ? $security->primary()?->sentence : null; $action = filled($action) ? $action : null; return [ 'status' => $security->status->value, 'text' => $text, 'label' => 'Security: '.mb_strtolower($text).($action === null ? '' : '. '.$action), 'tooltip' => $action, ]; } }