<commit_before><?php
namespace Spot;

/**
* Entity object
*
* @package Spot
*/
abstract class Entity
{
    protected static $table;
    protected static $tableOptions = [];
    protected static $mapper = false;

    protected $_objectId;

    // Entity data storage
    protected $_data = [];
    protected $_dataModified = [];
    protected $_relations = [];

    // Entity state
    protected $_isNew = true;
    protected $_inGetter = [];
    protected $_inSetter = [];

    // Entity error messages (may be present after save attempt)
    protected $_errors = [];

    /**
     * Constructor - allows setting of object properties with array on construct
     */
    public function __construct(array $data = array())
    {
        // Generate Unique object ID
        $this->_objectId = uniqid('entity_', true) . spl_object_hash($this);

        $this->initFields();

        // Set given data
        if ($data) {
            $this->data($data, false);
        }
    }

    /**
     * Set all field values to their defualts or null
     */
    protected function initFields()
    {
        $fields = static::fields();
        foreach ($fields as $field => $opts) {
            if (!isset($this->_data[$field])) {
                $this->_data[$field] = isset($opts['value']) ? $opts['value'] : null;
            }
        }
    }

    /**
     * Table name getter/setter
     */
    public static function table($tableName = null)
    {
        if (null !== $tableName) {
            static::$table = $tableName;

            return $this;
        }

        return static::$table;
    }

    /**
     * Datasource options getter/setter
     */
    public static function tableOptions($tableOpts = null)
    {
        if (null !== $tableOpts) {
            static::$tableOptions = $tableOpts;

            return $this;
        }

        return static::$tableOptions;
    }

    /**
     * Mapper name getter
     */
    public static function mapper()
    {
        return static::$mapper;
    }

    /**
     * Return defined fields of the entity
     */
    public static function fields()
    {
        return [];
    }

    /**
     * Add events to this entity
     */
    public static function events(EventEmitter $eventEmitter) { }

    /**
     * Return defined fields of the entity
     */
    public static function relations(Mapper $mapper, self $entity)
    {
        return [];
    }

    /**
     * Return scopes defined by this entity. Scopes are called from the
     * Spot\Query object as a sort of in-context dynamic query method
     */
    public static function scopes()
    {
        return [];
    }

    /**
     * Gets and sets data on the current entity
     */
    public function data($data = null, $modified = true)
    {
        // GET
        if (null === $data || !$data) {
            $data = array_merge($this->_data, $this->_dataModified);
            foreach ($data as $k => &$v) {
                $v = $this->__get($k, $v);
            }

            return $data;
        }

        // SET
        if (is_object($data) || is_array($data)) {
            $fields = $this->fields();
            foreach ($data as $k => $v) {
                $this->set($k, $v, $modified);
            }

            return $this;
        } else {
            throw new \InvalidArgumentException(__METHOD__ . " Expected array or object input - " . gettype($data) . " given");
        }
    }
<commit_msg>Fix #13 - Remove superfluous call to fields<commit_after><?php
namespace Spot;

/**
* Entity object
*
* @package Spot
*/
abstract class Entity
{
    protected static $table;
    protected static $tableOptions = [];
    protected static $mapper = false;

    protected $_objectId;

    // Entity data storage
    protected $_data = [];
    protected $_dataModified = [];
    protected $_relations = [];

    // Entity state
    protected $_isNew = true;
    protected $_inGetter = [];
    protected $_inSetter = [];

    // Entity error messages (may be present after save attempt)
    protected $_errors = [];

    /**
     * Constructor - allows setting of object properties with array on construct
     */
    public function __construct(array $data = array())
    {
        // Generate Unique object ID
        $this->_objectId = uniqid('entity_', true) . spl_object_hash($this);

        $this->initFields();

        // Set given data
        if ($data) {
            $this->data($data, false);
        }
    }

    /**
     * Set all field values to their defualts or null
     */
    protected function initFields()
    {
        $fields = static::fields();
        foreach ($fields as $field => $opts) {
            if (!isset($this->_data[$field])) {
                $this->_data[$field] = isset($opts['value']) ? $opts['value'] : null;
            }
        }
    }

    /**
     * Table name getter/setter
     */
    public static function table($tableName = null)
    {
        if (null !== $tableName) {
            static::$table = $tableName;

            return $this;
        }

        return static::$table;
    }

    /**
     * Datasource options getter/setter
     */
    public static function tableOptions($tableOpts = null)
    {
        if (null !== $tableOpts) {
            static::$tableOptions = $tableOpts;

            return $this;
        }

        return static::$tableOptions;
    }

    /**
     * Mapper name getter
     */
    public static function mapper()
    {
        return static::$mapper;
    }

    /**
     * Return defined fields of the entity
     */
    public static function fields()
    {
        return [];
    }

    /**
     * Add events to this entity
     */
    public static function events(EventEmitter $eventEmitter) { }

    /**
     * Return defined fields of the entity
     */
    public static function relations(Mapper $mapper, self $entity)
    {
        return [];
    }

    /**
     * Return scopes defined by this entity. Scopes are called from the
     * Spot\Query object as a sort of in-context dynamic query method
     */
    public static function scopes()
    {
        return [];
    }

    /**
     * Gets and sets data on the current entity
     */
    public function data($data = null, $modified = true)
    {
        // GET
        if (null === $data || !$data) {
            $data = array_merge($this->_data, $this->_dataModified);
            foreach ($data as $k => &$v) {
                $v = $this->__get($k, $v);
            }

            return $data;
        }

        // SET
        if (is_object($data) || is_array($data)) {
            foreach ($data as $k => $v) {
                $this->set($k, $v, $modified);
            }

            return $this;
        } else {
            throw new \InvalidArgumentException(__METHOD__ . " Expected array or object input - " . gettype($data) . " given");
        }
    }

{'fraction_non_alphanumeric': 0.12885317750182615, 'fraction_numerical': 0.00029218407596785974, 'mean_word_length': 1.7505022097227803, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '2086921', 'n_tokens_mistral': 1906, 'n_tokens_neox': 1868, 'n_words': 544}