ConsoleTableWriter::getTable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Ddeboer\DataImport\Writer;
4
5
use Ddeboer\DataImport\Writer;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Console\Helper\Table;
8
9
/**
10
 * @author Igor Mukhin <[email protected]>
11
 */
12
class ConsoleTableWriter implements Writer
13
{
14
    use WriterTemplate;
15
16
    /**
17
     * @var OutputInterface
18
     */
19
    private $output;
20
21
    /**
22
     * @var Table
23
     */
24
    private $table;
25
26
    /**
27
     * @var array
28
     */
29
    private $firstItem;
30
31
    /**
32
     * @param OutputInterface $output
33
     * @param Table           $table
34
     */
35 1
    public function __construct(OutputInterface $output, Table $table) {
36 1
        $this->output = $output;
37 1
        $this->table = $table;
38 1
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 1
    public function writeItem(array $item) {
44
45
        // Save first item to get keys to display at header
46 1
        if (is_null($this->firstItem)) {
47 1
            $this->firstItem = $item;
48 1
        }
49
50 1
        $this->table->addRow($item);
51 1
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 1
    public function finish() {
57 1
        $this->table->setHeaders(array_keys($this->firstItem));
58 1
        $this->table->render();
59
60 1
        $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...
61 1
    }
62
63
    /**
64
     * @return Table
65
     */
66
    public function getTable()
67
    {
68
        return $this->table;
69
    }
70
}
71