Completed
Pull Request — master (#94)
by Alessandro
04:59
created

ProcessPrinter::printFormattedWithCounter()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 2
nop 1
crap 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Paraunit\Printer;
5
6
use Paraunit\Lifecycle\ProcessEvent;
7
use Paraunit\TestResult\Interfaces\PrintableTestResultInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Class ProcessPrinter
12
 * @package Paraunit\Printer
13
 */
14
class ProcessPrinter
15
{
16
    /** @var  SingleResultFormatter */
17
    private $singleResultFormatter;
18
19
    /** @var  OutputInterface */
20
    private $output;
21
22
    /** @var int */
23
    private $counter = 0;
24
25
    /**
26
     * ProcessPrinter constructor.
27
     * @param SingleResultFormatter $singleResultFormatter
28
     * @param OutputInterface $output
29
     */
30 33
    public function __construct(SingleResultFormatter $singleResultFormatter, OutputInterface $output)
31
    {
32 33
        $this->singleResultFormatter = $singleResultFormatter;
33 33
        $this->output = $output;
34
    }
35
36
    /**
37
     * @param ProcessEvent $processEvent
38
     * @throws \BadMethodCallException
39
     */
40 33
    public function onProcessParsingCompleted(ProcessEvent $processEvent)
41
    {
42 33
        $process = $processEvent->getProcess();
43
44 33
        foreach ($process->getTestResults() as $testResult) {
45 33
            $this->printFormattedWithCounter($testResult);
46
        }
47
    }
48
49
    /**
50
     * @param PrintableTestResultInterface $testResult
51
     */
52 33
    private function printFormattedWithCounter(PrintableTestResultInterface $testResult)
53
    {
54 33
        if ($this->counter % 80 === 0 && $this->counter > 1) {
55 6
            $this->output->writeln('');
56
        }
57
58 33
        ++$this->counter;
59
60 33
        $this->output->write(
61 33
            $this->singleResultFormatter->formatSingleResult($testResult)
62
        );
63
    }
64
}
65