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

AnalyzerLogDirectoryReader::collectVampires()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 11
ccs 0
cts 8
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Scheb\Tombstone\Analyzer\Log;
4
5
use Scheb\Tombstone\Analyzer\Cli\ConsoleOutput;
6
use Scheb\Tombstone\Analyzer\VampireIndex;
7
use SebastianBergmann\FinderFacade\FinderFacade;
8
9
class AnalyzerLogDirectoryReader implements LogReaderInterface
10
{
11
    /**
12
     * @var AnalyzerLogFileReader
13
     */
14
    private $logReader;
15
16
    /**
17
     * @var string
18
     */
19
    private $logDir;
20
21
    /**
22
     * @var ConsoleOutput
23
     */
24
    private $output;
25
26
    public function __construct(AnalyzerLogFileReader $logReader, string $logDir, ConsoleOutput $output)
27
    {
28
        $this->logReader = $logReader;
29
        $this->logDir = $logDir;
30
        $this->output = $output;
31
    }
32
33
    public static function create(string $logDir, ConsoleOutput $output): self
34
    {
35
        return new AnalyzerLogDirectoryReader(new AnalyzerLogFileReader(), $logDir, $output);
36
    }
37
38
    public function collectVampires(VampireIndex $vampireIndex): void
39
    {
40
        $finder = new FinderFacade([$this->logDir], [], ['*.tombstone']);
41
        $files = $finder->findFiles();
42
43
        $progress = $this->output->createProgressBar(count($files));
44
        foreach ($files as $file) {
45
            $this->logReader->aggregateLog($file, $vampireIndex);
46
            $progress->advance();
47
        }
48
        $this->output->writeln();
49
    }
50
}
51