protected function applyIpMask(string $ip, int $maskLength): string
    {
        if (empty($ip) || $maskLength === 0) {
            return $ip;
        }

        // IPv4 or mapped IPv4 in IPv6
        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            return $this->applyIpV4Mask($ip, $maskLength);
        }

        return $this->applyIpV6Mask($ip, $maskLength);
    }