<commit_before><?php
namespace Czim\CmsModels\ModelInformation\Data\Form\Validation;

use Czim\CmsModels\Contracts\ModelInformation\Data\Form\Validation\ValidationRuleDataInterface;
use Czim\CmsModels\Support\Translation\TranslationLocaleHelper;

/**
 * Class ValidationRuleData
 *
 * Data describing validation rule(s) for a single form field (key).
 */
class ValidationRuleData implements ValidationRuleDataInterface
{
    /**
     * String key that identifies a validation rule data set.
     */
    const IDENTIFIER_KEY = '**';


    /**
     * The validation rules in Laravel array syntax.
     *
     * @var array|string[]
     */
    protected $rules;

    /**
     * The key for the validation rules in dot notation, if known.
     *
     * @var null|string
     */
    protected $key;

    /**
     * Whether the field for the rules is translated.
     *
     * @var bool
     */
    protected $translated;

    /**
     * The position of the locale placeholder in the dot notation key string.
     *
     * @var int
     */
    protected $localeIndex = 1;

    /**
     * The locale placeholder to use in the dot notation key, if not default.
     *
     * @var null|string
     */
    protected $localePlaceholder;

    /**
     * If true, the key should be required_with when used in translation context.
     *
     * @var bool
     */
    protected $requiredWithTranslation = false;


    /**
     * @param array       $rules        the rules for this key in Laravel array notation
     * @param string|null $key          the field key
     */
    public function __construct(array $rules, $key = null)
    {
        $this->rules = $rules;
        $this->key   = $key;
    }


    /**
     * Sets the key for the validation rules in dot notation.
     *
     * @param string $key
     * @return $this
     */
    public function setKey($key)
    {
        $this->key = $key;

        return $this;
    }

    /**
     * Returns the key in dot notation.
     *
     * @return string
     */
    public function key()
    {
        if ( ! $this->isTranslated()) {
            return $this->key;
        }

        $parts = explode('.', $this->key);

        array_splice($parts, $this->localeIndex, 0, $this->getLocalePlaceholder());

        return implode('.', $parts);
    }

    /**
     * Sets whether the field is translated.
     *
     * @param bool $translated
     * @return $this
     */
    public function setIsTranslated($translated = true)
    {
        $this->translated = (bool) $translated;

        return $this;
    }

    /**
     * Returns whether the field is known to be translated.
     *
     * @return bool
     */
    public function isTranslated()
    {
        return $this->translated;
    }

    /**
     * Sets the index at which the locale placeholder should be inserted for a full key.
     *
     * @param int $index
     * @return $this
     */
    public function setLocaleIndex($index)
    {
        $this->localeIndex = (int) $index;

        return $this;
    }

    /**
     * Returns the index at which the locale placeholder is inserted for a full key.
     *
     * @return int
     */
    public function localeIndex()
    {
        return $this->localeIndex;
    }

    /**
     * Sets the context to be required_with for translations.
     *
     * @param bool $required
     * @return $this
     */
    public function setRequiredWithTranslation($required = true)
    {
        $this->requiredWithTranslation = (bool) $required;

        return $this;
    }

    /**
     * Returns whether the context is set to be required_with for translations.
     *
     * @return bool
     */
    public function isRequiredWithTranslation()
    {
        return $this->requiredWithTranslation;
    }

    /**
     * Sets validation rules.
     *
     * @param array|string[] $rules
     * @return $this
     */
    public function setRules(array $rules)
    {
        $this->rules;

        return $this;
    }

    /**
     * Returns the validation rules.
     *
     * @return array|string[]<commit_msg>Fixed broken setter in validation rule data<commit_after><?php
namespace Czim\CmsModels\ModelInformation\Data\Form\Validation;

use Czim\CmsModels\Contracts\ModelInformation\Data\Form\Validation\ValidationRuleDataInterface;
use Czim\CmsModels\Support\Translation\TranslationLocaleHelper;

/**
 * Class ValidationRuleData
 *
 * Data describing validation rule(s) for a single form field (key).
 */
class ValidationRuleData implements ValidationRuleDataInterface
{
    /**
     * String key that identifies a validation rule data set.
     */
    const IDENTIFIER_KEY = '**';


    /**
     * The validation rules in Laravel array syntax.
     *
     * @var array|string[]
     */
    protected $rules;

    /**
     * The key for the validation rules in dot notation, if known.
     *
     * @var null|string
     */
    protected $key;

    /**
     * Whether the field for the rules is translated.
     *
     * @var bool
     */
    protected $translated;

    /**
     * The position of the locale placeholder in the dot notation key string.
     *
     * @var int
     */
    protected $localeIndex = 1;

    /**
     * The locale placeholder to use in the dot notation key, if not default.
     *
     * @var null|string
     */
    protected $localePlaceholder;

    /**
     * If true, the key should be required_with when used in translation context.
     *
     * @var bool
     */
    protected $requiredWithTranslation = false;


    /**
     * @param array       $rules        the rules for this key in Laravel array notation
     * @param string|null $key          the field key
     */
    public function __construct(array $rules, $key = null)
    {
        $this->rules = $rules;
        $this->key   = $key;
    }


    /**
     * Sets the key for the validation rules in dot notation.
     *
     * @param string $key
     * @return $this
     */
    public function setKey($key)
    {
        $this->key = $key;

        return $this;
    }

    /**
     * Returns the key in dot notation.
     *
     * @return string
     */
    public function key()
    {
        if ( ! $this->isTranslated()) {
            return $this->key;
        }

        $parts = explode('.', $this->key);

        array_splice($parts, $this->localeIndex, 0, $this->getLocalePlaceholder());

        return implode('.', $parts);
    }

    /**
     * Sets whether the field is translated.
     *
     * @param bool $translated
     * @return $this
     */
    public function setIsTranslated($translated = true)
    {
        $this->translated = (bool) $translated;

        return $this;
    }

    /**
     * Returns whether the field is known to be translated.
     *
     * @return bool
     */
    public function isTranslated()
    {
        return $this->translated;
    }

    /**
     * Sets the index at which the locale placeholder should be inserted for a full key.
     *
     * @param int $index
     * @return $this
     */
    public function setLocaleIndex($index)
    {
        $this->localeIndex = (int) $index;

        return $this;
    }

    /**
     * Returns the index at which the locale placeholder is inserted for a full key.
     *
     * @return int
     */
    public function localeIndex()
    {
        return $this->localeIndex;
    }

    /**
     * Sets the context to be required_with for translations.
     *
     * @param bool $required
     * @return $this
     */
    public function setRequiredWithTranslation($required = true)
    {
        $this->requiredWithTranslation = (bool) $required;

        return $this;
    }

    /**
     * Returns whether the context is set to be required_with for translations.
     *
     * @return bool
     */
    public function isRequiredWithTranslation()
    {
        return $this->requiredWithTranslation;
    }

    /**
     * Sets validation rules.
     *
     * @param array|string[] $rules
     * @return $this
     */
    public function setRules(array $rules)
    {
        $this->rules = $rules;

        return $this;
    }

    /**
     * Returns the validation rules.
     *
     * @return array|string[]
{'fraction_non_alphanumeric': 0.10749785249723892, 'fraction_numerical': 0.0004908577739599951, 'mean_word_length': 1.9411764705882353, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6987082', 'n_tokens_mistral': 2339, 'n_tokens_neox': 2256, 'n_words': 694}