The result. */ public static function categoryCodes(): array { return [ self::CATEGORY_ACCEPTED => [ 200 ], self::CATEGORY_PENDING => [ 202 ], self::CATEGORY_REJECTED => array_merge( [ 0 ], self::PERMANENT_CODES ), self::CATEGORY_LIMITED => [ 429 ], ]; } /** * Translated pill label for one display category. * * @param string $category Category slug from categoryFor. * @return string The result. */ public static function statusLabel( string $category ): string { if ( self::CATEGORY_PENDING === $category ) { return __( 'Key pending', 'rankkernel' ); } if ( self::CATEGORY_REJECTED === $category ) { return __( 'Rejected', 'rankkernel' ); } if ( self::CATEGORY_LIMITED === $category ) { return __( 'Rate limited', 'rankkernel' ); } if ( self::CATEGORY_RETRY === $category ) { return __( 'Retry later', 'rankkernel' ); } return __( 'Accepted', 'rankkernel' ); } /** * Pill class for one display category. * * @param string $category Category slug from categoryFor. * @return string The result. */ public static function statusPill( string $category ): string { $map = [ self::CATEGORY_ACCEPTED => 'rk-ui-pill rk-ui-pill-success', self::CATEGORY_PENDING => 'rk-ui-pill rk-ui-pill-info', self::CATEGORY_REJECTED => 'rk-ui-pill rk-ui-pill-danger', self::CATEGORY_LIMITED => 'rk-ui-pill rk-ui-pill-warning', self::CATEGORY_RETRY => 'rk-ui-pill rk-ui-pill-warning', ]; return $map[ $category ] ?? 'rk-ui-pill rk-ui-pill-success'; } /** * Translated source label, auto or manual. * * @param string $source Stored source value. * @return string The result. */ public static function sourceLabel( string $source ): string { if ( 'manual' === $source ) { return __( 'Manual', 'rankkernel' ); } return __( 'Auto', 'rankkernel' ); } /** * Pill class for one source value. * * @param string $source Stored source value. * @return string The result. */ public static function sourcePill( string $source ): string { if ( 'manual' === $source ) { return 'rk-ui-pill rk-pill-source-manual'; } return 'rk-ui-pill rk-ui-pill-neutral'; } /** * Stats strip numbers derived from per category counts. * * The query layer supplies the counts, so the strip covers the whole * table rather than a page. Accepted is the accepted plus pending * count, rejected is the rejected count, limited is the limited * count, retry is the retry count, and total is every row. * * @param array $counts Category counts keyed by category slug plus all. * @return array{total: int, accepted: int, rejected: int, limited: int, retry: int} The result. */ public static function statsFromCounts( array $counts ): array { return [ 'total' => (int) ( $counts['all'] ?? 0 ), 'accepted' => (int) ( $counts[ self::CATEGORY_ACCEPTED ] ?? 0 ) + (int) ( $counts[ self::CATEGORY_PENDING ] ?? 0 ), 'rejected' => (int) ( $counts[ self::CATEGORY_REJECTED ] ?? 0 ), 'limited' => (int) ( $counts[ self::CATEGORY_LIMITED ] ?? 0 ), 'retry' => (int) ( $counts[ self::CATEGORY_RETRY ] ?? 0 ), ]; } }