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

AnalyzerLogDirectoryReader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 40
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A collectVampires() 0 11 2
A create() 0 3 1
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