Passed
Push — master ( d29b77...fa6b97 )
by Christian
01:54
created

AnalyzerLogFileReader::aggregateLog()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 4
nop 2
dl 0
loc 15
ccs 0
cts 10
cp 0
crap 20
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Scheb\Tombstone\Analyzer\Log;
4
5
use Scheb\Tombstone\Analyzer\Exception\LogReaderException;
6
use Scheb\Tombstone\Analyzer\VampireIndex;
7
use Scheb\Tombstone\Logging\AnalyzerLogFormat;
8
9
class AnalyzerLogFileReader
10
{
11
    public function aggregateLog(string $file, VampireIndex $vampireIndex): void
12
    {
13
        $handle = fopen($file, 'r');
14
        if (false === $handle) {
15
            throw new LogReaderException('Could not read log file '.$file);
16
        }
17
18
        while (!feof($handle)) {
19
            $line = fgets($handle);
20
            $vampire = AnalyzerLogFormat::logToVampire($line);
21
            if ($vampire) {
22
                $vampireIndex->addVampire($vampire);
23
            }
24
        }
25
        fclose($handle);
26
    }
27
}
28