TPrettyTable   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 23
c 1
b 0
f 0
dl 0
loc 62
ccs 35
cts 35
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A resetTable() 0 3 1
A setTableDataLine() 0 4 1
A dumpTable() 0 16 5
A setTableColors() 0 4 1
A init() 0 4 2
A setTableHeaders() 0 4 1
A setTableColorsHeader() 0 4 1
1
<?php
2
3
namespace kalanis\kw_clipr\Output;
4
5
6
/**
7
 * Trait TPrettyTable
8
 * @package kalanis\kw_clipr\Output
9
 * @property bool $quiet
10
 */
11
trait TPrettyTable
12
{
13
    /**
14
     * @var PrettyTable
15
     */
16
    protected $prettyTable = null;
17
18 9
    public function setTableColors($values): void
19
    {
20 9
        $this->init();
21 9
        $this->prettyTable->setColors($values);
22 9
    }
23
24 2
    public function setTableColorsHeader($values): void
25
    {
26 2
        $this->init();
27 2
        $this->prettyTable->setColorsHeader($values);
28 2
    }
29
30 13
    public function setTableHeaders($values): void
31
    {
32 13
        $this->init();
33 13
        $this->prettyTable->setHeaders($values);
34 13
    }
35
36 8
    public function setTableDataLine($values): void
37
    {
38 8
        $this->init();
39 8
        $this->prettyTable->setDataLine($values);
40 8
    }
41
42 13
    private function init(): void
43
    {
44 13
        if (empty($this->prettyTable)) {
45 13
            $this->prettyTable = new PrettyTable();
46
        }
47 13
    }
48
49 10
    public function resetTable(): void
50
    {
51 10
        $this->prettyTable = null;
52 10
    }
53
54 10
    public function dumpTable(bool $displayHeader = true, bool $linesAround = true): void
55
    {
56 10
        if ($linesAround) {
57 10
            $this->writeLn($this->prettyTable->getSeparator());
58
        }
59 10
        if ($displayHeader) {
60 10
            $this->writeLn($this->prettyTable->getHeader());
61 10
            $this->writeLn($this->prettyTable->getSeparator());
62
        }
63 10
        foreach ($this->prettyTable as $row) {
64 8
            $this->writeLn($row);
65
        }
66 10
        if ($linesAround) {
67 10
            $this->writeLn($this->prettyTable->getSeparator());
68
        }
69 10
        $this->resetTable();
70 10
    }
71
72
    abstract public function writeLn(string $output = ''): void;
73
}
74