*/ public function counts(): array { $query = $this->query_runner->prepare( 'SELECT CASE outcome WHEN %s THEN %s WHEN %s THEN %s ELSE verdict END AS count_group, COUNT(*) AS group_total FROM ' . $this->tables->links() . ' WHERE outcome <> %s GROUP BY count_group', Outcome::Resolved->value, Verdict::Working->value, Outcome::Ignored->value, Outcome::Ignored->value, Outcome::Removed->value ); $counts = $this->add_up( $query, array( Verdict::Working->value, Verdict::Broken->value, Verdict::Blocked->value, Verdict::Moved->value, Verdict::Retrying->value, Outcome::Ignored->value, ) ); return array( self::TOTAL_GROUP => array_sum( $counts ) ) + $counts; } /** @return array */ public function places(): array { $query = $this->query_runner->prepare( 'SELECT links.verdict AS count_group, COUNT(*) AS group_total FROM ' . $this->tables->links() . ' links JOIN ' . $this->tables->uses() . ' uses ON uses.link_id = links.id WHERE links.outcome = %s GROUP BY links.verdict', Outcome::Listed->value ); return $this->add_up( $query, array( Verdict::Broken->value, Verdict::Blocked->value, Verdict::Moved->value, ) ); } /** * @param list $groups * @return array */ private function add_up( string $query, array $groups ): array { $rows = $this->query_runner->rows( $query ); $group_totals = array_column( $rows, 'group_total', 'count_group' ); $totals = array(); foreach ( $groups as $group ) { $totals[ $group ] = (int) ( $group_totals[ $group ] ?? 0 ); } return $totals; } }