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
Push — master ( f5f2be...76791b )
by w3l
7s
created

Browser::getBrowserAccessKeyModifiers()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 37
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 37
rs 8.5806
cc 4
eloc 25
nc 8
nop 3
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 'windows';
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
     * @deprecated 0.6 Need total rewrite with decent patterns.
68
     *
69
     * @return null|string User browser(Internet Explorer|Camino|Firefox|Safari|Chrome|Konqueror|Opera)
70
     */
71
    public static function getClientBrowser()
72
    {
73
        if (getenv('HTTP_USER_AGENT')) {
74
            
75
            $userAgent = getenv('HTTP_USER_AGENT');
76
            
77
            if ((
78
                preg_match('/MSIE/i', $userAgent) ||
79
                preg_match('/Trident/i', $userAgent)
80
                ) &&
81
                !preg_match('/Opera/i', $userAgent)) {
82
                return 'msie';
83
            } elseif (preg_match('/Camino/i', $userAgent)) {
84
                return "camino";
85
            } elseif (preg_match('/Firefox/i', $userAgent)) {
86
                return "firefox";
87
            } elseif (preg_match('/Safari/i', $userAgent)) {
88
                return "safari";
89
            } elseif (preg_match('/Chrome/i', $userAgent)) {
90
                return "chrome";
91
            } elseif (preg_match('/Konqueror/i', $userAgent)) {
92
                return "konqueror";
93
            } elseif (preg_match('/Opera/i', $userAgent)) {
94
                return "opera";
95
            }
96
        }
97
        
98
        return null;
99
    }
100
101
    /**
102
     * Check if browser is Google Chrome and not one of the browsers derived from Google Chrome.
103
     *
104
     * NOTICE: HTTP_USER_AGENT is easily spoofed. Don't trust this data.
105
     *
106
     * @return bool
107
     */
108
    public static function isClientBrowserGoogleChrome()
109
    {
110
        if (getenv('HTTP_USER_AGENT')) {
111
            
112
            $userAgent = getenv('HTTP_USER_AGENT');
113
            
114
            if (preg_match('/(Chrome|CriOS)\//i', $userAgent) &&
115
                !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...
116
                return true;
117
            }
118
        }
119
        return false;
120
    }
121
    
122
    /**
123
     * Get access key modifiers
124
     *
125
     * NOTICE: HTTP_USER_AGENT is easily spoofed. Don't trust this data.
126
     *
127
     * @link https://en.wikipedia.org/wiki/Access_key Source
128
     *
129
     * @param string|null $accessKey
130
     * @param string $getClientBrowser
131
     * @param string $getClientOperatingSystem
132
     * @return array|null
133
     */
134
    public static function getBrowserAccessKeyModifiers(
135
        $accessKey = null,
136
        $getClientBrowser = "auto",
137
        $getClientOperatingSystem = "auto"
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $getClientOperatingSystem exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
138
    ) {
139
        if ($getClientBrowser == "auto") {
140
            $getClientBrowser = self::getClientBrowser();
0 ignored issues
show
Deprecated Code introduced by
The method w3l\Holt45\Browser::getClientBrowser() has been deprecated with message: 0.6 Need total rewrite with decent patterns.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
141
        }
142
        
143
        if ($getClientOperatingSystem == "auto") {
144
            $getClientOperatingSystem = self::getClientOperatingSystem();
145
        }
146
        
147
        $accessKeyModifiers = array(
148
            "windows" => array(
149
                "firefox" => array("Alt", "Shift"),
150
                "chrome" => array("Alt"),
151
                "msie" => array("Alt")
152
            ),
153
            "mac" => array(
154
                "safari" => array("Ctrl", "Opt"),
155
                "chrome" => array("Ctrl", "Opt"),
156
                "firefox" => array("Ctrl", "Opt"),
157
                "camino" => array("Ctrl")
158
            ),
159
            "linux" => array(
160
                "konqueror" => array("Ctrl"),
161
                "firefox" => array("Alt", "Shift"),
162
                "chrome" => array("Alt")
163
            )
164
        );
165
        
166
        if ($keys = $accessKeyModifiers[$getClientOperatingSystem][$getClientBrowser]) {
167
            return array_merge($keys, (array)$accessKey);
168
        }
169
        return null;
170
    }
171
}
172