Completed
Push — master ( 0622b2...2b7c3d )
by Dev
12:57 queued 11:51
created

LogParser   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 76.47%

Importance

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

4 Methods

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