Server::getServerPort()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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