Results grouped by check group, each group sorted critical-first. */ public static function run( array $checks ): array { $groups = array(); foreach ( $checks as $check ) { try { $results = $check->run(); } catch ( \Throwable $e ) { $results = array( new Result( 'check.failed', Result::RECOMMENDED, __( 'A check could not run', 'keepwatch' ), Redactor::redact( $e->getMessage() ) ), ); } $group = $check->group(); if ( ! isset( $groups[ $group ] ) ) { $groups[ $group ] = array(); } $groups[ $group ] = array_merge( $groups[ $group ], $results ); } foreach ( $groups as $group => $results ) { usort( $results, static function ( Result $a, Result $b ): int { return $a->weight() <=> $b->weight(); } ); $groups[ $group ] = $results; } return $groups; } /** * Count results per status. * * @param array $groups Grouped results. * @return array{good: int, recommended: int, critical: int} */ public static function summary( array $groups ): array { $summary = array( 'good' => 0, 'recommended' => 0, 'critical' => 0, ); foreach ( $groups as $results ) { foreach ( $results as $result ) { if ( isset( $summary[ $result->status ] ) ) { ++$summary[ $result->status ]; } } } return $summary; } }