HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ubuntu-8gb-hel1-1 6.8.0-55-generic #57-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 12 23:42:21 UTC 2025 x86_64
User: www-data (33)
PHP: 8.1.32
Disabled: NONE
Upload Files
File: /var/www/agighana.org_backup/optimization-error-message.php
<?php

namespace ImageOptimization\Modules\Optimization\Classes;

use ImageOptimization\Classes\Image\Image_Optimization_Error_Type;

use TypeError;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

class Optimization_Error_Message {
	public static function get_reoptimization_error_message( string $error_type ) {
		if ( Image_Optimization_Error_Type::GENERIC === $error_type ) {
			return esc_html__( 'Image reoptimizing failed', 'image-optimization' );
		}

		return self::get_optimization_error_message( $error_type );
	}

	public static function get_optimization_error_message( string $error_type ) {
		if ( ! in_array( $error_type, Image_Optimization_Error_Type::get_values(), true ) ) {
			throw new TypeError( "Error type $error_type is not a part of Image_Optimization_Error_Type values" );
		}

		$messages = [
			Image_Optimization_Error_Type::FILE_ALREADY_EXISTS => esc_html__( 'File with this name already exists', 'image-optimization' ),
			Image_Optimization_Error_Type::QUOTA_EXCEEDED => esc_html__( 'Plan quota reached', 'image-optimization' ),
			Image_Optimization_Error_Type::GENERIC => esc_html__( 'Optimization error', 'image-optimization' ),
		];

		if ( isset( $messages[ $error_type ] ) ) {
			return $messages[ $error_type ];
		}

		return $messages[ Image_Optimization_Error_Type::GENERIC ];
	}
}