SingleResultFormatter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 40
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

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