<commit_before><?php
namespace Atlas\Orm\Mapper;

use Atlas\Orm\Exception;
use Atlas\Orm\Table\Row;

class Record implements RecordInterface
{
    private $row;
    private $related;
    private $mapperClass;

    public function __construct($mapperClass, Row $row, Related $related)
    {
        $this->mapperClass = $mapperClass;
        $this->row = $row;
        $this->related = $related;
    }

    public function __get($field)
    {
        if ($this->row->has($field)) {
            return $this->row->$field;
        }

        if ($this->related->has($field)) {
            return $this->related->$field;
        }

        throw Exception::propertyDoesNotExist($this, $field);
    }

    public function __set($field, $value)
    {
        if ($this->row->has($field)) {
            $this->row->$field = $value;
            return;
        }

        if ($this->related->has($field)) {
            $this->related->$field = $value;
            return;
        }

        throw Exception::propertyDoesNotExist($this, $field);
    }

    public function __isset($field)
    {
        if ($this->row->has($field)) {
            return isset($this->row->$field);
        }

        if ($this->related->has($field)) {
            return isset($this->related->$field);
        }

        throw Exception::propertyDoesNotExist($this, $field);
    }

    public function __unset($field)
    {
        if ($this->row->has($field)) {
            unset($this->row->$field);
            return;
        }

        if ($this->related->has($field)) {
            unset($this->related->$field);
            return;
        }

        throw Exception::propertyDoesNotExist($this, $field);
    }

    public function getMapperClass()
    {
        return $this->mapperClass;
    }

    public function has($field)
    {
        return $this->row->has($field)
            || $this->related->has($field);
    }

    public function getRow()
    {
        return $this->row;
    }

    public function getRelated()
    {
        return $this->related;
    }

    public function getArrayCopy()
    {
        // use +, not array_merge(), so row takes precedence over related
        return $this->row->getArrayCopy()
             + $this->related->getArrayCopy();
    }
}<commit_msg>consolidate has-field logic<commit_after><?php
namespace Atlas\Orm\Mapper;

use Atlas\Orm\Exception;
use Atlas\Orm\Table\Row;

class Record implements RecordInterface
{
    private $row;
    private $related;
    private $mapperClass;

    public function __construct($mapperClass, Row $row, Related $related)
    {
        $this->mapperClass = $mapperClass;
        $this->row = $row;
        $this->related = $related;
    }

    public function __get($field)
    {
        $prop = $this->assertHas($field);
        return $this->$prop->$field;
    }

    public function __set($field, $value)
    {
        $prop = $this->assertHas($field);
        $this->$prop->$field = $value;
    }

    public function __isset($field)
    {
        $prop = $this->assertHas($field);
        return isset($this->$prop->$field);
    }

    public function __unset($field)
    {
        $prop = $this->assertHas($field);
        unset($this->$prop->$field);
    }

    public function getMapperClass()
    {
        return $this->mapperClass;
    }

    public function has($field)
    {
        return $this->row->has($field)
            || $this->related->has($field);
    }

    public function getRow()
    {
        return $this->row;
    }

    public function getRelated()
    {
        return $this->related;
    }

    public function getArrayCopy()
    {
        // use +, not array_merge(), so row takes precedence over related
        return $this->row->getArrayCopy()
             + $this->related->getArrayCopy();
    }

    public function assertHas($field)
    {
        if ($this->row->has($field)) {
            return 'row';
        }

        if ($this->related->has($field)) {
            return 'related';
        }

        throw Exception::propertyDoesNotExist($this, $field);
    }
}
{'fraction_non_alphanumeric': 0.15036855036855037, 'fraction_numerical': 0.0, 'mean_word_length': 2.008869179600887, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 79, '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': '474330', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1197, 'n_words': 235}