<?php

declare(strict_types=1);

namespace Autogedal\FeedMonitor\Model\Fetch;

class InvalidFeedException extends \RuntimeException
{
    /**
     * Start of the content, without markup, to see in the alert what came instead of the feed (e.g. an error page).
     */
    public static function withSample(string $reason, string $content): self
    {
        $sample = trim((string)preg_replace('/\s+/', ' ', strip_tags($content)));

        return new self($reason . ($sample !== '' ? ' Inceput: ' . mb_substr($sample, 0, 200) : ''));
    }
}
