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

AbstractText   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 44
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A process() 0 10 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