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

TableTransformation::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 3
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