<commit_before><?php
declare(strict_types=1);

namespace HomoChecker\View;

class ServerSentEventView implements ViewInterface
{
    public $event;

    public function __construct($event)
    {
        $this->event = $event;

        // @codeCoverageIgnoreStart
        if (!headers_sent()) {
            header('Content-Type: text/event-stream');
        }
        // @codeCoverageIgnoreEnd

        // 2 KiB padding
        echo ":" . str_repeat(" ", 2048) . "\n";

        $this->flush();
    }

    /**
     * @codeCoverageIgnore
     */
    public function render($data, $event = null): void
    {
        $event = $event ?? $this->event;
        echo "event: {$event}\n";
        echo "data: " . json_encode($data) . "\n\n";
        $this->flush();
    }

    public function flush(): void
    {
        @ob_flush();
        flush();
    }

    public function close(): void
    {
        echo "event: close\n";
        echo "data: end\n\n";
    }
}<commit_msg>Fix a bug where close event was not sent<commit_after><?php
declare(strict_types=1);

namespace HomoChecker\View;

class ServerSentEventView implements ViewInterface
{
    public $event;

    public function __construct($event)
    {
        $this->event = $event;

        // @codeCoverageIgnoreStart
        if (!headers_sent()) {
            header('Content-Type: text/event-stream');
        }
        // @codeCoverageIgnoreEnd

        // 2 KiB padding
        echo ":" . str_repeat(" ", 2048) . "\n";

        $this->flush();
    }

    /**
     * @codeCoverageIgnore
     */
    public function render($data, $event = null): void
    {
        $event = $event ?? $this->event;
        echo "event: {$event}\n";
        echo "data: " . json_encode($data) . "\n\n";
        $this->flush();
    }

    public function flush(): void
    {
        @ob_flush();
        flush();
    }

    public function close(): void
    {
        echo "event: close\n";
        echo "data: end\n\n";
        $this->flush();
    }
}
{'fraction_non_alphanumeric': 0.1540010065425264, 'fraction_numerical': 0.006039255158530448, 'mean_word_length': 1.9021897810218977, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 12, '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': '7469372', 'n_tokens_mistral': 630, 'n_tokens_neox': 602, 'n_words': 135}