<commit_before><?php namespace Elegant;

use Elegant\Helper as Helper;

class Row {

	protected $model = null;

	function __construct(Model $model, $rowObject)
	{
		$this->model = $model;

		$this->model->exists = true;
		$this->model->setData( $rowObject );
	}

	// Getter
	function __get($field)
	{
		// Are we trying to get a related model?
		if(method_exists($this->model, $field))
		{
			// Is it eager loaded?
			$related = $this->model->getRelation($field);
			if($related !== false) return $related;

			$relation = call_user_func(array($this->model, $field));

			$data = $relation->getResults();
			return $data;
		}

		return $this->model->$field;
	}

	// Setter
	function __set($field, $value)
	{
		$this->model->$field = $value;
	}

	function __call($name, $arguments)
	{
		if(method_exists($this->model, $name))
			return call_user_func_array(array($this->model, $name), $arguments);
	}

	function __toString()
	{
		$json = array();

		foreach($this->model->getData() as $field => $value)
			$json[$field] = $this->{$field};

		return $json;
	}

	function save()
	{
		return $this->model->save();
	}<commit_msg>Fix getter to return blank array so foreach will not show warnings<commit_after><?php namespace Elegant;

use Elegant\Helper as Helper;

class Row {

	protected $model = null;

	function __construct(Model $model, $rowObject)
	{
		$this->model = $model;

		$this->model->exists = true;
		$this->model->setData( $rowObject );
	}

	// Getter
	function __get($field)
	{
		// Are we trying to get a related model?
		if(method_exists($this->model, $field))
		{
			// Is it eager loaded?
			$related = $this->model->getRelation($field);
			if($related !== null) return $related;

			$relation = call_user_func(array($this->model, $field));

			$data = $relation->getResults();
			return $data ?: array();
		}

		return $this->model->$field;
	}

	// Setter
	function __set($field, $value)
	{
		$this->model->$field = $value;
	}

	function __call($name, $arguments)
	{
		if(method_exists($this->model, $name))
			return call_user_func_array(array($this->model, $name), $arguments);
	}

	function __toString()
	{
		$json = array();

		foreach($this->model->getData() as $field => $value)
			$json[$field] = $this->{$field};

		return $json;
	}

	function save()
	{
		return $this->model->save();
	}
{'fraction_non_alphanumeric': 0.18071768266320795, 'fraction_numerical': 0.0, 'mean_word_length': 3.8208333333333333, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '6381932', 'n_tokens_mistral': 896, 'n_tokens_neox': 812, 'n_words': 182}