<commit_before><?php
namespace WEEEOpen\Tarallo;


class Item implements \JsonSerializable {
	private $code;
	private $features = [];
	private $content = [];

	function __construct($code) {
		if(!is_string($code)) {
			throw new \LogicException('Item code must be a string');
		}
		$this->code = $code;
	}

	private static function featureNameIsValid($name) {
		if(is_string($name)) {
			return true;
		} else {
			return false;
		}
	}

	private static function featureValueIsValid($value) {
		// values are all unsigned ints in the database
		if(is_string($value) || (is_int($value) && $value >= 0)) {
			return true;
		} else {
			return false;
		}
	}

	public function addFeature($name, $value) {
		if(!self::featureNameIsValid($name)) {
			throw new \LogicException('Feature name must be a string, ' . gettype($name) . ' given');
		}
		if(!self::featureValueIsValid($value)) {
			throw new \LogicException('Feature value must be a string or positive integer, ' . gettype($name) . ' given');
		}
		if(isset($this->features[$name])) {
			throw new InvalidParameterException('Feature ' . $name . ' already inserted into item ' . (string) $this);
		}

		$this->features[$name] = $value;
		return $this;
	}

	public function addMultipleFeatures($features) {
		if(!is_array($features)) {
			throw new \LogicException('Features must be passed as an array');
		}
		foreach($features as $name => $value) {
			$this->addFeature($name, $value);
		}
		return $this;
	}

	public function addChild(Item $item) {
		$this->content = $item;
	}

	function jsonSerialize() {
		return [
			'code' => $this->code,
			'features' => $this->features,
			'content' => $this->content,
		];
	}
}<commit_msg>toString e setter fluente<commit_after><?php
namespace WEEEOpen\Tarallo;


class Item implements \JsonSerializable {
	private $code;
	private $features = [];
	private $content = [];

	function __construct($code) {
		if(!is_string($code)) {
			throw new \LogicException('Item code must be a string');
		}
		$this->code = $code;
	}

	private static function featureNameIsValid($name) {
		if(is_string($name)) {
			return true;
		} else {
			return false;
		}
	}

	private static function featureValueIsValid($value) {
		// values are all unsigned ints in the database
		if(is_string($value) || (is_int($value) && $value >= 0)) {
			return true;
		} else {
			return false;
		}
	}

	public function addFeature($name, $value) {
		if(!self::featureNameIsValid($name)) {
			throw new \LogicException('Feature name must be a string, ' . gettype($name) . ' given');
		}
		if(!self::featureValueIsValid($value)) {
			throw new \LogicException('Feature value must be a string or positive integer, ' . gettype($name) . ' given');
		}
		if(isset($this->features[$name])) {
			throw new InvalidParameterException('Feature ' . $name . ' already inserted into item ' . (string) $this);
		}

		$this->features[$name] = $value;
		return $this;
	}

	public function addMultipleFeatures($features) {
		if(!is_array($features)) {
			throw new \LogicException('Features must be passed as an array');
		}
		foreach($features as $name => $value) {
			$this->addFeature($name, $value);
		}
		return $this;
	}

	public function addChild(Item $item) {
		$this->content = $item;
		return $this;
	}

	function jsonSerialize() {
		return [
			'code' => $this->code,
			'features' => $this->features,
			'content' => $this->content,
		];
	}

	public function toString() {
		if(isset($this->content['type'])) {
			$type = $this->content['type'];
			return $this->code . " ($type)";
		} else {
			return $this->code;
		}
	}
}
{'fraction_non_alphanumeric': 0.16130835896002235, 'fraction_numerical': 0.0005591277606933184, 'mean_word_length': 3.8351351351351353, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '290349', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1165, 'n_words': 291}