<commit_before><?php
/**
 * Created by PhpStorm.
 * User: <NAME>
 * Date: 30.12.2018
 * Time: 01:09
 */

namespace Exodus4D\ESI\Lib\Stream;


use GuzzleHttp\Psr7\StreamDecoratorTrait;
use Psr\Http\Message\StreamInterface;

class JsonStream implements StreamInterface {

    // we need to "overwrite" the default Trait getContents() method
    // -> therefore we make it accessible as traitGetContents() and call it from
    // the new getContents() method
    use StreamDecoratorTrait {
        StreamDecoratorTrait::getContents as traitGetContents;
    }

    /**
     * @return mixed|string|null
     */
    public function getContents(){
        $contents = (string) $this->traitGetContents();

        if($contents === ''){
            return null;
        }
        $decodedContents = \GuzzleHttp\json_decode($contents);

        if(json_last_error() !== JSON_ERROR_NONE){
            throw new \RuntimeException('Error trying to decode response: ' . json_last_error_msg());
        }

        return $decodedContents;
    }
}<commit_msg>- added Guzzle "RetryMiddleware" to Api calls - implemented "Monolog" logging for "Guzzle" Api calls<commit_after><?php
/**
 * Created by PhpStorm.
 * User: <NAME>
 * Date: 30.12.2018
 * Time: 01:09
 */

namespace Exodus4D\ESI\Lib\Stream;


use GuzzleHttp\Psr7\StreamDecoratorTrait;
use Psr\Http\Message\StreamInterface;

class JsonStream implements StreamInterface {

    // we need to "overwrite" the default Trait getContents() method
    // -> therefore we make it accessible as traitGetContents() and call it from
    // the new getContents() method
    use StreamDecoratorTrait {
        StreamDecoratorTrait::getContents as traitGetContents;
    }

    /**
     * @return mixed|string|null
     */
    public function getContents(){
        $contents = $this->traitGetContents();

        if($contents === ''){
            return null;
        }
        $decodedContents = \GuzzleHttp\json_decode($contents);

        if(json_last_error() !== JSON_ERROR_NONE){
            throw new \RuntimeException('Error trying to decode response: ' . json_last_error_msg());
        }

        return $decodedContents;
    }

    /**
     * we need to overwrite this because of Trait __toString() calls $this->Contents() which no longer returns a string
     * @return string
     */
    public function __toString(){
        try {
            if ($this->isSeekable()) {
                $this->seek(0);
            }
            return $this->traitGetContents();
        } catch (\Exception $e) {
            // Really, PHP? https://bugs.php.net/bug.php?id=53648
            trigger_error('StreamDecorator::__toString exception: '
                . (string) $e, E_USER_ERROR);
            return '';
        }
    }
}
{'fraction_non_alphanumeric': 0.11724137931034483, 'fraction_numerical': 0.012341197822141561, 'mean_word_length': 2.510828025477707, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 1, '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': '3075857', 'n_tokens_mistral': 830, 'n_tokens_neox': 790, 'n_words': 200}