<?php

declare(strict_types=1);

namespace Plugin\tnt_stabila_shop\src\Helper;

/**
 * Validates a Sentry DSN. Accepts any http(s) URL that carries a public key in the
 * "key@host/project" form, so self-hosted Sentry hosts pass too — we do not hard-code sentry.io.
 */
final class SentryDsnValidator
{
    public static function isValid(string $dsn): bool
    {
        $dsn = \trim($dsn);
        if (\preg_match('#^https?://#i', $dsn) !== 1 || \str_contains($dsn, '@') === false) {
            return false;
        }
        $parts = \parse_url($dsn);
        return \is_array($parts)
            && ($parts['user'] ?? '') !== ''
            && ($parts['host'] ?? '') !== ''
            && \trim($parts['path'] ?? '', '/') !== '';
    }
}
