Completed
Pull Request — master (#1)
by Greg
02:06
created

TableTransformation   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 33
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A transformRow() 0 8 3
A getHeaders() 0 4 1
A getData() 0 4 1
1
<?php
2
namespace Consolidation\OutputFormatters\Transformations;
3
4
class TableTransformation
5
{
6
    protected $headers;
7
    protected $rows;
8
9
    public function __construct($data, $fieldLabels, $options)
0 ignored issues
show
Unused Code introduced by
The parameter $options 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...
10
    {
11
        $this->headers = array_values($fieldLabels);
12
        $this->rows = [];
13
        foreach ($data as $row) {
14
            $this->rows[] = $this->transformRow($row, $fieldLabels);
15
        }
16
    }
17
18
    protected function transformRow($row, $fieldLabels)
19
    {
20
        $result = [];
21
        foreach ($fieldLabels as $key => $label) {
22
            $result[$key] = array_key_exists($key, $row) ? $row[$key] : '';
23
        }
24
        return $result;
25
    }
26
27
    public function getHeaders()
28
    {
29
        return $this->headers;
30
    }
31
32
    public function getData()
33
    {
34
        return $this->rows;
35
    }
36
}
37