Passed
Push — master ( cc91a3...057c43 )
by Christian
02:20
created

ReportExporter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 33
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A generate() 0 15 4
1
<?php
2
3
namespace Scheb\Tombstone\Analyzer\Report;
4
5
use Scheb\Tombstone\Analyzer\AnalyzerResult;
6
use Scheb\Tombstone\Analyzer\Cli\ConsoleOutput;
7
8
class ReportExporter
9
{
10
    /**
11
     * @var ConsoleOutput
12
     */
13
    private $output;
14
15
    /**
16
     * @var ReportGeneratorInterface[]
17
     */
18
    private $reportGenerators;
19
20
    public function __construct(ConsoleOutput $output, array $reportGenerators)
21
    {
22
        $this->output = $output;
23
        $this->reportGenerators = $reportGenerators;
24
    }
25
26
    public function generate(AnalyzerResult $result): void
27
    {
28
        $i = 0;
29
        foreach ($this->reportGenerators as $reportGenerator) {
30
            if ($i > 0) {
31
                $this->output->writeln();
32
            }
33
            $generatorName = $reportGenerator->getName();
34
            ++$i;
35
            $this->output->write('Generate '.$generatorName.' report... ');
36
            try {
37
                $reportGenerator->generate($result);
38
                $this->output->writeln('Done');
39
            } catch (\Exception $e) {
40
                $this->output->writeln('Could not generate '.$generatorName.' report: '.$e->getMessage());
41
            }
42
        }
43
    }
44
}
45