MarkdownResultsRenderer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A inline() 0 9 2
A render() 0 8 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
    #[\Override]
21
    public function render(OutputInterface $output, array $results): void
22
    {
23
        $output->writeln('| File | Times Changed | Complexity | Score |');
24
        $output->writeln('|------|---------------|------------|-------|');
25
26
        foreach ($results as $result) {
27
            $output->writeln($this->inline($result));
28
        }
29
    }
30
31
    /**
32
     * @param array<float|integer|string> $data The data to inline.
33
     */
34
    private function inline(array $data): string
35
    {
36
        $escapedData = \array_map(static function ($item) {
37
            return \is_string($item)
38
                ? \str_replace('|', '\\|', $item)
39
                : $item;
40
        }, $data);
41
42
        return '| ' . \implode(' | ', $escapedData) . ' |';
43
    }
44
}
45