Passed
Pull Request — master (#456)
by Alejandro
06:37 queued 01:57
created

ShlinkTable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 16
dl 0
loc 31
rs 10
c 0
b 0
f 0
ccs 15
cts 15
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromOutput() 0 3 1
A render() 0 13 1
A __construct() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\CLI\Util;
5
6
use Symfony\Component\Console\Helper\Table;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
final class ShlinkTable
10
{
11
    private const DEFAULT_STYLE_NAME = 'default';
12
    private const TABLE_TITLE_STYLE = '<options=bold> %s </>';
13
14
    /** @var Table|null */
15
    private $baseTable;
16
17 14
    public function __construct(Table $baseTable)
18
    {
19 14
        $this->baseTable = $baseTable;
20
    }
21
22 13
    public static function fromOutput(OutputInterface $output): self
23
    {
24 13
        return new self(new Table($output));
25
    }
26
27 13
    public function render(array $headers, array $rows, ?string $footerTitle = null, ?string $headerTitle = null): void
28
    {
29 13
        $style = Table::getStyleDefinition(self::DEFAULT_STYLE_NAME);
30 13
        $style->setFooterTitleFormat(self::TABLE_TITLE_STYLE)
31 13
              ->setHeaderTitleFormat(self::TABLE_TITLE_STYLE);
32
33 13
        $table = clone $this->baseTable;
34 13
        $table->setStyle($style)
35 13
              ->setHeaders($headers)
36 13
              ->setRows($rows)
37 13
              ->setFooterTitle($footerTitle)
38 13
              ->setHeaderTitle($headerTitle)
39 13
              ->render();
40
    }
41
}
42