<commit_before><?php

abstract class FormHandler {
    private $elementValues;

    public function __construct(array $elementValues = array()) {
        $this->elementValues = $elementValues;
    }

    public function getValue($name) {
        return $this->elementValues[$name];
    }

    public function getValues() {
        return $this->elementValues;
    }

    public function isReady() {
        foreach($this->elementValues as $name => $notUsed) {
            if(!isset($_POST[$name])) {
                return false;
            }
        }

        return true;
    }

    public function validate() {
        $errors = array();

        foreach($this->elementValues as $name => $notUsed) {
            $value = $_POST[$name];
            $methodName = 'validate_' . $name;
            $this->elementValues[$name] = $value;
            $error = method_exists($this, $methodName) ? $this->$methodName($value) : '';

            if($error != '') {
                $errors[$name] = $error;
            }
        }

        return $errors;
    }

    protected function addElement($key, $defaultValue) {
        if(!array_key_exists($key, $this->elementValues)) {
            $this->elementValues[$key] = $defaultValue;<commit_msg>refactor FormHandler, valid value is now null instead of the empty string<commit_after><?php

abstract class FormHandler {
    private $elementValues;

    public function __construct(array $elementValues = array()) {
        $this->elementValues = $elementValues;
    }

    public function getValue($key) {
        return $this->elementValues[$key];
    }

    public function getValues() {
        return $this->elementValues;
    }

    public function isReady() {
        foreach(array_keys($this->elementValues) as $key) {
            if(!isset($_POST[$key])) {
                return false;
            }
        }

        return true;
    }

    public function validate() {
        $errors = array();

        foreach(array_keys($this->elementValues) as $key) {
            $value = $_POST[$key];
            $methodName = 'validate_' . $key;
            $this->elementValues[$key] = $value;
            $error = method_exists($this, $methodName)
                ? $this->$methodName($value)
                : null;

            if(!is_null($error)) {
                $errors[$key] = $error;
            }
        }

        return $errors;
    }

    protected function addElement($key, $defaultValue) {
        if(!array_key_exists($key, $this->elementValues)) {
            $this->elementValues[$key] = $defaultValue;
{'fraction_non_alphanumeric': 0.1353558926487748, 'fraction_numerical': 0.0, 'mean_word_length': 2.0546318289786223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '1854801', 'n_tokens_mistral': 711, 'n_tokens_neox': 685, 'n_words': 145}