TableWriter::writeItem()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Port\SymfonyConsole;
4
5
use Port\Writer;
6
use Port\Writer\WriterTemplate;
7
use Symfony\Component\Console\Helper\Table;
8
9
/**
10
 * @author Igor Mukhin <[email protected]>
11
 */
12
class TableWriter implements Writer
13
{
14
    use WriterTemplate;
15
16
    /**
17
     * @var Table
18
     */
19
    private $table;
20
21
    /**
22
     * @var array
23
     */
24
    private $firstItem;
25
26
    /**
27
     * @param Table $table
28
     */
29
    public function __construct(Table $table) {
30
        $this->table = $table;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function writeItem(array $item) {
37
38
        // Save first item to get keys to display at header
39
        if (is_null($this->firstItem)) {
40
            $this->firstItem = $item;
41
        }
42
43
        $this->table->addRow($item);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function finish() {
50
        $headers = $this->firstItem ? array_keys($this->firstItem) : [];
51
        $this->table->setHeaders($headers);
52
        $this->table->render();
53
54
        $this->firstItem = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array of property $firstItem.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
    }
56
}
57