IPGetCurrent::getIP()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 10
ccs 6
cts 7
cp 0.8571
crap 3.0261
rs 10
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