Completed
Pull Request — master (#120)
by Alessandro
09:14
created

AbstractText::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 6
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 5
    private $output;
19
20 5
    /** @var OutputFile */
21 5
    private $targetFile;
22
23
    /** @var bool */
24 2
    private $showColors;
25
26 2
    /**
27
     * AbstractText constructor.
28
     * @param OutputInterface $output
29
     * @param bool $showColors
30
     * @param bool $onlySummary
31
     * @param OutputFile|null $targetFile
32
     */
33
    public function __construct(OutputInterface $output, bool $showColors, bool $onlySummary, OutputFile $targetFile = null)
34
    {
35
        $this->text = new PHPUnitText(50, 90, false, $onlySummary);
36
        $this->output = $output;
37
        $this->targetFile = $targetFile;
38
        $this->showColors = $showColors;
39
    }
40
41
    /**
42
     * @param CodeCoverage $coverage
43
     * @throws \RuntimeException
44
     */
45
    public function process(CodeCoverage $coverage)
46
    {
47
        $coverageResults = $this->text->process($coverage, $this->showColors);
48
49
        if ($this->targetFile) {
50
            file_put_contents($this->targetFile->getFilePath(), $coverageResults);
51
        } else {
52
            $this->output->writeln($coverageResults);
53
        }
54
    }
55
}
56