<commit_before><?php namespace DoubleOptIn\ClientApi\Client\Commands\Responses;

use DoubleOptIn\ClientApi\Client\Commands\Responses\Limiter\RateLimit;
use Guzzle\Http\Message\Response;
use stdClass;

/**
 * Class CommandResponse
 *
 * Base class for command responses
 *
 * @package DoubleOptIn\ClientApi\Client\Commands\Responses
 */
abstract class CommandResponse
{
	/**
	 * original response
	 *
	 * @var Response
	 */
	private $response;

	/**
	 * limiter
	 *
	 * @var RateLimit
	 */
	private $limiter;

	/**
	 * return json decoded \stdClass
	 *
	 * @var stdClass
	 */
	private $json;

	/**
	 * @param Response $response
	 */
	public function __construct(Response $response)
	{
		$this->response = $response;

		$this->limiter = new RateLimit($response->getHeaders());
	}

	/**
	 * returns decoded object
	 *
	 * @return null|stdClass
	 */
	protected function decoded()
	{
		if ($this->json === null) {
			/** @var \Guzzle\Http\Message\Header $contentType */
			$contentType = (string)$this->response->getHeader('content-type');
			if ($contentType === 'application/json')
				$this->json = json_decode($this->response->getBody(true));
		}

		return $this->json;
	}

	/**
	 * returns limiter
	 *
	 * @return RateLimit
	 */
	public function limiter()
	{
		return $this->limiter;
	}

	/**
	 * command failed?
	 *
	 * @return bool
	 */
	public function fails()
	{
		return $this->response->getStatusCode() >= 300;
	}

	/**
	 * returns the error message
	 *
	 * @return string
	 */
	public function errorMessage()
	{
		$message = sprintf('%s (%s)', $this->decoded()->message, $this->statusCode());

		if (isset($this->decoded()->errors)) {
			$errors = $this->decoded()->errors;

			$message .= $this->resolveAttributes($errors);<commit_msg>fixing command  returned empty server response<commit_after><?php namespace DoubleOptIn\ClientApi\Client\Commands\Responses;

use DoubleOptIn\ClientApi\Client\Commands\Responses\Limiter\RateLimit;
use Guzzle\Http\Message\Response;
use stdClass;

/**
 * Class CommandResponse
 *
 * Base class for command responses
 *
 * @package DoubleOptIn\ClientApi\Client\Commands\Responses
 */
abstract class CommandResponse
{
	/**
	 * original response
	 *
	 * @var Response
	 */
	private $response;

	/**
	 * limiter
	 *
	 * @var RateLimit
	 */
	private $limiter;

	/**
	 * return json decoded \stdClass
	 *
	 * @var stdClass
	 */
	private $json;

	/**
	 * @param Response $response
	 */
	public function __construct(Response $response)
	{
		$this->response = $response;

		$this->limiter = new RateLimit($response->getHeaders());
	}

	/**
	 * returns decoded object
	 *
	 * @return null|stdClass
	 */
	protected function decoded()
	{
		if ($this->json === null) {
			/** @var \Guzzle\Http\Message\Header $contentType */
			$contentType = (string)$this->response->getHeader('content-type');
			if ($contentType === 'application/json')
				$this->json = json_decode($this->response->getBody(true));
		}

		return $this->json;
	}

	/**
	 * returns limiter
	 *
	 * @return RateLimit
	 */
	public function limiter()
	{
		return $this->limiter;
	}

	/**
	 * command failed?
	 *
	 * @return bool
	 */
	public function fails()
	{
		return $this->response->getStatusCode() >= 300;
	}

	/**
	 * returns the error message
	 *
	 * @return string
	 */
	public function errorMessage()
	{
		if ($this->decoded() === null) {
			throw new \RuntimeException('No result from server.');
		}

		$message = sprintf('%s (%s)', $this->decoded()->message, $this->statusCode());

		if (isset($this->decoded()->errors)) {
			$errors = $this->decoded()->errors;

			$message .= $this->resolveAttributes($errors);
{'fraction_non_alphanumeric': 0.16560685651092066, 'fraction_numerical': 0.0016588332872546309, 'mean_word_length': 3.466666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 48, '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': '5929791', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1132, 'n_words': 241}