<commit_before><?php

class DutyCalculator_Response
{
	protected $_responseXML;

	public function __construct($responseXML)
	{
		$this->_responseXML = $responseXML;
		$this->checkError();
	}

	/**
	 * @return string
	 */
	public function getAsXML()
	{
		return $this->_responseXML;
	}

	/**
	 * @return array
	 */
	public function getAsArray()
	{
		$root = simplexml_load_string($this->_responseXML);
		$result = $this->convertToArray($root);
		return $result;
	}

	private function convertToArray(SimpleXMLElement $node)
	{
		$result = array();
		$nodeData = array();

		foreach($node->attributes() as $attribute)
		{
			$nodeData[$attribute->getName()] = (string)$attribute;
		}
		if ($node->count())
		{
			$nodeData['node-value'] = array();
			foreach ($node as $child)
			{
				$nodeData['node-value'][] = $this->convertToArray($child);
			}
		}
		else
		{
			$value = trim((string)$node);
			if ($value)
			{
				$nodeData['node-value'] = $value;
			}
		}
		$result[$node->getName()] = $nodeData;
		return $result;
	}

	/**
	 * @return string
	 */
	public function getAsJSON()
	{
		$result = $this->getAsArray();
		return json_encode($result);
	}

	private function checkError()
	{
		if (stripos($this->_responseXML, '<?xml') === false)
		{
			throw new DutyCalculator_Exception('Response is not a valid XML.', 0);
		}
		else
		{
			$xml = simplexml_load_string($this->_responseXML);
			if (isset($xml->code) && (string)$xml->code)
			{
				throw new DutyCalculator_Exception((string)$xml->message, (string)$xml->code);
			}
		}
	}
}<commit_msg>Little fix for response<commit_after><?php

class DutyCalculator_Response
{
	protected $_responseXML;

	public function __construct($responseXML)
	{
		$this->_responseXML = $responseXML;
		$this->checkError();
	}

	/**
	 * @return string
	 */
	public function getAsXML()
	{
		return $this->_responseXML;
	}

	/**
	 * @return array
	 */
	public function getAsArray()
	{
		$root = simplexml_load_string($this->_responseXML);
		$result = $this->convertToArray($root);
		return $result;
	}

	private function convertToArray(SimpleXMLElement $node)
	{
		$result = array();
		$nodeData = array();

		foreach($node->attributes() as $attribute)
		{
			$nodeData[$attribute->getName()] = (string)$attribute;
		}
		if ($node->count())
		{
			$nodeData['node-value'] = array();
			foreach ($node as $child)
			{
				$nodeData['node-value'][] = $this->convertToArray($child);
			}
		}
		else
		{
			$value = trim((string)$node);
			$nodeData['node-value'] = $value;
		}
		$result[$node->getName()] = $nodeData;
		return $result;
	}

	/**
	 * @return string
	 */
	public function getAsJSON()
	{
		$result = $this->getAsArray();
		return json_encode($result);
	}

	private function checkError()
	{
		if (stripos($this->_responseXML, '<?xml') === false)
		{
			throw new DutyCalculator_Exception('Response is not a valid XML.', 0);
		}
		else
		{
			$xml = simplexml_load_string($this->_responseXML);
			if (isset($xml->code) && (string)$xml->code)
			{
				throw new DutyCalculator_Exception((string)$xml->message, (string)$xml->code);
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.17854828256642905, 'fraction_numerical': 0.0006480881399870382, 'mean_word_length': 3.778637770897833, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, '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': '3939861', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1060, 'n_words': 197}