<?php

/**
 * Rule to ensure the minium value.
 *
 * @package    Framework
 * @subpackage Validation\Rules
 * @since      1.0.0
 */
namespace Kirki\Framework\Validation\Rules;

\defined('ABSPATH') || exit;
use function Kirki\Framework\message;
class Sanitizer extends BaseRule
{
    /**
     * Check if the value is valid.
     *
     * @return bool
     *
     * @since 1.0.0
     */
    public function validate_rule()
    {
        $this->sanitize_data();
        return \true;
    }
    /**
     * Get the error message if the value is less than the min value.
     *
     * @return string
     *
     * @since 1.0.0
     */
    public function get_error_message()
    {
        return message('validator.sanitize', $this->last_key_segment());
    }
    /**
     * Sanitize the data.
     *
     * @return void
     *
     * @since 1.0.0
     */
    public function sanitize_data()
    {
        switch ($this->rule_value) {
            case 'trim':
                $this->value = \trim($this->value);
                break;
            case 'text':
                $this->value = sanitize_text_field($this->value);
                break;
            case 'textarea':
                $this->value = sanitize_textarea_field($this->value);
                break;
            case 'email':
                $this->value = sanitize_email($this->value);
                break;
            case 'url':
                $this->value = sanitize_url($this->value);
                break;
            case 'key':
                $this->value = sanitize_key($this->value);
                break;
            case 'title':
                $this->value = sanitize_title($this->value);
                break;
            case 'file-name':
                $this->value = sanitize_file_name($this->value);
                break;
            case 'mime-type':
                $this->value = sanitize_mime_type($this->value);
                break;
        }
    }
}
