Completed
Push — master ( 605dcd...eeb8ed )
by Nate
02:13
created

ArrayData::normalizeData()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 18
cp 0
rs 8.439
c 0
b 0
f 0
cc 5
eloc 12
nc 7
nop 2
crap 30
1
<?php
2
3
/**
4
 * @author    Flipbox Factory
5
 * @copyright Copyright (c) 2017, Flipbox Digital
6
 * @link      https://github.com/flipbox/transform/releases/latest
7
 * @license   https://github.com/flipbox/transform/blob/master/LICENSE
8
 */
9
10
namespace Flipbox\Transform\Transformers\Traits;
11
12
use Flipbox\Transform\Resources\ResourceInterface;
13
use Flipbox\Transform\Scope;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
trait ArrayData
20
{
21
    /**
22
     * @param $data
23
     * @param Scope $scope
24
     * @return array
25
     */
26
    protected function normalizeData(array $data, Scope $scope)
27
    {
28
        $includedData = [];
29
30
        // Bail now
31
        if (null === $data) {
32
            return $includedData;
33
        }
34
35
        if (is_string($data)) {
36
            $data = [$data];
37
        }
38
39
        foreach ($data as $key => $val) {
40
            if (!$scope->includeValue($this, $key)) {
41
                continue;
42
            }
43
            $includedData[$key] = $scope->parseValue($val, $data, $key);
44
        }
45
46
        // Return only the requested fields
47
        $includedData = $scope->filterFields($includedData);
48
49
        return $includedData;
50
    }
51
}
52