Skip to content

Commit

Permalink
remove else after return and inline assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
melbahja committed Jun 13, 2018
1 parent 4061792 commit 9a0bc43
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Http/ServerRequest.php
Expand Up @@ -585,7 +585,8 @@ public function session(Session $session = null)
public function clientIp()
{
if ($this->trustProxy) {
if ($forwarded = $this->getEnv('HTTP_X_FORWARDED_FOR')) {
$forwarded = $this->getEnv('HTTP_X_FORWARDED_FOR');
if ($forwarded) {
$addresses = array_map('trim', explode(',', $forwarded));
$trusted = (count($this->trustedProxies) > 0);
$n = count($addresses);
Expand All @@ -599,13 +600,17 @@ public function clientIp()
}
}

return (($trusted) ? $addresses[0] : $addresses[$n - 1]);
} else {
if ($ip = $this->getEnv('HTTP_X_REAL_IP')) {
return $ip;
} elseif ($ip = $this->getEnv('HTTP_CLIENT_IP')) {
return $ip;
if ($trusted) {
return $addresses[0];
}

return $addresses[$n - 1];
}

if ($this->getEnv('HTTP_X_REAL_IP')) {
return $this->getEnv('HTTP_X_REAL_IP');
} elseif ($this->getEnv('HTTP_CLIENT_IP')) {
return $this->getEnv('HTTP_CLIENT_IP');
}
}

Expand Down

0 comments on commit 9a0bc43

Please sign in to comment.