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:38 queued 01:49
created

Browser   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 23
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 89
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B getClientIpAddress() 0 18 7
B getClientOperatingSystem() 0 16 5
C getClientBrowser() 0 29 11
1
<?php
2
/**
3
 * Browser.php
4
 */
5
namespace w3l\Holt45;
6
7
/**
8
 * Get data from the browser/user.
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