Passed
Push — master ( fab03e...ecd430 )
by Andrew
02:08
created

Csv   A

Complexity

Total Complexity 27

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 63.49%

Importance

Changes 0
Metric Value
wmc 27
lcom 1
cbo 1
dl 0
loc 131
ccs 40
cts 63
cp 0.6349
rs 10
c 0
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getData() 0 4 1
A getRowCount() 0 4 1
A appendRow() 0 4 1
A prependRow() 0 4 1
A columnExists() 0 4 1
A mapColumn() 0 9 3
A mapRows() 0 4 1
A filterRows() 0 4 1
A addColumn() 0 4 1
A removeColumn() 0 4 1
A removeRowByIndex() 0 4 1
A removeRow() 0 4 1
A removeRows() 0 4 1
A reorderColumn() 0 4 1
A reorderColumns() 0 4 1
A reorderRow() 0 4 1
A reorderRows() 0 4 1
A reorderRowsByColumn() 0 4 1
A reorderRowsByColumns() 0 4 1
A removeDuplicates() 0 11 2
A removeBlanks() 0 9 3
1
<?php
2
3
namespace CsvParser;
4
5
class Csv
6
{
7
    protected $data;
8
9 17
    public function __construct($array)
10
    {
11 17
        $this->data = $array;
12 17
    }
13
14 14
    public function getData()
15
    {
16 14
        return $this->data;
17
    }
18
19 1
    public function getRowCount()
20
    {
21 1
        return count($this->data);
22
    }
23
24 2
    public function appendRow($row)
25
    {
26 2
        array_unshift($this->data, $row);
27 2
    }
28
29 2
    public function prependRow($row)
30
    {
31 2
        $this->data[] = $row;
32 2
    }
33
34 2
    public function columnExists($column)
35
    {
36 2
        return isset($this->data[0][$column]);
37
    }
38
39 1
    public function mapColumn($column, $callback)
40
    {
41 1
        if ( ! $this->columnExists($column)) {
42
            throw new Exception('Column does not exist');
43
        }
44 1
        foreach ($this->data as $i => $row) {
45 1
            $this->data[$i][$column] = $callback($row[$column]);
46
        }
47 1
    }
48
49 1
    public function mapRows($callback)
50
    {
51 1
        $this->data = array_map($callback, $this->data);
52 1
    }
53
54 3
    public function filterRows($callback)
55
    {
56 3
        $this->data = array_filter($this->data, $callback);
57 3
    }
58
59
    public function addColumn($column, $default='')
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $default is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
    {
61
        // TODO
62
    }
63
64
    public function removeColumn($column)
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
    {
66
        // TODO
67
    }
68
69
    public function removeRowByIndex($index)
0 ignored issues
show
Unused Code introduced by
The parameter $index is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
    {
71
        // TODO
72
    }
73
74
    public function removeRow($col, $val)
0 ignored issues
show
Unused Code introduced by
The parameter $col is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $val is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
    {
76
        // TODO
77
    }
78
79
    public function removeRows($rows)
0 ignored issues
show
Unused Code introduced by
The parameter $rows is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
    {
81
        // TODO
82
    }
83
84
    public function reorderColumn($col, $index)
0 ignored issues
show
Unused Code introduced by
The parameter $col is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $index is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
    {
86
        // TODO
87
    }
88
89
    public function reorderColumns($rows)
0 ignored issues
show
Unused Code introduced by
The parameter $rows is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90
    {
91
        // TODO
92
    }
93
94
    public function reorderRow($col, $val, $index)
0 ignored issues
show
Unused Code introduced by
The parameter $col is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $val is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $index is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
95
    {
96
        // TODO
97
    }
98
99
    public function reorderRows($rows)
0 ignored issues
show
Unused Code introduced by
The parameter $rows is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
100
    {
101
        // TODO
102
    }
103
104
    public function reorderRowsByColumn($column, $type='asc')
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
105
    {
106
        // TODO
107
    }
108
109
    public function reorderRowsByColumns($columns)
0 ignored issues
show
Unused Code introduced by
The parameter $columns is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
110
    {
111
        // TODO
112
    }
113
114 1
    public function removeDuplicates($column)
115
    {
116 1
        $index = array();
117
        $this->filterRows(function ($row) use ($column, &$index) {
118 1
            if (in_array($row[$column], $index)) {
119 1
                return false;
120
            }
121 1
            $index[] = $row[$column];
122 1
            return true;
123 1
        });
124 1
    }
125
126
    public function removeBlanks($column)
127
    {
128 1
        $this->filterRows(function ($row) use ($column) {
129 1
            if ( ! isset($row[$column]) || trim($row[$column])==='') {
130 1
                return false;
131
            }
132 1
            return true;
133 1
        });
134 1
    }
135
}
136