Completed
Push — master ( 29c7fd...0622b2 )
by Dev
53:37 queued 52:34
created

LogParser   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
eloc 14
dl 0
loc 38
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setDomain() 0 3 1
A createEntry() 0 3 2
A parse() 0 15 4
A setType() 0 3 1
1
<?php
2
3
namespace PiedWeb\LogsAnalyzer;
4
5
class LogParser extends \Kassner\LogParser\LogParser
6
{
7
    protected $domain;
8
    protected $type;
9
10
    public function setDomain(string $domain)
11
    {
12
        $this->domain = $domain;
13
    }
14
15
    public function setType(string $type)
16
    {
17
        $this->type = $type;
18
    }
19
20
    public function parse($line)
21
    {
22
        if (!preg_match($this->pcreFormat, $line, $matches)) {
23
            throw new \Kassner\LogParser\FormatException($line);
24
        }
25
26
        $entry = $this->createEntry();
27
        foreach (array_filter(array_keys($matches), 'is_string') as $key) {
28
            $setter = 'set'.$key;
29
            if (method_exists($entry, $setter)) {
30
                $entry->$setter($matches[$key]);
31
            }
32
        }
33
34
        return $entry;
35
    }
36
37
    /**
38
     * @return LogLine
39
     */
40
    protected function createEntry()
41
    {
42
        return null === $this->type ? new LogLine($this->domain) : new $this->type($this->domain);
43
    }
44
}
45