<commit_before><?php namespace Konduto\Models;

const FIELD_NOT_VALID = 'NOT_VALID';

abstract class Model implements Entity {

    protected $mandatory = [];
    protected $errors = [];

    // Method called in the constructor of child classes
    protected function set_mandatory_fields($field_array) {
        $this->mandatory = $field_array;
    }

    // Reset errors
    public function clean_errors() {
        $this->errors = null;
    }

    /**
     * Look for unpopulated mandatory fields and add them to errors property.
     */
    public function get_errors() {
        // Check if all mandatory fields are present
        $properties = $this->as_array();

        foreach ($this->mandatory as $field) {
            if ((!array_key_exists($field, $properties) or $properties[$field] === null) and (!isset($this->errors[$field]))) {
                $this->errors[$field] = null;
            }
        }

        return $this->errors;
    }

    /**
     * Return true no validation error occurred and all mandatory fields are populated.
     */
    public function is_valid() {
        // Check if there are errors
        return empty($this->get_errors());
    }

    abstract public function set();

    /**
     * Does the validation according to ValidationSchema rules. If the parameter passed is valid,
     * sets the property and returns true. Returns false otherwise.
     * @param field: the property to be set.
     * @param field_name: the name of the field as in ValidationSchema.
     * @param value: the value to be set in the property.
     */
    abstract protected function set_property(&$field, $field_name, $value);
}<commit_msg>Hack for overcoming php 5.4- limitation in 'empty' function.<commit_after><?php namespace Konduto\Models;

const FIELD_NOT_VALID = 'NOT_VALID';

abstract class Model implements Entity {

    protected $mandatory = [];
    protected $errors = [];

    // Method called in the constructor of child classes
    protected function set_mandatory_fields($field_array) {
        $this->mandatory = $field_array;
    }

    // Reset errors
    public function clean_errors() {
        $this->errors = null;
    }

    /**
     * Look for unpopulated mandatory fields and add them to errors property.
     */
    public function get_errors() {
        // Check if all mandatory fields are present
        $properties = $this->as_array();

        foreach ($this->mandatory as $field) {
            if ((!array_key_exists($field, $properties) or $properties[$field] === null) and (!isset($this->errors[$field]))) {
                $this->errors[$field] = null;
            }
        }

        return $this->errors;
    }

    /**
     * Return true no validation error occurred and all mandatory fields are populated.
     */
    public function is_valid() {
        // Check if there are errors
        $isEmpty = empty($this->get_errors());
        return $isEmpty;
    }

    abstract public function set();

    /**
     * Does the validation according to ValidationSchema rules. If the parameter passed is valid,
     * sets the property and returns true. Returns false otherwise.
     * @param field: the property to be set.
     * @param field_name: the name of the field as in ValidationSchema.
     * @param value: the value to be set in the property.
     */
    abstract protected function set_property(&$field, $field_name, $value);
}
{'fraction_non_alphanumeric': 0.10506180105944674, 'fraction_numerical': 0.0005885815185403178, 'mean_word_length': 2.5517241379310347, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '2717496', 'n_tokens_mistral': 902, 'n_tokens_neox': 873, 'n_words': 320}