<commit_before><?php

namespace Formjack;

use Formjack\Field\AbstractField;
use Formjack\Rule\AbstractRule;
use Formjack\Helper\ValidationCondition;

class Validator {

    /**
     * @param  AbstractField $field
     * @return \stdClass
     */
    public static function validateField(AbstractField $field) {
        $errors = array();
        $result = new \stdClass();
        $rules = $field->getRules();
        self::loop($field, $rules, $errors);

        $result->valid = empty($errors);
        $result->trace = $errors;

        return $result;
    }

    private static function loop(AbstractField $field, array $rules, array &$errors) {
        foreach ($rules as $rule) {
            if ($rule instanceof AbstractRule && $rule->run($field)) {
                $result = $rule->validate($field);
                if (is_bool($result) && $result === false) {
                    $errors[] = $rule->getInvalidMessage();
                } elseif (is_array($result)) {
                    self::loop($field, $result, $errors);
                }
            }
        }

        return;
    }

}<commit_msg>Updated phpDOC for loop method.<commit_after><?php

namespace Formjack;

use Formjack\Field\AbstractField;
use Formjack\Rule\AbstractRule;
use Formjack\Helper\ValidationCondition;

class Validator {

    /**
     * @param  AbstractField $field
     * @return \stdClass
     */
    public static function validateField(AbstractField $field) {
        $errors = array();
        $result = new \stdClass();
        $rules = $field->getRules();
        self::loop($field, $rules, $errors);

        $result->valid = empty($errors);
        $result->trace = $errors;

        return $result;
    }

    /**
     * @param  AbstractField $field
     * @param  array         $rules
     * @param  array         &$errors
     * @return void
     */
    private static function loop(AbstractField $field, array $rules, array &$errors) {
        foreach ($rules as $rule) {
            if ($rule instanceof AbstractRule && $rule->run($field)) {
                $result = $rule->validate($field);
                if (is_bool($result) && $result === false) {
                    $errors[] = $rule->getInvalidMessage();
                } elseif (is_array($result)) {
                    self::loop($field, $result, $errors);
                }
            }
        }

        return;
    }

}
{'fraction_non_alphanumeric': 0.13879598662207357, 'fraction_numerical': 0.0, 'mean_word_length': 1.9800747198007471, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '1818467', 'n_tokens_mistral': 669, 'n_tokens_neox': 644, 'n_words': 153}