runAll(); if ($this->option('json')) { $this->line((string) json_encode($findings->map(fn (Finding $f) => [ 'key' => $f->key, 'severity' => $f->severity->value, 'count' => $f->count, 'samples' => $f->samples, ])->all(), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); return $this->exitCode($findings); } foreach ($findings as $finding) { $this->components->twoColumnDetail( $finding->title(), $this->badge($finding), ); foreach ($finding->samples as $sample) { $this->line(" · {$sample}"); } } $this->newLine(); $problems = $findings->filter(fn (Finding $f) => $f->severity->isProblem()); if ($problems->isEmpty()) { $this->components->info(__('health.all_clear')); } else { $this->components->warn( trans_choice('health.problem_summary', $problems->count(), ['count' => $problems->count()]) ); } return $this->exitCode($findings); } /** * @param Collection $findings */ protected function exitCode($findings): int { $threshold = match ((string) $this->option('fail-on')) { 'error' => Severity::Error, 'never' => null, default => Severity::Warning, }; if ($threshold === null) { return self::SUCCESS; } $failing = $findings->contains( fn (Finding $f) => $f->severity->weight() <= $threshold->weight() && $f->severity->isProblem() ); return $failing ? self::FAILURE : self::SUCCESS; } protected function badge(Finding $finding): string { return match ($finding->severity) { Severity::Ok => 'ok', Severity::Warning => "{$finding->count}", Severity::Error => "{$finding->count}", }; } }