id = $id; $this->label = $label; $this->status = $status; $this->summary = $summary; $this->consequence = $consequence; $this->next_action = $next_action; $this->detail = $detail; } /** * Returns the check identifier. * * @return string Identifier. */ public function get_id(): string { return $this->id; } /** * Returns the check label. * * @return string Label. */ public function get_label(): string { return $this->label; } /** * Returns the status. * * @return string One of the status constants. */ public function get_status(): string { return $this->status; } /** * Whether this finding needs the user's attention. * * @return bool True when something is wrong or undetermined. */ public function needs_attention(): bool { return in_array( $this->status, array( self::BROKEN, self::INERT, self::UNKNOWN ), true ); } /** * Whether this finding represents real, working enforcement. * * @return bool True when the layer actually refuses requests. */ public function is_enforcing(): bool { return self::PROTECTED_STATE === $this->status; } /** * Returns the short, human-readable label for a status constant. * * @param string $status One of the status constants. * @return string Human-readable label. */ public static function label_for( string $status ): string { switch ( $status ) { case self::PROTECTED_STATE: return __( 'Blocking', 'ai-blackout' ); case self::DECLARED: return __( 'Asking only', 'ai-blackout' ); case self::INERT: return __( 'Not working', 'ai-blackout' ); case self::BROKEN: return __( 'Needs attention', 'ai-blackout' ); case self::INACTIVE: return __( 'Off', 'ai-blackout' ); case self::UNKNOWN: return __( 'Cannot tell', 'ai-blackout' ); default: return __( 'Information', 'ai-blackout' ); } } /** * Returns the dashicon slug for a status's icon. * * @param string $status One of the status constants. * @return string Dashicon slug, for use as "dashicons-{slug}". */ public static function icon_for( string $status ): string { switch ( $status ) { case self::PROTECTED_STATE: return 'yes-alt'; case self::DECLARED: return 'megaphone'; case self::BROKEN: case self::INERT: case self::UNKNOWN: return 'warning'; case self::INACTIVE: return 'dismiss'; default: return 'info-outline'; } } /** * Returns the finding as an array, for REST responses and rendering. * * @return array Finding data. */ public function to_array(): array { return array( 'id' => $this->id, 'label' => $this->label, 'status' => $this->status, 'summary' => $this->summary, 'consequence' => $this->consequence, 'next_action' => $this->next_action, 'detail' => $this->detail, ); } }