Completed
Push — master ( 00d60f...aabe5c )
by Dion
14s
created

FieldCommand::renderTable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 9.392
c 0
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
3
/*
4
 * This file is part of the SexyField package.
5
 *
6
 * (c) Dion Snoeijen <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare (strict_types = 1);
13
14
namespace Tardigrades\Command;
15
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Helper\Table;
18
use Symfony\Component\Console\Helper\TableCell;
19
use Symfony\Component\Console\Helper\TableSeparator;
20
use Symfony\Component\Console\Output\OutputInterface;
21
use Tardigrades\Entity\Field;
22
23
abstract class FieldCommand extends Command
24
{
25
    protected function renderTable(
26
        OutputInterface $output,
27
        array $fields,
28
        string $info
29
    ): void {
30
        $table = new Table($output);
31
32
        $rows = [];
33
        /** @var Field $field */
34
        foreach ($fields as $field) {
35
            $rows[] = [
36
                $field->getId(),
37
                $field->getName(),
38
                $field->getHandle(),
39
                $field->getFieldType()->getType(),
40
                (string) $field->getConfig(),
41
                $field->getUpdated()->format('d-m-y h:i')
42
            ];
43
        }
44
45
        $rows[] = new TableSeparator();
46
        $rows[] = [
47
            new TableCell('<info>' . $info . '</info>', ['colspan' => 7])
48
        ];
49
50
        $table
51
            ->setHeaders([
52
                '#id', 'name', 'handle',
53
                'type', 'config', 'updated'
54
            ])
55
            ->setRows($rows)
56
        ;
57
        $table->render();
58
    }
59
}
60