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

namespace KiH\Action;

use DateTimeZone;
use KiH\Client;
use KiH\Generator;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class Feed
{
    private Client $client;

    private Generator $generator;

    public function __construct(Client $client, Generator $generator)
    {
        $this->client    = $client;
        $this->generator = $generator;
    }

    public function __invoke(Request $request, Response $response) : Response
    {
        $response = $response
            ->withHeader('Content-Type', 'text/xml; charset=UTF-8');

        $feed = $this->client->getFeed();

        foreach ($feed as $item) {
            $response = $response
                ->withHeader(
                    'Expires',
                    $item->getCreatedAt()
                        ->setTimezone(new DateTimeZone('UTC'))
                        ->modify('+1 day')->format('D, d M Y H:i:s \G\M\T')
                );
            break;
        }

        $response->getBody()->write(
            $this->generator->generate($feed, $request->getUri())->saveXML()
        );

        return $response;
    }
}<commit_msg>Native PHP APIs are so fun to deal with!<commit_after><?php declare(strict_types=1);

namespace KiH\Action;

use DateTimeZone;
use KiH\Client;
use KiH\Generator;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use function assert;
use function is_string;

class Feed
{
    private Client $client;

    private Generator $generator;

    public function __construct(Client $client, Generator $generator)
    {
        $this->client    = $client;
        $this->generator = $generator;
    }

    public function __invoke(Request $request, Response $response) : Response
    {
        $response = $response
            ->withHeader('Content-Type', 'text/xml; charset=UTF-8');

        $feed = $this->client->getFeed();

        foreach ($feed as $item) {
            $response = $response
                ->withHeader(
                    'Expires',
                    $item->getCreatedAt()
                        ->setTimezone(new DateTimeZone('UTC'))
                        ->modify('+1 day')->format('D, d M Y H:i:s \G\M\T')
                );
            break;
        }

        $xml = $this->generator->generate($feed, $request->getUri())
            ->saveXML();
        assert(is_string($xml));

        $response->getBody()->write($xml);

        return $response;
    }
}
{'fraction_non_alphanumeric': 0.13356697819314642, 'fraction_numerical': 0.002336448598130841, 'mean_word_length': 2.069295101553166, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, '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': '7178672', 'n_tokens_mistral': 736, 'n_tokens_neox': 704, 'n_words': 165}