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 ( a8bbdd...ff86b0 )
by w3l
02:05
created

Browser::getClientBrowser()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 0
loc 18
rs 8.2222
cc 7
eloc 12
nc 6
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
     * @return null|string User browser
67
     */
68
    public static function getClientBrowser()
69
    {
70
        if ($userAgent = getenv('HTTP_USER_AGENT')) {
71
            
72
            if (preg_match('/(MSIE|Trident)/i', $userAgent)) {
73
                return 'msie';
74
            } elseif (preg_match('/^((?!Mozilla).*?)\//i', $userAgent, $match)) {
75
                return mb_strtolower($match[1]);
76
            } elseif (preg_match('/(Chrome)/i', $userAgent) &&
77
                      preg_match('/(Safari)/i', $userAgent)) {
78
                return 'chrome';
79
            } elseif (preg_match('/([^\s]+)$/i', $userAgent, $match)) {
80
                return mb_strtolower(current(explode("/", $match[1])));
81
            }
82
        }
83
        
84
        return null;
85
    }
86
87
    /**
88
     * Check if browser is Google Chrome and not one of the browsers derived from Google Chrome.
89
     *
90
     * NOTICE: HTTP_USER_AGENT is easily spoofed. Don't trust this data.
91
     *
92
     * @return bool
93
     */
94
    public static function isClientBrowserGoogleChrome()
95
    {
96
        if ($userAgent = getenv('HTTP_USER_AGENT')) {
97
            
98
            if (preg_match('/(Chrome|CriOS)\//i', $userAgent) &&
99
                !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...
100
                return true;
101
            }
102
        }
103
        return false;
104
    }
105
    
106
    /**
107
     * Get access key modifiers
108
     *
109
     * NOTICE: HTTP_USER_AGENT is easily spoofed. Don't trust this data.
110
     *
111
     * @link https://en.wikipedia.org/wiki/Access_key Source
112
     *
113
     * @param string|null $accessKey
114
     * @param string $getClientBrowser
115
     * @param string $getClientOperatingSystem
116
     * @return array|null
117
     */
118
    public static function getBrowserAccessKeyModifiers(
119
        $accessKey = null,
120
        $getClientBrowser = "auto",
121
        $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...
122
    ) {
123
        if ($getClientBrowser == "auto") {
124
            $getClientBrowser = self::getClientBrowser();
125
        }
126
        
127
        if ($getClientOperatingSystem == "auto") {
128
            $getClientOperatingSystem = self::getClientOperatingSystem();
129
        }
130
        
131
        $accessKeyModifiers = array(
132
            "windows" => array(
133
                "firefox" => array("Alt", "Shift"),
134
                "chrome" => array("Alt"),
135
                "msie" => array("Alt")
136
            ),
137
            "mac" => array(
138
                "safari" => array("Ctrl", "Opt"),
139
                "chrome" => array("Ctrl", "Opt"),
140
                "firefox" => array("Ctrl", "Opt"),
141
                "camino" => array("Ctrl")
142
            ),
143
            "linux" => array(
144
                "konqueror" => array("Ctrl"),
145
                "firefox" => array("Alt", "Shift"),
146
                "chrome" => array("Alt")
147
            )
148
        );
149
        
150
        if ($keys = $accessKeyModifiers[$getClientOperatingSystem][$getClientBrowser]) {
151
            return array_merge($keys, (array)$accessKey);
152
        }
153
        return null;
154
    }
155
}
156