<commit_before><?php
namespace SimplyAdmire\CrowdConnector\Crowd;

use Neos\Utility\Arrays;

class Response
{

    /**
     * @var array
     */
    protected $data;

    /**
     * @var array
     */
    protected $responseInfo;

    public function __construct(array $data, array $responseInfo = [])
    {
        $this->data = $data;
        $this->responseInfo = $responseInfo;
    }

    public static function createFromResponseContent($responseBody, array $responseInfo)
    {
        return new static(
            \json_decode($responseBody, true),
            $responseInfo
        );
    }

    /**
     * @return array
     */
    public function getData()
    {
        return $this->data;
    }

    /**
     * @return array
     */
    public function getResponseInfo()
    {
        return $this->responseInfo;
    }

    public function isSuccess()
    {
        return Arrays::getValueByPath($this->responseInfo, 'http_code') === 200;
    }

}
<commit_msg>TASK: Return an empty response if no valid json<commit_after><?php
namespace SimplyAdmire\CrowdConnector\Crowd;

use Neos\Utility\Arrays;

class Response
{

    /**
     * @var array
     */
    protected $data;

    /**
     * @var array
     */
    protected $responseInfo;

    public function __construct(array $data, array $responseInfo = [])
    {
        $this->data = $data;
        $this->responseInfo = $responseInfo;
    }

    public static function createFromResponseContent($responseBody, array $responseInfo)
    {
        $statusCode = Arrays::getValueByPath($responseInfo, 'http_code');

        if ($statusCode === 200) {
            $responseBody = \json_decode($responseBody, true);
            if (\is_array($responseBody)) {
                return new static($responseBody, $responseInfo);
            } else {
                $statusCode = 500;
            }
        }

        return new static([], ['http_code' => $statusCode]);
    }

    /**
     * @return array
     */
    public function getData()
    {
        return $this->data;
    }

    /**
     * @return array
     */
    public function getResponseInfo()
    {
        return $this->responseInfo;
    }

    public function isSuccess()
    {
        return Arrays::getValueByPath($this->responseInfo, 'http_code') === 200;
    }

}

{'fraction_non_alphanumeric': 0.12461873638344227, 'fraction_numerical': 0.00522875816993464, 'mean_word_length': 2.0572569906790945, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '3277021', 'n_tokens_mistral': 687, 'n_tokens_neox': 664, 'n_words': 141}