UnstructuredDataFieldAccessor::get()   B
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 8.9617
c 0
b 0
f 0
cc 6
nc 5
nop 1
1
<?php
2
namespace Consolidation\OutputFormatters\Transformations;
3
4
use Dflydev\DotAccessData\Data;
5
6
class UnstructuredDataFieldAccessor
7
{
8
    protected $data;
9
10
    public function __construct($data)
11
    {
12
        $this->data = $data;
13
    }
14
15
    public function get($fields)
16
    {
17
        $data = new Data($this->data);
18
        $result = new Data();
19
        foreach ($fields as $key => $label) {
20
            $item = $data->get($key);
21
            if (isset($item)) {
22
                if ($label == '.') {
23
                    if (!is_array($item)) {
24
                        return $item;
25
                    }
26
                    foreach ($item as $key => $value) {
27
                        $result->set($key, $value);
28
                    }
29
                } else {
30
                    $result->set($label, $data->get($key));
31
                }
32
            }
33
        }
34
        return $result->export();
35
    }
36
}
37