<commit_before><?php
namespace Mivir\Pupil;

class ValidationResult
implements ValidationResultInterface, \Iterator
{
	protected $position = 0;

	protected $results = array();

	public function __construct($results)
	{
		foreach ($results as $field => $result) {
			$this->results[] = array($field, $result);
		}
	}

	public function isValid()
	{
		foreach ($this->results as $result) {
			if ( ! $result[1]) return false;
		}

		return true;
	}

	public function hasErrors()
	{
		return ! $this->isValid();
	}

	/**
	 * Return fields with validation errors.
	 *
	 * @return  array  An array of fields with validation errors
	 */
	public function errors()
	{
		$errors = array();

		foreach ($this->results as $result) {
			if ( ! $result[1]) {
				$errors[] = $result[0];
			}
		}

		return $errors;
	}

	/**
	 * Returns the validated fields.
	 *
	 * @return  array  An array containing the validated fields
	 */
	public function getFields()
	{
		$fields = array();

		foreach ($this->results as $result) {
			$fields[$result[0]] = $result[1];
		}

		return $fields;
	}

	/**
	 * Iterator methods
	 */

	public function rewind()
	{
		$this->position = 0;
	}

	public function current()
	{
		$thisResult = $this->results[$this->position];
		return array($thisResult[0] => $thisResult[1]);
	}

	public function key()
	{
		return $this->position;
	}

	public function next()
	{
		$this->position++;
	}

	public function valid()
	{
		return isset($this->results[$this->position]);
	}
}<commit_msg>Fix a bug in the ValidationResults class that caused it to not return the key and value as expected when iterating the object with e.g. foreach.<commit_after><?php
namespace Mivir\Pupil;

class ValidationResult
implements ValidationResultInterface, \Iterator
{
	protected $position = 0;

	protected $results = array();

	public function __construct($results)
	{
		foreach ($results as $field => $result) {
			$this->results[] = array($field, $result);
		}
	}

	public function isValid()
	{
		foreach ($this->results as $result) {
			if ( ! $result[1]) return false;
		}

		return true;
	}

	public function hasErrors()
	{
		return ! $this->isValid();
	}

	/**
	 * Return fields with validation errors.
	 *
	 * @return  array  An array of fields with validation errors
	 */
	public function errors()
	{
		$errors = array();

		foreach ($this->results as $result) {
			if ( ! $result[1]) {
				$errors[] = $result[0];
			}
		}

		return $errors;
	}

	/**
	 * Returns the validated fields.
	 *
	 * @return  array  An array containing the validated fields
	 */
	public function getFields()
	{
		$fields = array();

		foreach ($this->results as $result) {
			$fields[$result[0]] = $result[1];
		}

		return $fields;
	}

	/**
	 * Iterator methods
	 */

	public function rewind()
	{
		$this->position = 0;
	}

	public function current()
	{
		return $this->results[$this->position][1];
	}

	public function key()
	{
		return $this->results[$this->position][0];
	}

	public function next()
	{
		$this->position++;
	}

	public function valid()
	{
		return isset($this->results[$this->position]);
	}
}
{'fraction_non_alphanumeric': 0.1520752269779507, 'fraction_numerical': 0.005836575875486381, 'mean_word_length': 3.338959212376934, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '6943292', 'n_tokens_mistral': 1119, 'n_tokens_neox': 989, 'n_words': 274}