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.

Browser   A
last analyzed

Complexity

Total Complexity 28

Size/Duplication

Total Lines 159
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 159
rs 10
c 0
b 0
f 0
wmc 28
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
B getClientIpAddress() 0 18 7
B getClientOperatingSystem() 0 15 5
B getBrowserNameFromUA() 0 15 6
A getClientBrowser() 0 7 2
A isClientBrowserGoogleChrome() 0 11 4
B getBrowserAccessKeyModifiers() 0 37 4
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 ($userAgent = getenv('HTTP_USER_AGENT')) {
48
49
            if (preg_match('/linux/i', $userAgent)) {
50
                return 'linux';
51
            } elseif (preg_match('/macintosh|mac os x/i', $userAgent)) {
52
                return'mac';
53
            } elseif (preg_match('/windows|win32/i', $userAgent)) {
54
                return 'windows';
55
            }
56
        }
57
        
58
        return null;
59
    }
60
61
    /**
62
     * Convert UA to browser name
63
     *
64
     * @param Useragent-string
65
     * return null|string Browser name
66
     */
67
    public static function getBrowserNameFromUA($userAgent)
68
    {
69
        if (preg_match('/(MSIE|Trident)/i', $userAgent)) {
70
            return 'msie';
71
        } elseif (preg_match('/^((?!Mozilla).*?)\//i', $userAgent, $match)) {
72
            return mb_strtolower($match[1]);
73
        } elseif (preg_match('/(Chrome)/i', $userAgent) &&
74
                  preg_match('/(Safari)/i', $userAgent)) {
75
            return 'chrome';
76
        } elseif (preg_match('/([^\s]+)$/i', $userAgent, $match)) {
77
            return mb_strtolower(current(explode("/", $match[1])));
78
        }
79
        
80
        return null;
81
    }
82
    
83
    /**
84
     * Get client browser
85
     *
86
     * NOTICE: HTTP_USER_AGENT is easily spoofed. Don't trust this data.
87
     *
88
     * @return null|string User browser
89
     */
90
    public static function getClientBrowser()
91
    {
92
        if ($userAgent = getenv('HTTP_USER_AGENT')) {
93
            return self::getBrowserNameFromUA($userAgent);            
94
        }
95
        return null;
96
    }
97
98
    /**
99
     * Check if browser is Google Chrome and not one of the browsers derived from Google Chrome.
100
     *
101
     * NOTICE: HTTP_USER_AGENT is easily spoofed. Don't trust this data.
102
     *
103
     * @return bool
104
     */
105
    public static function isClientBrowserGoogleChrome()
106
    {
107
        if ($userAgent = getenv('HTTP_USER_AGENT')) {
108
            
109
            if (preg_match('/(Chrome|CriOS)\//i', $userAgent) &&
110
                !preg_match('/(Aviator|brave|ChromePlus|coc_|Dragon|Edge|Flock|Iron|Kinza|Maxthon|MxNitro|Nichrome|OPR|Perk|Rockmelt|Seznam|Sleipnir|Spark|UBrowser|Vivaldi|WebExplorer|YaBrowser)/i', $userAgent)) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 213 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
111
                return true;
112
            }
113
        }
114
        return false;
115
    }
116
    
117
    /**
118
     * Get access key modifiers
119
     *
120
     * NOTICE: HTTP_USER_AGENT is easily spoofed. Don't trust this data.
121
     *
122
     * @link https://en.wikipedia.org/wiki/Access_key Source
123
     *
124
     * @used-by: Holt45::kbdSymbol()
125
     *
126
     * @param string|null $accessKey
127
     * @param string $getClientBrowser
128
     * @param string $getClientOS
129
     * @return array|null
130
     */
131
    public static function getBrowserAccessKeyModifiers(
132
        $accessKey = null,
133
        $getClientBrowser = "auto",
134
        $getClientOS = "auto"
135
    ) {
136
        if ($getClientBrowser == "auto") {
137
            $getClientBrowser = self::getClientBrowser();
138
        }
139
        
140
        if ($getClientOS == "auto") {
141
            $getClientOS = self::getClientOperatingSystem();
142
        }
143
        
144
        $accessKeyModifiers = array(
145
            "windows" => array(
146
                "firefox" => array("Alt", "Shift"),
147
                "chrome" => array("Alt"),
148
                "msie" => array("Alt")
149
            ),
150
            "mac" => array(
151
                "safari" => array("Ctrl", "Opt"),
152
                "chrome" => array("Ctrl", "Opt"),
153
                "firefox" => array("Ctrl", "Opt"),
154
                "camino" => array("Ctrl")
155
            ),
156
            "linux" => array(
157
                "konqueror" => array("Ctrl"),
158
                "firefox" => array("Alt", "Shift"),
159
                "chrome" => array("Alt")
160
            )
161
        );
162
        
163
        if ($keys = $accessKeyModifiers[$getClientOS][$getClientBrowser]) {
164
            return array_merge($keys, (array)$accessKey);
165
        }
166
        return null;
167
    }
168
}
169