ShlinkTable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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