<commit_before><?php

namespace PHPRtorrentClient;

class Response {

	private $request = null;
	private $response = null;
	private $is_error = false;
	private $error_code = null;
	private $error_string = null;

	public function __construct(Request $request, \GuzzleHttp\Psr7\Response $response) {
		$this->request = $request;
		$this->response = xmlrpc_decode($response->getBody());

		if(isset($this->response->faultcode)) {
			$this->is_error = true;
			$this->error_code = $this->response->faultCode;
			$this->error_string = $this->response->faultString;
		}
	}

	public function __toString() {
		return print_r($this->getLast(),true);
	}

	public function getAll() {
		if($this->is_error) {
			return false;
		}

		$ret = array();
		$methods = $this->request->getMethods();

		foreach($methods as $k => $v) {
			if(count($methods) == 1) {
				$ret[$v->getMethod()] = $this->response;
			} else {
				$ret[$v->getMethod()] = $this->response[$k];
			}
		}
		return $ret;
	}

	public function getMethod($method_name) {
		if($this->is_error) {
			return false;
		}

		$all = $this->getAll();
		return $all[$method_name];
	}

	public function getLast() {
		if($this->is_error) {
			return false;
		}

		$all = $this->getAll();
		return array_pop($all);
	}

	public function isError() {
		return $this->is_error;
	}

	public function getErrorCode() {
		return $this->error_code;
	}

	public function getErrorString() {
		return $this->error_string;
	}
}<commit_msg>fix error response, fix 64 bit integers<commit_after><?php

namespace PHPRtorrentClient;

class Response {

	private $request = null;
	private $response = null;
	private $is_error = false;
	private $error_code = null;
	private $error_string = null;

	public function __construct(Request $request, \GuzzleHttp\Psr7\Response $response) {
		$this->request = $request;
		$body = $this->fixBody($response->getBody());
		$this->response = xmlrpc_decode($body);

		if(array_key_exists('faultCode',$this->response)) {
			$this->is_error = true;
			$this->error_code = $this->response['faultCode'];
			$this->error_string = $this->response['faultString'];
		}
	}

	public function __toString() {
		return print_r($this->getLast(),true);
	}

	public function getAll() {
		if($this->isError()) {
			return false;
		}

		$ret = array();
		$methods = $this->request->getMethods();

		foreach($methods as $k => $v) {
			if(count($methods) == 1) {
				$ret[$v->getMethod()] = $this->response;
			} else {
				$ret[$v->getMethod()] = $this->response[$k];
			}
		}
		return $ret;
	}

	public function getMethod($method_name) {
		if($this->isError()) {
			return false;
		}

		$all = $this->getAll();
		return $all[$method_name];
	}

	public function getLast() {
		if($this->isError()) {
			return false;
		}

		$all = $this->getAll();
		return array_pop($all);
	}

	public function isError() {
		return $this->is_error;
	}

	public function getErrorCode() {
		return $this->error_code;
	}

	public function getErrorString() {
		return $this->error_string;
	}

	private function fixBody($str) {
		// PHP's xmlrpc_decode doesn't support i8 integers, so convert them to string
		$str = preg_replace('#<(/)?i8>#','<\\1string>',$str);
		return $str;
	}
}
{'fraction_non_alphanumeric': 0.17547700969659055, 'fraction_numerical': 0.0028151391929934315, 'mean_word_length': 3.996875, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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': '4021776', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1111, 'n_words': 226}