Passed
Push — master ( 6c908c...829dc3 )
by Fabien
01:49
created

MarkdownResultsRenderer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
c 1
b 0
f 0
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A inline() 0 9 2
A render() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Churn\Result\Render;
6
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
/**
10
 * @internal
11
 */
12
final class MarkdownResultsRenderer implements ResultsRendererInterface
13
{
14
    /**
15
     * Renders the results.
16
     *
17
     * @param OutputInterface $output Output Interface.
18
     * @param array<array<float|integer|string>> $results The results.
19
     */
20
    public function render(OutputInterface $output, array $results): void
21
    {
22
        $output->writeln('| File | Times Changed | Complexity | Score |');
23
        $output->writeln('|------|---------------|------------|-------|');
24
25
        foreach ($results as $result) {
26
            $output->writeln($this->inline($result));
27
        }
28
    }
29
30
    /**
31
     * @param array<float|integer|string> $data The data to inline.
32
     */
33
    private function inline(array $data): string
34
    {
35
        $escapedData = \array_map(static function ($item) {
36
            return \is_string($item)
37
                ? \str_replace('|', '\\|', $item)
38
                : $item;
39
        }, $data);
40
41
        return '| ' . \implode(' | ', $escapedData) . ' |';
42
    }
43
}
44