CaptureIpTrait::getUserIp()   B
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 15
c 1
b 0
f 0
nc 7
nop 0
dl 0
loc 19
rs 8.8333
1
<?php
2
namespace App\Traits;
3
4
trait CaptureIpTrait
5
{
6
    private $ip = null;
7
8
    public function getUserIp()
9
    {
10
        if (getenv('HTTP_CLIENT_IP')) {
11
            $ip = getenv('HTTP_CLIENT_IP');
12
        } elseif (getenv('HTTP_X_FORWARDED_FOR')) {
13
            $ip = getenv('HTTP_X_FORWARDED_FOR');
14
        } elseif (getenv('HTTP_X_FORWARDED')) {
15
            $ip = getenv('HTTP_X_FORWARDED');
16
        } elseif (getenv('HTTP_FORWARDED_FOR')) {
17
            $ip = getenv('HTTP_FORWARDED_FOR');
18
        } elseif (getenv('HTTP_FORWARDED')) {
19
            $ip = getenv('HTTP_FORWARDED');
20
        } elseif (getenv('REMOTE_ADDR')) {
21
            $ip = getenv('REMOTE_ADDR');
22
        } else {
23
            $ip = config('settings.nullIpAddress');
24
        }
25
26
        return $ip;
27
    }
28
}