<commit_before><?php
namespace NamelessCoder\Gizzle;

/**
 * Class JsonDataMapper
 */
abstract class JsonDataMapper {

	/**
	 * @var array
	 */
	protected $propertyMap = array();

	/**
	 * @var array
	 */
	protected $propertyClasses = array();

	/**
	 * @param mixed $jsonData
	 */
	public function __construct($jsonData = array()) {
		$this->map($jsonData);
	}

	/**
	 * @param mixed $jsonData
	 * @return void
	 */
	public function map($jsonData) {
		if (FALSE === is_array($jsonData)) {
			$jsonData = json_decode($jsonData, JSON_OBJECT_AS_ARRAY);
		}
		if (FALSE === is_array($jsonData)) {
			throw new \RuntimeException('Invalid JSON data received by ' . get_class($this), 1411216651);
		}
		foreach ($jsonData as $propertyName => $propertyValue) {
			$propertyName = TRUE === isset($this->propertyMap[$propertyName]) ? $this->propertyMap[$propertyName] : $propertyName;
			$propertyClass = TRUE === isset($this->propertyClasses[$propertyName]) ? $this->propertyClasses[$propertyName] : NULL;
			if (FALSE === property_exists(get_class($this), $propertyName)) {
				continue;
			} elseif (NULL === $propertyClass) {
				$propertyValue = $propertyValue;
			} elseif ('DateTime' === $propertyClass) {
				$propertyValue = new \DateTime($propertyValue);
			} elseif (FALSE === strpos($propertyClass, '[]')) {
				$propertyValue = new $propertyClass($propertyValue);
			} elseif (NULL !== $propertyClass) {
				$className = substr($propertyClass, 0, -2);
				$values = array();
				foreach ($propertyValue as $childObjectData) {
					$values[] = new $className($childObjectData);
				}
				$propertyValue = $values;<commit_msg>[BUGFIX] Create DateTimes using format U, not constructor<commit_after><?php
namespace NamelessCoder\Gizzle;

/**
 * Class JsonDataMapper
 */
abstract class JsonDataMapper {

	/**
	 * @var array
	 */
	protected $propertyMap = array();

	/**
	 * @var array
	 */
	protected $propertyClasses = array();

	/**
	 * @param mixed $jsonData
	 */
	public function __construct($jsonData = array()) {
		$this->map($jsonData);
	}

	/**
	 * @param mixed $jsonData
	 * @return void
	 */
	public function map($jsonData) {
		if (FALSE === is_array($jsonData)) {
			$jsonData = json_decode($jsonData, JSON_OBJECT_AS_ARRAY);
		}
		if (FALSE === is_array($jsonData)) {
			throw new \RuntimeException('Invalid JSON data received by ' . get_class($this), 1411216651);
		}
		foreach ($jsonData as $propertyName => $propertyValue) {
			$propertyName = TRUE === isset($this->propertyMap[$propertyName]) ? $this->propertyMap[$propertyName] : $propertyName;
			$propertyClass = TRUE === isset($this->propertyClasses[$propertyName]) ? $this->propertyClasses[$propertyName] : NULL;
			if (FALSE === property_exists(get_class($this), $propertyName)) {
				continue;
			} elseif (NULL === $propertyClass) {
				$propertyValue = $propertyValue;
			} elseif ('DateTime' === $propertyClass) {
				$propertyValue = \DateTime::createFromFormat('U', $propertyValue);
			} elseif (FALSE === strpos($propertyClass, '[]')) {
				$propertyValue = new $propertyClass($propertyValue);
			} elseif (NULL !== $propertyClass) {
				$className = substr($propertyClass, 0, -2);
				$values = array();
				foreach ($propertyValue as $childObjectData) {
					$values[] = new $className($childObjectData);
				}
				$propertyValue = $values;
{'fraction_non_alphanumeric': 0.16631515516721904, 'fraction_numerical': 0.0072310937029225674, 'mean_word_length': 4.354838709677419, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '4253543', 'n_tokens_mistral': 1133, 'n_tokens_neox': 993, 'n_words': 220}