public function getIpAddress(): ?string
    {
        $ipAddress    = null;
        $request      = $this->serverRequest;
        $serverParams = $request->getServerParams();

        // direct IP address
        if (isset($serverParams['REMOTE_ADDR']) && $this->isValidIpAddress($serverParams['REMOTE_ADDR'])) {
            $ipAddress = $serverParams['REMOTE_ADDR'];
        }

        foreach (self::$headersToInspect as $header) {
            if ($request->hasHeader($header)) {
                $ip = $this->getFirstIpAddressFromHeader($request, $header);

                if ($this->isValidIpAddress($ip)) {
                    $ipAddress = $ip;

                    break;
                }
            }
        }

        return $ipAddress;
    }