<commit_before><?php
/**
 * This file is part of the NeedleProject\FileIo package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace NeedleProject\FileIo\Content;

use NeedleProject\FileIo\Exception\ContentException;

/**
 * Class JsonContent
 *
 * @package NeedleProject\FileIo\Content
 * @author <NAME> <<EMAIL>>
 * @copyright 2017 <NAME>
 * @license https://opensource.org/licenses/MIT MIT Licence
 */
class JsonContent extends Content implements ContentInterface
{
    /**
     * Return the content as an array
     *
     * @return array
     * @throws \NeedleProject\FileIo\Exception\ContentException
     */
    public function getArray(): array
    {
        $content = json_decode($this->get(), true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new ContentException(
                sprintf("Could not decode content, got %s", json_last_error_msg())
            );
        }
        return $content;
    }

    /**
     * @return \stdClass
     * @throws \NeedleProject\FileIo\Exception\ContentException
     */
    public function getObject()
    {
        $content = json_decode($this->get());
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new ContentException(
                sprintf("Could not decode content, got %s", json_last_error_msg())
            );
        }
        return $content;
    }
}
<commit_msg>Small refactor in JsonContent<commit_after><?php
/**
 * This file is part of the NeedleProject\FileIo package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace NeedleProject\FileIo\Content;

use NeedleProject\FileIo\Exception\ContentException;

/**
 * Class JsonContent
 *
 * @package NeedleProject\FileIo\Content
 * @author <NAME> <<EMAIL>>
 * @copyright 2017 <NAME>
 * @license https://opensource.org/licenses/MIT MIT Licence
 */
class JsonContent extends Content implements ContentInterface
{
    /**
     * Return the content as an array
     *
     * @return array
     * @throws \NeedleProject\FileIo\Exception\ContentException
     */
    public function getArray(): array
    {
        return $this->decodeJson(true);
    }

    /**
     * @return \stdClass
     * @throws \NeedleProject\FileIo\Exception\ContentException
     */
    public function getObject()
    {
        return $this->decodeJson();
    }

    /**
     * @param bool $asArray
     * @return mixed
     * @throws \NeedleProject\FileIo\Exception\ContentException
     */
    private function decodeJson(bool $asArray = false)
    {
        $content = json_decode($this->get(), $asArray);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new ContentException(
                sprintf("Could not decode content, got %s", json_last_error_msg())
            );
        }
        return $content;
    }
}

{'fraction_non_alphanumeric': 0.11054937647455342, 'fraction_numerical': 0.002696326255476913, 'mean_word_length': 2.6195121951219513, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 2, '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': '1434311', 'n_tokens_mistral': 827, 'n_tokens_neox': 817, 'n_words': 218}