<commit_before><?php
namespace Pinpoint\Siren;

use JsonSerializable;
use InvalidArgumentException;

class Entity implements JsonSerializable
{
    protected $data;

    public function __construct()
    {
        $this->data = array();
    }

    public function setRel(Rel $rel)
    {
        $this->data['rel'] = $rel;
    }

    public function setClass($class)
    {
        $this->data['class'] = array();
        $classes = func_get_args();
        foreach ($classes as $class) {
            $this->addClass($class);
        }
    }

    public function addClass($class)
    {
        if (!isset($this->data['class'])) {
            $this->data['class'] = array();
        }

        if (is_string($class)) {
            $this->data['class'][] = $class;
        } else {
            throw new InvalidArgumentException(
                sprintf(
                    "Invalid Argument %s:%s",
                    __CLASS__,
                    __METHOD__
                )
            );
        }
    }

    public function setProperty($key, $value)
    {
        if (!isset($this->data['properties'])) {
            $this->data['properties'] = array();
        }

        if (is_string($key) && is_scalar($value)) {
            $this->data['properties'][$key] = $value;
        } elseif (is_string($key) && is_array($value)) {
            $this->data['properties'][$key] = $value;
        } else {
            throw new InvalidArgumentException(
                sprintf(
                    "Invalid Argument %s:%s",
                    __CLASS__,
                    __METHOD__
                )
            );
        }
    }<commit_msg>Added the ability for any property that implements JsonSerializable to be able to be added.<commit_after><?php
namespace Pinpoint\Siren;

use JsonSerializable;
use InvalidArgumentException;

class Entity implements JsonSerializable
{
    protected $data;

    public function __construct()
    {
        $this->data = array();
    }

    public function setRel(Rel $rel)
    {
        $this->data['rel'] = $rel;
    }

    public function setClass($class)
    {
        $this->data['class'] = array();
        $classes = func_get_args();
        foreach ($classes as $class) {
            $this->addClass($class);
        }
    }

    public function addClass($class)
    {
        if (!isset($this->data['class'])) {
            $this->data['class'] = array();
        }

        if (is_string($class)) {
            $this->data['class'][] = $class;
        } else {
            throw new InvalidArgumentException(
                sprintf(
                    "Invalid Argument %s:%s",
                    __CLASS__,
                    __METHOD__
                )
            );
        }
    }

    public function setProperty($key, $value)
    {
        if (!isset($this->data['properties'])) {
            $this->data['properties'] = array();
        }

        if (is_string($key) && is_scalar($value)) {
            $this->data['properties'][$key] = $value;
        } elseif (is_string($key) && is_array($value)) {
            $this->data['properties'][$key] = $value;
        } elseif (is_string($key) && $value instanceof JsonSerializable) {
            $this->data['properties'][$key] = $value;
        } else {
            throw new InvalidArgumentException(
                sprintf(
                    "Invalid Argument %s:%s",
                    __CLASS__,
                    __METHOD__
                )
            );
        }
    }
{'fraction_non_alphanumeric': 0.1389762653703174, 'fraction_numerical': 0.0, 'mean_word_length': 1.5911111111111111, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '4014068', 'n_tokens_mistral': 955, 'n_tokens_neox': 920, 'n_words': 191}