<commit_before><?php

namespace GuzzleHttp\Stream;

/**
 * Stream decorator trait
 */
trait StreamDecoratorTrait
{
    /** @var StreamInterface Decorated stream */
    private $stream;

    /**
     * @param StreamInterface $stream Stream to decorate
     */
    public function __construct(StreamInterface $stream)
    {
        $this->stream = $stream;
    }

    public function __toString()
    {
        try {
            $this->seek(0);
            return $this->getContents();
        } catch (\Exception $e) {
            // Really, PHP? https://bugs.php.net/bug.php?id=53648
            trigger_error('StreamDecorator::__toString exception: ' . (string) $e, E_USER_ERROR);
            return '';
        }
    }

    public function getContents($maxLength = -1)
    {
        $buffer = '';

        while (!$this->eof()) {
            if ($maxLength === -1) {
                $read = 1048576;
            } else {
                $len = strlen($buffer);
                if ($len == $maxLength) {
                    break;
                }
                $read = min(1048576, $maxLength - $len);
            }
            $buffer .= $this->read($read);
        }

        return $buffer;
    }

    /**
     * Allow decorators to implement custom methods
     *
     * @param string $method Missing method name
     * @param array  $args   Method arguments
     *<commit_msg>Preventing infinite loops in broken implementations<commit_after><?php

namespace GuzzleHttp\Stream;

/**
 * Stream decorator trait
 */
trait StreamDecoratorTrait
{
    /** @var StreamInterface Decorated stream */
    private $stream;

    /**
     * @param StreamInterface $stream Stream to decorate
     */
    public function __construct(StreamInterface $stream)
    {
        $this->stream = $stream;
    }

    public function __toString()
    {
        try {
            $this->seek(0);
            return $this->getContents();
        } catch (\Exception $e) {
            // Really, PHP? https://bugs.php.net/bug.php?id=53648
            trigger_error('StreamDecorator::__toString exception: ' . (string) $e, E_USER_ERROR);
            return '';
        }
    }

    public function getContents($maxLength = -1)
    {
        $buffer = '';

        while (!$this->eof()) {
            if ($maxLength === -1) {
                $read = 1048576;
            } else {
                $len = strlen($buffer);
                if ($len == $maxLength) {
                    break;
                }
                $read = min(1048576, $maxLength - $len);
            }
            if ('' === ($line = $this->read($read))) {
                break;
            }
            $buffer .= $line;
        }

        return $buffer;
    }

    /**
     * Allow decorators to implement custom methods
     *
     * @param string $method Missing method name
     * @param array  $args   Method arguments
     *
{'fraction_non_alphanumeric': 0.12841813776393216, 'fraction_numerical': 0.01523018345448252, 'mean_word_length': 1.568888888888889, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '1669570', 'n_tokens_mistral': 842, 'n_tokens_neox': 791, 'n_words': 187}