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 — dev ( 5f8111...1bcb68 )
by w3l
01:52
created

Browser::getBrowserAccessKeyModifiers()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 34
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 34
rs 8.5806
cc 4
eloc 22
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 $accessKey
0 ignored issues
show
Documentation introduced by
Should the type for parameter $accessKey not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
130
     * @param string $getClientBrowser
131
     * @param string $getClientOperatingSystem
132
     * @return array|null
133
     */
134
    public static function getBrowserAccessKeyModifiers($accessKey = null, $getClientBrowser = "auto", $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...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 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...
135
    {
136
        if ($getClientBrowser == "auto") {
137
            $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...
138
        }
139
        
140
        if ($getClientOperatingSystem == "auto") {
141
            $getClientOperatingSystem = 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[$getClientOperatingSystem][$getClientBrowser]) {
164
            return array_merge($keys, (array)$accessKey);
165
        }
166
        return null;
167
    }
168
}
169