<commit_before><?php

namespace Layer\Data\TableData;

class StringifierDecorator implements TableDataDecoratorInterface {

	public function decorateColumns(array $columns) {
		return $columns;
	}

	/**
	 * @param $value
	 * @param $key
	 * @param $object
	 * @return string
	 */
	public function decorateData($value, $key, $object) {
		if(is_array($value)) {
			$value = '[ARRAY]';
		} elseif(is_object($value) && !method_exists($value, '__toString')) {
			if($value instanceof \DateTime) {
				$value = $this->formatDateTime($value);
			} else {
				$value = sprintf('[OBJECT:%s]', get_class($value));
			}
		}
		if(!settype($value, 'string')) {
			return '';
		}
		return $value;
	}

	protected function formatDateTime(\DateTime $dateTime) {
		return $dateTime->format('Y-m-d H:i:s');
	}

}<commit_msg>Improved stringifier<commit_after><?php

namespace Layer\Data\TableData;

class StringifierDecorator implements TableDataDecoratorInterface {

	public function decorateColumns(array $columns) {
		return $columns;
	}

	/**
	 * @param $value
	 * @param $key
	 * @param $object
	 * @return string
	 */
	public function decorateData($value, $key, $object) {
		return $this->stringify($value);
	}

	protected function stringify($value, $force = true) {
		if(is_array($value)) {
			return $this->stringifyArray($value);
		} elseif(is_object($value) && !method_exists($value, '__toString')) {
			if($value instanceof \DateTime) {
				return $this->formatDateTime($value);
			} else {
				return $force ? sprintf('[OBJECT:%s]', get_class($value)) : false;
			}
		}
		if(!settype($value, 'string')) {
			return $force ? '' : false;
		}
		return $value;
	}

	protected function stringifyArray(array $array, $force = true) {
		$parts = [];
		foreach($array as $part) {
			$part = $this->stringify($part, false);
			if(!is_string($part)) {
				return $force ? '[ARRAY]' : false;
			}
			$parts[] = $part;
		}
		return implode(', ', $parts);
	}

	protected function formatDateTime(\DateTime $dateTime) {
		return $dateTime->format('Y-m-d H:i:s');
	}

}
{'fraction_non_alphanumeric': 0.17221135029354206, 'fraction_numerical': 0.0, 'mean_word_length': 4.177215189873418, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '2001382', 'n_tokens_mistral': 762, 'n_tokens_neox': 680, 'n_words': 141}