Completed
Push — master ( aab589...178fab )
by Alessandro
12s
created

AbstractText::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paraunit\Coverage\Processor;
6
7
use Paraunit\Configuration\OutputFile;
8
use SebastianBergmann\CodeCoverage\CodeCoverage;
9
use SebastianBergmann\CodeCoverage\Report\Text as PHPUnitText;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
abstract class AbstractText implements CoverageProcessorInterface
13
{
14
    /** @var PHPUnitText */
15
    private $text;
16
17
    /** @var OutputInterface */
18
    private $output;
19
20
    /** @var OutputFile */
21
    private $targetFile;
22
23
    /** @var bool */
24
    private $showColors;
25
26
    /**
27
     * AbstractText constructor.
28
     * @param OutputInterface $output
29
     * @param bool $showColors
30
     * @param bool $onlySummary
31
     * @param OutputFile|null $targetFile
32
     */
33 12
    public function __construct(OutputInterface $output, bool $showColors, bool $onlySummary, OutputFile $targetFile = null)
34
    {
35 12
        $this->text = new PHPUnitText(50, 90, false, $onlySummary);
36 12
        $this->output = $output;
37 12
        $this->targetFile = $targetFile;
38 12
        $this->showColors = $showColors;
39
    }
40
41
    /**
42
     * @param CodeCoverage $coverage
43
     * @throws \RuntimeException
44
     */
45 9
    public function process(CodeCoverage $coverage)
46
    {
47 9
        $coverageResults = $this->text->process($coverage, $this->showColors);
48
49 9
        if ($this->targetFile) {
50 5
            file_put_contents($this->targetFile->getFilePath(), $coverageResults);
51
        } else {
52 4
            $this->output->writeln($coverageResults);
53
        }
54
    }
55
}
56