Server   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 58
ccs 0
cts 25
cp 0
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getServerIP() 0 3 1
A getClientPort() 0 3 1
A getHost() 0 3 1
A getServerPort() 0 3 1
A getClientIP() 0 11 3
1
<?php
2
/**
3
 * DronePHP (http://www.dronephp.com)
4
 *
5
 * @link      http://github.com/Pleets/DronePHP
6
 * @copyright Copyright (c) 2016-2018 Pleets. (http://www.pleets.org)
7
 * @license   http://www.dronephp.com/license
8
 * @author    Darío Rivera <[email protected]>
9
 */
10
11
namespace Drone\Network;
12
13
/**
14
 * Server class
15
 *
16
 * Helper class to get some information about server
17
 */
18
class Server
19
{
20
    /**
21
     * Returns http host
22
     *
23
     * @return string
24
     */
25
    public static function getHost()
26
    {
27
        return $_SERVER["HTTP_HOST"];
28
    }
29
30
    /**
31
     * Returns server port
32
     *
33
     * @return string
34
     */
35
    public static function getServerPort()
36
    {
37
        return $_SERVER["SERVER_PORT"];
38
    }
39
40
    /**
41
     * Returns client port
42
     *
43
     * @return string
44
     */
45
    public static function getClientPort()
46
    {
47
        return $_SERVER["REMOTE_PORT"];
48
    }
49
50
    /**
51
     * Returns server ip
52
     *
53
     * @return string
54
     */
55
    public static function getServerIP()
56
    {
57
        return $_SERVER["SERVER_ADDR"];
58
    }
59
60
    /**
61
     * Returns client ip
62
     *
63
     * @return string
64
     */
65
    public static function getClientIP()
66
    {
67
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
68
            return $_SERVER['HTTP_CLIENT_IP'];
69
        }
70
71
        if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
72
            return $_SERVER['HTTP_X_FORWARDED_FOR'];
73
        }
74
75
        return $_SERVER['REMOTE_ADDR'];
76
    }
77
}
78