ConsoleTableWriter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 59
rs 10
c 0
b 0
f 0
ccs 15
cts 17
cp 0.8824

4 Methods

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