<?php

namespace App\Service\SnipParser;

abstract class AbstractParser implements ParserInterface
{
    public static function getName(): string
    {
        $path = explode('\\', static::class);
        return strtolower(str_replace('Parser', '', array_pop($path)));
    }

    public function parseRaw(string $content): string
    {
        return $content;
    }

    public function parseView(string $content): string
    {
        try {
            return $this->safeParseView($content);
        } catch (\Exception $exception) {
            return sprintf('<pre><code>%s</code></pre>', htmlspecialchars($exception->getMessage()));
        }
    }

    abstract function safeParseView(string $content): string;
}