GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#37)
by w3l
03:36 queued 01:38
created

Browser::getClientIpAddress()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 8.2222
cc 7
eloc 14
nc 7
nop 1
1
<?php
2
/**
3
 * Misc.php
4
 */
5
namespace w3l\Holt45;
6
7
/**
8
 * Things that does not fit in other traits...
9
 */
10
trait Browser
11
{
12
    /**
13
     * Get client ip-address
14
     *
15
     * @return null|string User ip-address
16
     */
17
    public static function getClientIpAddress($fallbackReturn = null)
18
    {
19
        if (getenv('HTTP_CLIENT_IP')) {
20
            return getenv('HTTP_CLIENT_IP');
21
        } elseif (getenv('HTTP_X_FORWARDED_FOR')) {
22
            return getenv('HTTP_X_FORWARDED_FOR');
23
        } elseif (getenv('HTTP_X_FORWARDED')) {
24
            return getenv('HTTP_X_FORWARDED');
25
        } elseif (getenv('HTTP_FORWARDED_FOR')) {
26
            return getenv('HTTP_FORWARDED_FOR');
27
        } elseif (getenv('HTTP_FORWARDED')) {
28
            return getenv('HTTP_FORWARDED');
29
        } elseif (getenv('REMOTE_ADDR')) {
30
            return getenv('REMOTE_ADDR');
31
        }
32
        /* Unknown IP */
33
        return $fallbackReturn;
34
    }
35
36
    /**
37
     * Get client operating system
38
     *
39
     * NOTICE: HTTP_USER_AGENT is easily spoofed. Don't trust this data.
40
     *
41
     * @used-by: Holt45::kbdSymbol()
42
     *
43
     * @return null|string User operating system(win|mac|linux)
44
     */
45
    public static function getClientOperatingSystem()
46
    {
47
        if (getenv('HTTP_USER_AGENT')) {
48
            $userAgent = getenv('HTTP_USER_AGENT');
49
50
            if (preg_match('/linux/i', $userAgent)) {
51
                return 'linux';
52
            } elseif (preg_match('/macintosh|mac os x/i', $userAgent)) {
53
                return'mac';
54
            } elseif (preg_match('/windows|win32/i', $userAgent)) {
55
                return 'win';
56
            }
57
        }
58
        
59
        return null;
60
    }
61
62
    /**
63
     * Get client browser
64
     *
65
     * NOTICE: HTTP_USER_AGENT is easily spoofed. Don't trust this data.
66
     *
67
     * @return null|string User browser(Internet Explorer|Camino|Firefox|Safari|Chrome|Konqueror|Opera)
68
     */
69
    public static function getClientBrowser()
70
    {
71
        if (getenv('HTTP_USER_AGENT')) {
72
            
73
            $userAgent = getenv('HTTP_USER_AGENT');
74
            
75
            if ((
76
                preg_match('/MSIE/i', $userAgent) ||
77
                preg_match('/Trident/i', $userAgent)
78
                ) && 
79
                !preg_match('/Opera/i', $userAgent)) {
80
                return 'Internet Explorer';
81
            } elseif (preg_match('/Camino/i', $userAgent)) {
82
                return "Camino";
83
            } elseif (preg_match('/Firefox/i', $userAgent)) {
84
                return "Firefox";
85
            } elseif (preg_match('/Safari/i', $userAgent)) {
86
                return "Safari";
87
            } elseif (preg_match('/Chrome/i', $userAgent)) {
88
                return "Chrome";
89
            } elseif (preg_match('/Konqueror/i', $userAgent)) {
90
                return "Konqueror";
91
            } elseif (preg_match('/Opera/i', $userAgent)) {
92
                return "Opera";
93
            }
94
        }
95
        
96
        return null;
97
    }
98
}
99