<commit_before><?php

namespace App\Entity;

use Illuminate\Support\Str;
use RuntimeException;

/**
 * Base DataSet Row.
 */
abstract class AbstractEntity implements EntityInterface
{
    /**
     * Constructor.
     *
     * BaseEntity constructor.
     *
     * @param mixed $values
     */
    public function __construct($values = null)
    {
        if ($values) {
            $this->fromArray((array) $values);
        }
    }

    /**
     * Hydrate array to object.
     *
     * @param array $source
     *
     * @return self $destination
     */
    private function fromArray(array $source)
    {
        $properties = array_fill_keys(array_keys((array) get_object_vars($this)), 1);

        foreach ($source as $name => $value) {
            $property = Str::camel($name);
            if (isset($properties[$property])) {
                $this->{$property} = $value;
            }
        }

        return $this;
    }

    /**
     * Magic method.
     *
     * @param string $name
     *
     * @throws RuntimeException
     */
    public function __get($name)
    {
        throw new RuntimeException(sprintf("Property [%s] doesn't exist for class [%s].", $name, get_class($this)));
    }

    /**
     * Magic method.
     *
     * @param string $name
     * @param mixed $value
     *
     * @throws RuntimeException
     */
    public function __set($name, $value)
    {
        throw new RuntimeException(sprintf("Property [%s] doesn't exist for class [%s]. Cannot set value [%s].", $name, get_class($this), $value));
    }

    /**
     * Convert to array.
     *
     * @return array Data
     */
    public function toArray(): array
    {
        $array = [];
        $properties = get_object_vars($this);

        foreach ($properties as $property => $value) {
            $array[Str::snake($property)] = $this->{$property};
        }

        return $array;
    }
}
<commit_msg>Optimized performance<commit_after><?php

namespace App\Entity;

use Illuminate\Support\Str;
use RuntimeException;

/**
 * Base DataSet Row.
 */
abstract class AbstractEntity implements EntityInterface
{
    /**
     * Constructor.
     *
     * @param mixed $data Data
     */
    public function __construct($data = null)
    {
        if ($data) {
            $this->fromArray((array) $data);
        }
    }

    /**
     * Hydrate array to object.
     *
     * @param array $data Data
     *
     * @return self
     */
    protected function fromArray(array $data)
    {
        foreach ($data as $name => $value) {
            $property = Str::camel($name);
            if (property_exists($this, $property)) {
                $this->{$property} = $value;
            }
        }

        return $this;
    }

    /**
     * Magic method.
     *
     * @param string $name
     *
     * @throws RuntimeException
     */
    public function __get($name)
    {
        throw new RuntimeException(sprintf("Property [%s] doesn't exist for class [%s].", $name, get_class($this)));
    }

    /**
     * Magic method.
     *
     * @param string $name
     * @param mixed $value
     *
     * @throws RuntimeException
     */
    public function __set($name, $value)
    {
        throw new RuntimeException(sprintf("Property [%s] doesn't exist for class [%s]. Cannot set value [%s].", $name, get_class($this), $value));
    }

    /**
     * Convert to array.
     *
     * @return array Data
     */
    public function toArray(): array
    {
        $array = [];
        $properties = get_object_vars($this);

        foreach ($properties as $property => $value) {
            $array[Str::snake($property)] = $this->{$property};
        }

        return $array;
    }
}

{'fraction_non_alphanumeric': 0.14130434782608695, 'fraction_numerical': 0.0002717391304347826, 'mean_word_length': 1.9052880820836622, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '4125920', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1079, 'n_words': 265}