Completed
Push — master ( 301313...fef224 )
by Florian
03:10
created

Document::addData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Cocur\Arff;
4
5
use Cocur\Arff\Column\ColumnInterface;
6
7
/**
8
 * ArffDocument.
9
 *
10
 * @author    Florian Eckerstorfer
11
 * @copyright 2015-2017 Florian Eckerstorfer
12
 */
13
class Document
14
{
15
    /**
16
     * @var string[]
17
     */
18
    protected static $allowedTypes = ['numeric', 'nominal', 'string', 'date'];
19
20
    /**
21
     * @var string
22
     */
23
    protected $name;
24
25
    /**
26
     * @var ColumnInterface[]
27
     */
28
    protected $columns = [];
29
30
    /**
31
     * @var array
32
     */
33
    protected $data = [];
34
35
    /**
36
     * @param string $name Name of the relation
37
     */
38 1
    public function __construct($name)
39
    {
40 1
        $this->name = $name;
41 1
    }
42
43
    /**
44
     * @return string
45
     */
46 1
    public function getName()
47
    {
48 1
        return $this->name;
49
    }
50
51
    /**
52
     * @param ColumnInterface $column
53
     *
54
     * @return Document
55
     */
56 1
    public function addColumn(ColumnInterface $column)
57
    {
58 1
        $this->columns[$column->getName()] = $column;
59
60 1
        return $this;
61
    }
62
63
    /**
64
     * @return ColumnInterface[]
65
     */
66 1
    public function getColumns()
67
    {
68 1
        return $this->columns;
69
    }
70
71
    /**
72
     * @param array $row
73
     *
74
     * @return Document
75
     */
76 2
    public function addData(array $row)
77
    {
78 2
        foreach ($this->columns as $name => $column) {
79 2
            if (!isset($row[$name])) {
80 2
                $row[$name] = '?';
81
            }
82
        }
83 2
        $this->data[] = $row;
84
85 2
        return $this;
86
    }
87
88
    /**
89
     * @return array
90
     */
91 2
    public function getData()
92
    {
93 2
        return $this->data;
94
    }
95
}
96