Passed
Push — master ( c01c31...d9cbe6 )
by Radu
01:46
created

RequestServerTrait::getRemoteAddress()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 3
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace WebServCo\Framework\Traits;
3
4
use WebServCo\Framework\Framework;
5
6
trait RequestServerTrait
7
{
8
    public function getAcceptLanguage()
9
    {
10
        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...
11
            return false;
12
        }
13
        return substr($this->server['HTTP_ACCEPT_LANGUAGE'], 0, 2);
14
    }
15
16
    public function getHost()
17
    {
18
        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...
19
            return $this->server['HTTP_HOST'];
20
        } elseif (!empty($this->server['SERVER_NAME'])) {
21
            return $this->server['SERVER_NAME'];
22
        } elseif (!empty($this->server['HOSTNAME'])) {
23
            return $this->server['HOSTNAME']; //CLI
24
        }
25
        return null;
26
    }
27
28
    public function getHostExtension()
29
    {
30
        $host = $this->getHost();
31
        if (empty($host)) {
32
            return false;
33
        }
34
35
        $parts = explode('.', $host);
36
        return end($parts);
37
    }
38
39
    public function getReferer()
40
    {
41
        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...
42
    }
43
44
    public function getSchema()
45
    {
46
        if (Framework::isCLI()) {
47
            return null;
48
        }
49
50
        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...
51
            return 'https';
52
        } elseif (isset($this->server['HTTP_X_FORWARDED_PROTO']) &&
53
        'https' == $this->server['HTTP_X_FORWARDED_PROTO']) {
54
            return 'https';
55
        } elseif (isset($this->server['HTTP_X_FORWARDED_SSL']) &&
56
        'on' == $this->server['HTTP_X_FORWARDED_SSL']) {
57
            return 'https';
58
        }
59
        return 'http';
60
    }
61
62
    public function getServerProtocol()
63
    {
64
        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...
65
            return false;
66
        }
67
        return $this->server['SERVER_PROTOCOL'];
68
    }
69
70
    public function getRemoteAddress()
71
    {
72
        if (Framework::isCLI()) {
73
            return gethostbyname(php_uname('n'));
74
        }
75
        return isset($this->server['REMOTE_ADDR']) ? $this->server['REMOTE_ADDR'] : false;
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...
76
    }
77
}
78