final private static function guardConstants(array $constants): void
    {
        $duplicates = [];
        foreach ($constants as $value) {
            $names = array_keys($constants, $value, $strict = true);
            if (count($names) > 1) {
                $duplicates[VarPrinter::toString($value)] = $names;
            }
        }
        if (!empty($duplicates)) {
            $list = array_map(function ($names) use ($constants) {
                return sprintf('(%s)=%s', implode('|', $names), VarPrinter::toString($constants[$names[0]]));
            }, $duplicates);
            $message = sprintf('Duplicate enum values: %s', implode(', ', $list));
            throw new DomainException($message);
        }
    }