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 — 3.0 ( d17819...f7dde3 )
by Vermeulen
02:59
created

Request   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 153
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 153
rs 10
wmc 25
lcom 2
cbo 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A getIp() 0 4 1
A getLang() 0 4 1
A getReferer() 0 4 1
A getMethod() 0 4 1
A getSsl() 0 4 1
A __construct() 0 4 1
A getInstance() 0 8 2
A getRequest() 0 4 1
A getServerVar() 0 8 2
A runDetect() 0 9 1
A detectIp() 0 4 1
A detectLang() 0 23 2
A detectReferer() 0 4 1
A detectMethod() 0 4 1
B detectSsl() 0 16 7
A detectRequest() 0 17 1
1
<?php
2
3
namespace BFW;
4
5
class Request
6
{
7
    protected static $instance = null;
8
9
    protected $ip;
10
11
    protected $lang;
12
13
    protected $referer;
14
15
    protected $method;
16
17
    protected $ssl;
18
19
    protected $request;
20
21
    protected function __construct()
22
    {
23
        $this->runDetect();
24
    }
25
26
    public static function getInstance()
27
    {
28
        if (self::$instance === null) {
29
            self::$instance = new self;
30
        }
31
32
        return self::$instance;
33
    }
34
35
    public function getIp()
36
    {
37
        return $this->ip;
38
    }
39
40
    public function getLang()
41
    {
42
        return $this->lang;
43
    }
44
45
    public function getReferer()
46
    {
47
        return $this->referer;
48
    }
49
50
    public function getMethod()
51
    {
52
        return $this->method;
53
    }
54
55
    public function getSsl()
56
    {
57
        return $this->ssl;
58
    }
59
60
    public function getRequest()
61
    {
62
        return $this->request;
63
    }
64
65
    public static function getServerVar($keyName)
66
    {
67
        if (!isset($_SERVER[$keyName])) {
68
            return '';
69
        }
70
71
        return $_SERVER[$keyName];
72
    }
73
    
74
    public function runDetect()
75
    {
76
        $this->detectIp();
77
        $this->detectLang();
78
        $this->detectReferer();
79
        $this->detectMethod();
80
        $this->detectSsl();
81
        $this->detectRequest();
82
    }
83
84
    protected function detectIp()
85
    {
86
        $this->ip = self::getServerVar('REMOTE_ADDR');
87
    }
88
89
    protected function detectLang()
90
    {
91
        /*
92
         * HTTP_ACCEPT_LANGUAGE -> fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
93
         * First "fr-FR" (preference 1/1)
94
         * After in the order, "fr" (preference 0.8 / 1)
95
         * Next "en-US" (preference 0.6/1)
96
         * End "en" (preference 0.4/1)
97
         **/
98
99
        $acceptLang  = self::getServerVar('HTTP_ACCEPT_LANGUAGE');
100
        $acceptLangs = explode(',', $acceptLang);
101
102
        $firstLang = explode(';', $acceptLangs[0]);
103
        $lang      = strtolower($firstLang[0]);
104
105
        if (strpos($lang, '-') !== false) {
106
            $minLang = explode('-', $lang);
107
            $lang    = $minLang[0];
108
        }
109
110
        $this->lang = $lang;
111
    }
112
113
    protected function detectReferer()
114
    {
115
        $this->referer = self::getServerVar('HTTP_REFERER');
116
    }
117
118
    protected function detectMethod()
119
    {
120
        $this->method = self::getServerVar('REQUEST_METHOD');
121
    }
122
123
    protected function detectSsl()
124
    {
125
        $serverHttps = self::getServerVar('HTTPS');
126
        $fwdProto    = self::getServerVar('HTTP_X_FORWARDED_PROTO');
127
        $fwdSsl      = self::getServerVar('HTTP_X_FORWARDED_SSL');
128
129
        $this->ssl = false;
130
131
        if (!empty($serverHttps) && $serverHttps !== 'off') {
132
            $this->ssl = true;
133
        } elseif (!empty($fwdProto) && $fwdProto === 'https') {
134
            $this->ssl = true;
135
        } elseif (!empty($fwdSsl) && $fwdSsl === 'on') {
136
            $this->ssl = true;
137
        }
138
    }
139
140
    protected function detectRequest()
141
    {
142
        $parseUrl = parse_url(self::getServerVar('REQUEST_URI'));
143
144
        $this->request = [
145
            'scheme'   => '',
146
            'host'     => self::getServerVar('HTTP_HOST'),
147
            'port'     => '',
148
            'user'     => '',
149
            'pass'     => '',
150
            'path'     => '',
151
            'query'    => '',
152
            'fragment' => '',
153
        ];
154
155
        $this->request = (object) array_merge($this->request, $parseUrl);
156
    }
157
}
158