Completed
Push — master ( a6c8f9...b97be3 )
by Vladimir
03:52 queued 19s
created

CsvTransformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 29
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transformData() 0 13 2
A getExtensions() 0 6 1
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\DataTransformer;
9
10
class CsvTransformer implements DataTransformer
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 3
    public static function transformData($content)
16
    {
17 3
        $rows = array_map('str_getcsv', explode("\n", trim($content)));
18 3
        $columns = array_shift($rows);
19 3
        $csv = [];
20
21 3
        foreach ($rows as $row)
22
        {
23 2
            $csv[] = array_combine($columns, $row);
24 3
        }
25
26 3
        return $csv;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 7
    public static function getExtensions()
33
    {
34
        return [
35 7
            'csv',
36 7
        ];
37
    }
38
}
39