<?php

namespace App\Support;

final class IntegrationSiteSecretMask
{
    public static function mask(?string $plain): ?string
    {
        if ($plain === null || $plain === '') {
            return null;
        }

        $len = strlen($plain);
        if ($len <= 8) {
            return str_repeat('*', $len);
        }

        return substr($plain, 0, 4).str_repeat('*', max(4, $len - 8)).substr($plain, -4);
    }
}
