Completed
Pull Request — master (#69)
by Greg
01:51
created

simplifyToString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
namespace Consolidation\OutputFormatters\Transformations;
3
4
use Consolidation\OutputFormatters\Options\FormatterOptions;
5
6
class UnstructuredDataListTransformation extends \ArrayObject implements StringTransformationInterface
7
{
8
    public function __construct($data, $fields)
9
    {
10
        $this->originalData = $data;
0 ignored issues
show
Bug introduced by
The property originalData does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
11
        $rows = static::transformRows($data, $fields);
12
        parent::__construct($rows);
13
    }
14
15
    protected static function transformRows($data, $fields)
16
    {
17
        $rows = [];
18
        foreach ($data as $rowid => $row) {
19
            $rows[$rowid] = UnstructuredDataTransformation::transformRow($row, $fields);
20
        }
21
        return $rows;
22
    }
23
24
    public function simplifyToString(FormatterOptions $options)
25
    {
26
        $result = '';
27
        $iterator = $this->getIterator();
28
        while ($iterator->valid()) {
29
            $simplifiedRow = UnstructuredDataTransformation::simplifyRow($iterator->current());
30
            if (isset($simplifiedRow)) {
31
                $result .= "$simplifiedRow\n";
32
            }
33
34
            $iterator->next();
35
        }
36
        return $result;
37
    }
38
}
39