Passed
Push — master ( 724c6f...9da6fd )
by Rafael
06:22
created

MarkdownTableExporter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 39
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
B export() 0 26 2
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Error\Exporter;
12
13
use Symfony\Component\Console\Helper\Table;
14
use Symfony\Component\Console\Helper\TableStyle;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class MarkdownTableExporter implements ErrorListExporterInterface
18
{
19
    /**
20
     * {@inheritDoc}
21
     */
22
    public function getName(): string
23
    {
24
        return 'markdown';
25
    }
26
27
    /**
28
     * @inheritDoc
29
     */
30
    public function export($errors, OutputInterface $output): void
31
    {
32
        $rows = [
33
            ['Code', 'Text', 'Description'],
34
            ['---', '---', '---'],
35
        ];
36
        foreach ($errors as $error) {
37
            $description = str_replace(["\n\n", "\n"], ['<br>', null], $error->getDescription());
38
            $rows[] = [
39
                sprintf('**%s**', $error->getCode()),
40
                sprintf('**%s**', $error->getMessage()),
41
                $description,
42
            ];
43
        }
44
45
        $table = new Table($output);
46
47
        $styleGuide = new TableStyle();
48
        $styleGuide->setHorizontalBorderChar('')
49
                   ->setVerticalBorderChar('|')
50
                   ->setCrossingChar(' ')
51
                   ->setCellHeaderFormat('%s');
52
53
        $table->setStyle($styleGuide);
54
        $table->setRows($rows);
55
        $table->render();
56
    }
57
}