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

MarkdownTableExporter::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 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
}