Completed
Push — master ( 9a7b87...ad20a3 )
by Alessandro
03:07
created

SingleResultFormatter::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 12
1
<?php
2
declare(strict_types=1);
3
4
namespace Paraunit\Printer;
5
6
use Paraunit\TestResult\Interfaces\PrintableTestResultInterface;
7
use Paraunit\TestResult\TestResultList;
8
use Paraunit\TestResult\TestResultWithSymbolFormat;
9
10
/**
11
 * Class SingleResultFormatter
12
 * @package Paraunit\Printer
13
 */
14
class SingleResultFormatter
15
{
16
    /** @var  array */
17
    private $tagMap;
18
19
    /**
20
     * SingleResultFormatter constructor.
21
     * @param TestResultList $testResultList
22
     */
23
    public function __construct(TestResultList $testResultList)
24
    {
25
        $this->tagMap = [];
26
27
        foreach ($testResultList->getTestResultContainers() as $parser) {
28
            $format = $parser->getTestResultFormat();
29
            if ($format instanceof TestResultWithSymbolFormat) {
30
                $this->addToMap($format);
31
            }
32
        }
33
    }
34
35
    public function formatSingleResult(PrintableTestResultInterface $singleResult): string
36
    {
37
        $format = $singleResult->getTestResultFormat();
38
39
        if (! $format instanceof TestResultWithSymbolFormat) {
40
            return '';
41
        }
42
43
        $resultSymbol = $format->getTestResultSymbol();
44
        $tag = $this->tagMap[$resultSymbol];
45
46
        return sprintf('<%s>%s</%s>', $tag, $resultSymbol, $tag);
47
    }
48
49
    private function addToMap(TestResultWithSymbolFormat $format)
50
    {
51
        $this->tagMap[$format->getTestResultSymbol()] = $format->getTag();
52
    }
53
}
54