> */ public const CHECKS = [ // Things already wrong on the public site come first. MissingSlugs::class, DuplicateSlugs::class, BrokenImages::class, TestimonialsMissingOriginal::class, BrokenRedirects::class, // Then things that will bite later. MissingTranslations::class, // The same fault one step later: translated, and left behind by // the language it was translated from. Nothing else in the panel // would ever mention it — by every other measure those records // are finished. StaleTranslations::class, ImagesWithoutAlt::class, IncompleteSeo::class, ExpiredCalls::class, UnansweredSubmissions::class, // Somebody handed work over and nobody answered. The failure // mode the review step introduces: before it, an editor who // could not publish was stuck and knew it. StaleReviews::class, RedirectsToNowhere::class, // What visitors could not reach. Last of the redirect family because // it is the one that arrives on its own: the others are found by // looking at what is stored, this one by somebody hitting a dead link. UnresolvedMissingUrls::class, ServicesWithoutWork::class, ClientsWithoutLogo::class, TalksWithoutSpeaker::class, StalledMediaQueue::class, StaleRepositories::class, ]; /** * Every check there is, worst first. * * For the command line, which runs as a deploy rather than as a person: * there is nobody to hide a result from, and a release that skipped the * checks it could not attribute to a user would be worse than useless. * * @return Collection */ public function runAll(): Collection { return $this->execute(collect(self::CHECKS)->map(fn (string $check) => app($check))); } /** * Only the checks this user is allowed to see. * * @return Collection */ public function runFor(?User $user): Collection { return $this->execute( collect(self::CHECKS) ->map(fn (string $check) => app($check)) ->filter(fn (Check $check) => $this->visibleTo($check, $user)), ); } /** * How many checks are failing, for the badge in the sidebar. * * Cached, because this is read on every panel page render and running ten * checks to draw a number would make every page in the panel slower. */ public function problemCount(?User $user): int { return Cache::remember( $this->cacheKey($user), now()->addMinutes(5), fn () => $this->runFor($user)->filter(fn (Finding $f) => $f->severity->isProblem())->count(), ); } public function forget(?User $user): void { Cache::forget($this->cacheKey($user)); } /** * @param Collection $checks * @return Collection */ protected function execute(Collection $checks): Collection { return $checks ->map(fn (Check $check) => $check->run()) ->sortBy([ fn (Finding $a, Finding $b) => $a->severity->weight() <=> $b->severity->weight(), fn (Finding $a, Finding $b) => $b->count <=> $a->count, ]) ->values(); } protected function visibleTo(Check $check, ?User $user): bool { $permission = $check->permission(); if ($permission === null) { return true; } return $user?->can($permission) ?? false; } protected function cacheKey(?User $user): string { return 'health:problems:'.($user?->id ?? 'guest'); } }