| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimization\Modules\Optimization\Classes; |
| 4 |
|
| 5 |
use ImageOptimization\Classes\Image\Image_Optimization_Error_Type; |
| 6 |
|
| 7 |
use TypeError; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
|
| 13 |
class Optimization_Error_Message { |
| 14 |
public static function get_reoptimization_error_message( string $error_type ) { |
| 15 |
if ( Image_Optimization_Error_Type::GENERIC === $error_type ) { |
| 16 |
return esc_html__( 'Image reoptimizing failed', 'image-optimization' ); |
| 17 |
} |
| 18 |
|
| 19 |
return self::get_optimization_error_message( $error_type ); |
| 20 |
} |
| 21 |
|
| 22 |
public static function get_optimization_error_message( string $error_type ) { |
| 23 |
if ( ! in_array( $error_type, Image_Optimization_Error_Type::get_values(), true ) ) { |
| 24 |
throw new TypeError( "Error type $error_type is not a part of Image_Optimization_Error_Type values" ); |
| 25 |
} |
| 26 |
|
| 27 |
$messages = [ |
| 28 |
Image_Optimization_Error_Type::FILE_ALREADY_EXISTS => esc_html__( 'File with this name already exists', 'image-optimization' ), |
| 29 |
Image_Optimization_Error_Type::QUOTA_EXCEEDED => esc_html__( 'Plan quota reached', 'image-optimization' ), |
| 30 |
Image_Optimization_Error_Type::GENERIC => esc_html__( 'Optimization error', 'image-optimization' ), |
| 31 |
]; |
| 32 |
|
| 33 |
if ( isset( $messages[ $error_type ] ) ) { |
| 34 |
return $messages[ $error_type ]; |
| 35 |
} |
| 36 |
|
| 37 |
return $messages[ Image_Optimization_Error_Type::GENERIC ]; |
| 38 |
} |
| 39 |
} |
| 40 |
|