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 ( 76791b...692afa )
by w3l
10s
created

Browser::isClientBrowserGoogleChrome()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 11
rs 9.2
cc 4
eloc 6
nc 3
nop 0
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
     * Get client browser
63
     *
64
     * NOTICE: HTTP_USER_AGENT is easily spoofed. Don't trust this data.
65
     *
66
     * @deprecated 0.6 Need total rewrite with decent patterns.
67
     *
68
     * @return null|string User browser(Internet Explorer|Camino|Firefox|Safari|Chrome|Konqueror|Opera)
69
     */
70
    public static function getClientBrowser()
71
    {
72
        if ($userAgent = getenv('HTTP_USER_AGENT')) {
73
            
74
            if ((
75
                preg_match('/MSIE/i', $userAgent) ||
76
                preg_match('/Trident/i', $userAgent)
77
                ) &&
78
                !preg_match('/Opera/i', $userAgent)) {
79
                return 'msie';
80
            } elseif (preg_match('/Camino/i', $userAgent)) {
81
                return "camino";
82
            } elseif (preg_match('/Firefox/i', $userAgent)) {
83
                return "firefox";
84
            } elseif (preg_match('/Safari/i', $userAgent)) {
85
                return "safari";
86
            } elseif (preg_match('/Chrome/i', $userAgent)) {
87
                return "chrome";
88
            } elseif (preg_match('/Konqueror/i', $userAgent)) {
89
                return "konqueror";
90
            } elseif (preg_match('/Opera/i', $userAgent)) {
91
                return "opera";
92
            }
93
        }
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
     * @param string|null $accessKey
125
     * @param string $getClientBrowser
126
     * @param string $getClientOperatingSystem
127
     * @return array|null
128
     */
129
    public static function getBrowserAccessKeyModifiers(
130
        $accessKey = null,
131
        $getClientBrowser = "auto",
132
        $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...
133
    ) {
134
        if ($getClientBrowser == "auto") {
135
            $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...
136
        }
137
        
138
        if ($getClientOperatingSystem == "auto") {
139
            $getClientOperatingSystem = self::getClientOperatingSystem();
140
        }
141
        
142
        $accessKeyModifiers = array(
143
            "windows" => array(
144
                "firefox" => array("Alt", "Shift"),
145
                "chrome" => array("Alt"),
146
                "msie" => array("Alt")
147
            ),
148
            "mac" => array(
149
                "safari" => array("Ctrl", "Opt"),
150
                "chrome" => array("Ctrl", "Opt"),
151
                "firefox" => array("Ctrl", "Opt"),
152
                "camino" => array("Ctrl")
153
            ),
154
            "linux" => array(
155
                "konqueror" => array("Ctrl"),
156
                "firefox" => array("Alt", "Shift"),
157
                "chrome" => array("Alt")
158
            )
159
        );
160
        
161
        if ($keys = $accessKeyModifiers[$getClientOperatingSystem][$getClientBrowser]) {
162
            return array_merge($keys, (array)$accessKey);
163
        }
164
        return null;
165
    }
166
}
167