Passed
Push — master ( ca838e...76d3e9 )
by Radu
01:16
created

RequestServerTrait::getSchema()   B

Complexity

Conditions 8
Paths 5

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 7.7777
c 0
b 0
f 0
cc 8
eloc 11
nc 5
nop 0
1
<?php
2
namespace WebServCo\Framework\Traits;
3
4
trait RequestServerTrait
5
{
6
    public function getAcceptLanguage()
7
    {
8
        if (!isset($this->server['HTTP_ACCEPT_LANGUAGE'])) {
0 ignored issues
show
Bug Best Practice introduced by
The property server does not exist on WebServCo\Framework\Traits\RequestServerTrait. Did you maybe forget to declare it?
Loading history...
9
            return false;
10
        }
11
        return substr($this->server['HTTP_ACCEPT_LANGUAGE'], 0, 2);
12
    }
13
    
14
    public function getHost()
15
    {
16
        if (!empty($this->server['HTTP_HOST'])) {
0 ignored issues
show
Bug Best Practice introduced by
The property server does not exist on WebServCo\Framework\Traits\RequestServerTrait. Did you maybe forget to declare it?
Loading history...
17
            return $this->server['HTTP_HOST'];
18
        } elseif (!empty($this->server['SERVER_NAME'])) {
19
            return $this->server['SERVER_NAME'];
20
        } elseif (!empty($this->server['HOSTNAME'])) {
21
            return $this->server['HOSTNAME']; //CLI
22
        }
23
        return null;
24
    }
25
    
26
    public function getReferer()
27
    {
28
        return isset($this->server['HTTP_REFERER']) ? $this->server['HTTP_REFERER'] : null;
0 ignored issues
show
Bug Best Practice introduced by
The property server does not exist on WebServCo\Framework\Traits\RequestServerTrait. Did you maybe forget to declare it?
Loading history...
29
    }
30
    
31
    public function getSchema()
32
    {
33
        if (\WebServCo\Framework\Framework::isCLI()) {
34
            return null;
35
        }
36
        
37
        if (isset($this->server['HTTPS']) && 'off' != $this->server['HTTPS']) {
0 ignored issues
show
Bug Best Practice introduced by
The property server does not exist on WebServCo\Framework\Traits\RequestServerTrait. Did you maybe forget to declare it?
Loading history...
38
            return 'https';
39
        } elseif (isset($this->server['HTTP_X_FORWARDED_PROTO']) &&
40
        'https' == $this->server['HTTP_X_FORWARDED_PROTO']) {
41
            return 'https';
42
        } elseif (isset($this->server['HTTP_X_FORWARDED_SSL']) &&
43
        'on' == $this->server['HTTP_X_FORWARDED_SSL']) {
44
            return 'https';
45
        }
46
        return 'http';
47
    }
48
    
49
    public function getServerProtocol()
50
    {
51
        if (!isset($this->server['SERVER_PROTOCOL'])) {
0 ignored issues
show
Bug Best Practice introduced by
The property server does not exist on WebServCo\Framework\Traits\RequestServerTrait. Did you maybe forget to declare it?
Loading history...
52
            return false;
53
        }
54
        return $this->server['SERVER_PROTOCOL'];
55
    }
56
}
57