TableWriter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A writeItem() 0 9 2
A finish() 0 7 2
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