<commit_before><?php

namespace Amp\ByteStream;

use Amp\InvalidYieldError;
use Amp\Promise;

final class Parser {
    /** @var \Generator */
    private $generator;

    /** @var string */
    private $buffer = '';

    /** @var int|string|null */
    private $delimiter;

    /**
     * @param \Generator $generator
     *
     * @throws \Amp\InvalidYieldError If the generator yields an invalid value.
     */
    public function __construct(\Generator $generator) {
        $this->generator = $generator;

        $this->delimiter = $this->generator->current();

        if (!$this->generator->valid()) {
            $this->generator = null;
            return;
        }

        if ($this->delimiter !== null
            && (!\is_int($this->delimiter) || $this->delimiter <= 0)
            && (!\is_string($this->delimiter) || !\strlen($this->delimiter))
        ) {
            throw new InvalidYieldError(
                $generator,
                \sprintf(
                    "Unexpected yield; Expected NULL, an int greater than 0, or a non-empty string; %s given",
                    \is_object($this->delimiter) ? \sprintf("instance of %s", \get_class($this->delimiter)) : \gettype($this->delimiter)
                )
            );
        }
    }

    /**
     * Cancels the generator parser and returns any remaining data in the internal buffer. Writing data after calling
     * this method will result in an error.
     *
     * @return string
     */
    public function cancel(): string {
        $this->generator = null;
        return $this->buffer;
    }

    public function push(string $data): Promise {<commit_msg>Remove wrong return type from Parser::push<commit_after><?php

namespace Amp\ByteStream;

use Amp\InvalidYieldError;

final class Parser {
    /** @var \Generator */
    private $generator;

    /** @var string */
    private $buffer = '';

    /** @var int|string|null */
    private $delimiter;

    /**
     * @param \Generator $generator
     *
     * @throws \Amp\InvalidYieldError If the generator yields an invalid value.
     */
    public function __construct(\Generator $generator) {
        $this->generator = $generator;

        $this->delimiter = $this->generator->current();

        if (!$this->generator->valid()) {
            $this->generator = null;
            return;
        }

        if ($this->delimiter !== null
            && (!\is_int($this->delimiter) || $this->delimiter <= 0)
            && (!\is_string($this->delimiter) || !\strlen($this->delimiter))
        ) {
            throw new InvalidYieldError(
                $generator,
                \sprintf(
                    "Unexpected yield; Expected NULL, an int greater than 0, or a non-empty string; %s given",
                    \is_object($this->delimiter) ? \sprintf("instance of %s", \get_class($this->delimiter)) : \gettype($this->delimiter)
                )
            );
        }
    }

    /**
     * Cancels the generator parser and returns any remaining data in the internal buffer. Writing data after calling
     * this method will result in an error.
     *
     * @return string
     */
    public function cancel(): string {
        $this->generator = null;
        return $this->buffer;
    }

    public function push(string $data) {
{'fraction_non_alphanumeric': 0.13469139556096077, 'fraction_numerical': 0.0012161751292186075, 'mean_word_length': 1.985480943738657, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, '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': '5581007', 'n_tokens_mistral': 913, 'n_tokens_neox': 892, 'n_words': 242}