IPGetCurrent   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 18
ccs 6
cts 7
cp 0.8571
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getIP() 0 10 3
1
<?php
2
3
/**
4
 * Get IP address of current user
5
 */
6
7
namespace Hepa19\IPGeo;
8
9
/**
10
 * Get IP of current user
11
 *
12
 */
13
class IPGetCurrent
14
{
15
    /**
16
     * Returns user's current IP address
17
     *
18
     * @return string $currentIP User's IP address
19
     */
20
21 9
    public function getIP() : string
22
    {
23 9
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24 4
            $currentIP = $_SERVER['HTTP_CLIENT_IP'];
25 5
        } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
            $currentIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
27
        } else {
28 5
            $currentIP = $_SERVER['REMOTE_ADDR'];
29
        }
30 9
        return $currentIP;
31
    }
32
}
33