Completed
Push — master ( bcc5fe...59ad42 )
by Dev
01:59
created

LogLine   A

Complexity

Total Complexity 38

Size/Duplication

Total Lines 192
Duplicated Lines 0 %

Test Coverage

Coverage 65.59%

Importance

Changes 0
Metric Value
wmc 38
eloc 58
dl 0
loc 192
ccs 61
cts 93
cp 0.6559
rs 9.36
c 0
b 0
f 0

32 Methods

Rating   Name   Duplication   Size   Complexity  
A getKeys() 0 3 1
A getDomain() 0 3 1
A getStatus() 0 3 1
A getReferer() 0 3 1
A setHost() 0 3 1
A getResponseBytes() 0 3 1
A __construct() 0 3 1
A setRequest() 0 7 1
A setHeaderUserAgent() 0 3 1
A setResponseBytes() 0 3 1
A getLogname() 0 3 1
A getTime() 0 3 1
A setHeaderReferer() 0 4 3
A setUrl() 0 3 1
A setDomain() 0 3 1
A getUser() 0 3 1
A setUseragent() 0 3 1
A setLogname() 0 4 2
A ipAdressNumber() 0 5 1
A setHttpVersion() 0 3 1
A getUseragent() 0 3 1
A isInternalReferer() 0 3 2
A getRequest() 0 3 1
A setUser() 0 4 2
A getIp() 0 3 1
A setIp() 0 3 1
A setStatus() 0 3 1
A setReferer() 0 5 2
A setMethod() 0 3 1
A getHttpVersion() 0 3 1
A setTime() 0 7 1
A get() 0 3 1
1
<?php
2
3
namespace PiedWeb\LogsAnalyzer;
4
5
class LogLine
6
{
7
    protected $ip;
8
    protected $logname;
9
    protected $user;
10
    protected $date;
11
    protected $time;
12
    protected $domain;
13
    protected $method;
14
    protected $url;
15
    protected $httpVersion;
16
    protected $status;
17
    protected $responseBytes;
18
    protected $referer;
19
    protected $useragent;
20
21 3
    public function __construct(?string $domain = null)
22
    {
23 3
        $this->domain = $domain;
24 3
    }
25
26
    public function getKeys()
27
    {
28
        return array_keys(get_object_vars($this));
29
    }
30
31
    public function get()
32
    {
33
        return array_values(get_object_vars($this));
34
    }
35
36
    public function getIp()
37
    {
38
        return $this->ip;
39
    }
40
41 3
    public function setHost($ip)
42
    {
43 3
        $this->setIp($ip);
44 3
    }
45
46 3
    public function setIp($ip)
47
    {
48 3
        $this->ip = $ip;
49 3
    }
50
51
    public function getLogname()
52
    {
53
        return $this->logname;
54
    }
55
56 3
    public function setLogname($logname)
57
    {
58 3
        if ('-' != $logname) {
59
            $this->logname = $logname;
60
        }
61 3
    }
62
63
    public function getUser()
64
    {
65
        return $this->user;
66
    }
67
68 3
    public function setUser($user)
69
    {
70 3
        if ('-' != $user) {
71
            $this->user = $user;
72
        }
73 3
    }
74
75
    public function getTime()
76
    {
77
        return $this->time;
78
    }
79
80 3
    public function setTime($time)
81
    {
82 3
        list($date, $time) = explode(':', $time, 2);
83 3
        $this->time = $time;
84
85 3
        $date = \DateTime::createFromFormat('j/M/Y', $date);
86 3
        $this->date = $date->format('Ymd');
87 3
    }
88
89
    public function getDomain()
90
    {
91
        return $this->domain;
92
    }
93
94
    public function setDomain($domain)
95
    {
96
        $this->domain = $domain;
97
    }
98
99
    public function getRequest()
100
    {
101
        return $this->request;
0 ignored issues
show
Bug Best Practice introduced by
The property request does not exist on PiedWeb\LogsAnalyzer\LogLine. Did you maybe forget to declare it?
Loading history...
102
    }
103
104 3
    public function setMethod($method)
105
    {
106 3
        $this->method = $method;
107 3
    }
108
109 3
    public function setUrl($url)
110
    {
111 3
        $this->url = $url;
112 3
    }
113
114 3
    public function setRequest($request)
115
    {
116 3
        $request = str_replace(['http://'.$this->domain.'/', 'https://'.$this->domain.'/'], '/', $request);
117 3
        list($method, $url, $httpVersion) = explode(' ', $request);
118 3
        $this->setMethod($method);
119 3
        $this->setUrl($url);
120 3
        $this->setHttpVersion($httpVersion);
121 3
    }
122
123
    public function getHttpVersion()
124
    {
125
        return $this->httpVersion;
126
    }
127
128 3
    public function setHttpVersion($httpVersion)
129
    {
130 3
        $this->httpVersion = $httpVersion;
131 3
    }
132
133
    public function getStatus()
134
    {
135
        return $this->status;
136
    }
137
138 3
    public function setStatus($status)
139
    {
140 3
        $this->status = $status;
141 3
    }
142
143
    public function getResponseBytes()
144
    {
145
        return $this->responseBytes;
146
    }
147
148 3
    public function setResponseBytes($responseBytes)
149
    {
150 3
        $this->responseBytes = $responseBytes;
151 3
    }
152
153
    public function getReferer()
154
    {
155
        return $this->referer;
156
    }
157
158 3
    protected function isInternalReferer($referer)
159
    {
160 3
        return 0 === strpos($referer, 'http://'.$this->domain) || 0 === strpos($referer, 'https://'.$this->domain);
161
    }
162
163 3
    public function setHeaderReferer($referer)
164
    {
165 3
        if (!empty($referer) && '-' != $referer) {
166 3
            $this->setReferer($referer);
167
        }
168 3
    }
169
170 3
    public function setReferer($referer)
171
    {
172 3
        $referer = $this->isInternalReferer($referer) ? null : $referer;
173
174 3
        $this->referer = $referer;
175 3
    }
176
177 3
    public function getUseragent()
178
    {
179 3
        return $this->useragent;
180
    }
181
182 3
    public function setHeaderUserAgent($useragent)
183
    {
184 3
        $this->setUserAgent($useragent);
185 3
    }
186
187 3
    public function setUseragent($useragent)
188
    {
189 3
        $this->useragent = $useragent;
190 3
    }
191
192
    public function ipAdressNumber($dotted)
193
    {
194
        $dotted = preg_split('/[.]+/', $dotted);
195
196
        return (float) ($dotted[0] * 16777216) + ($dotted[1] * 65536) + ($dotted[2] * 256) + ($dotted[3]);
197
    }
198
}
199