<commit_before><?php

/**
 * This file is part of the Hayttp package.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2017
 * @license MIT
 */

namespace Hayttp\Payloads;

use Hayttp\Traits\Common\DebugInfo;
use Hayttp\Contracts\Payload as PayloadContract;

/**
 * Raw (string) body Helper.
 */
class JsonPayload implements PayloadContract
{
    use DebugInfo;

    /**
     * @var array|object
     */
    protected $contents;

    /**
     * @var string
     */
    protected $contentType = 'application/json';

    /**
     * Constructor.
     *
     * @param array|object $contents
     * @param string       $contentType
     */
    public function __construct($contents, $contentType = 'application/json')
    {
        $this->contents = $contents;
        $this->contentType = (string) $contentType;
    }

    /**
     * The Content-Type header to use when sending this payload.
     *
     * @return string
     */
    public function contentType()
    {
        return $this->contentType;
    }

    /**
     * Render into a http request body.
     */
    public function render()
    {
        return json_encode($this->contents, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    }
<commit_msg>More robust json implementation<commit_after><?php

/**
 * This file is part of the Hayttp package.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2017
 * @license MIT
 */

namespace Hayttp\Payloads;

use InvalidArgumentException;
use Hayttp\Traits\Common\DebugInfo;
use Hayttp\Contracts\Payload as PayloadContract;

/**
 * Raw (string) body Helper.
 */
class JsonPayload implements PayloadContract
{
    use DebugInfo;

    /**
     * @var array|object
     */
    protected $contents;

    /**
     * @var string
     */
    protected $contentType = 'application/json';

    /**
     * Constructor.
     *
     * @param array|object $contents
     * @param string       $contentType
     */
    public function __construct($contents, $contentType = 'application/json')
    {
        if (!(is_array($contents) || is_object($contents))) {
            throw new InvalidArgumentException('Contents must be array or object');
        }

        $this->contents = $contents;
        $this->contentType = (string) $contentType;
    }

    /**
     * The Content-Type header to use when sending this payload.
     *
     * @return string
     */
    public function contentType()
    {
        return $this->contentType;
    }

    /**
     * Render into a http request body.
     *
     * @return string The json-encoded contents
     */
    public function render()
    {
        return json_encode($this->contents);
    }

{'fraction_non_alphanumeric': 0.12009149828440717, 'fraction_numerical': 0.0030499428135722455, 'mean_word_length': 2.3384223918575064, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '4305319', 'n_tokens_mistral': 779, 'n_tokens_neox': 757, 'n_words': 197}