'pass', 'id' => static::$id, 'category' => static::$category, 'weight' => static::$weight, 'title' => static::get_title(), 'description' => static::get_description(), 'message' => $message, 'details' => $details, ); } /** * Build a failing result. * * @param string $severity 'low', 'medium', or 'high'. * @param string $message Short explanation of the problem. * @param string $recommendation Actionable fix advice. * @param array $details Optional structured data for the UI. * * @return array * * @since 4.9.0 */ protected static function fail( string $severity, string $message, string $recommendation = '', array $details = array() ): array { return array( 'status' => 'fail', 'severity' => $severity, 'id' => static::$id, 'category' => static::$category, 'weight' => static::$weight, 'title' => static::get_title(), 'description' => static::get_description(), 'message' => $message, 'recommendation' => $recommendation, 'details' => $details, ); } /** * Build a warning result (passes but worth attention). * * @param string $message Short explanation. * @param string $recommendation Optional advice. * @param array $details Optional structured data for the UI. * * @return array * * @since 4.9.0 */ protected static function warning( string $message, string $recommendation = '', array $details = array() ): array { return array( 'status' => 'warning', 'id' => static::$id, 'category' => static::$category, 'weight' => static::$weight, 'title' => static::get_title(), 'description' => static::get_description(), 'message' => $message, 'recommendation' => $recommendation, 'details' => $details, ); } /** * Build an informational result — neutral, no pass/fail judgement. * * Use when a check cannot meaningfully grade the site (e.g. the feature * isn't applicable, data is unavailable, or the outcome is purely * informational). The score calculator treats 'info' identically to 'pass'. * * @param string $message Short explanation. * @param array $details Optional structured data for the UI. * @return array * * @since 4.9.0 */ protected static function info( string $message, array $details = array() ): array { return array( 'status' => 'info', 'id' => static::$id, 'category' => static::$category, 'weight' => static::$weight, 'title' => static::get_title(), 'description' => static::get_description(), 'message' => $message, 'details' => $details, ); } // ------------------------------------------------------------------ // Formatting utilities — available to every check via static::. // ------------------------------------------------------------------ /** * Format an integer with locale-aware thousands separators. * * Examples: 1234 → "1,234" 1234567 → "1,234,567" * * @param int|float $number The number to format. * @param int $decimals Number of decimal places (default 0). * * @return string * * @since 4.9.0 */ protected static function format_number( int|float $number, int $decimals = 0 ): string { return number_format( (float) $number, $decimals ); } /** * Format a raw byte count into a human-readable string. * * Examples: 512 → "512 B" 1536 → "1.50 KB" 2097152 → "2.00 MB" * * @param int|float $bytes The byte count. * @param int $decimals Decimal places for the formatted value (default 2). * * @return string * * @since 4.9.0 */ protected static function format_bytes( int|float $bytes, int $decimals = 2 ): string { $bytes = max( 0.0, (float) $bytes ); $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB' ); $index = 0; while ( $bytes >= 1024 && $index < ( count( $units ) - 1 ) ) { $bytes /= 1024; ++$index; } return round( $bytes, $decimals ) . ' ' . $units[ $index ]; } } }