Duplicates::parse()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 26
c 0
b 0
f 0
ccs 23
cts 23
cp 1
rs 9.1928
cc 5
nc 5
nop 1
crap 5
1
<?php
2
3
namespace Maketok\DataMigration\Input\Shaper\Processor;
4
5
use Maketok\DataMigration\Input\Shaper\Processor;
6
7
class Duplicates extends Processor
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12 8
    public function parse(array $entity)
13
    {
14 8
        $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($entity));
15 8
        $current = [];
16 8
        $res = [];
17 8
        $depthMap = [];
18 8
        $prevDepth = 0;
19 8
        foreach ($iterator as $key => $value) {
20 8
            $depth = $iterator->getDepth();
21 8
            if ($depth < $prevDepth) {
22 1
                $res[] = $current;
23 1
                $depthMap = [];
24 1
            }
25 8
            if (isset($depthMap[$depth]) && in_array($key, $depthMap[$depth])) {
26 5
                $res[] = $current;
27 5
                $depthMap = [];
28 5
                $depthMap[$depth][] = $key;
29 5
            } else {
30 8
                $depthMap[$depth][] = $key;
31
            }
32 8
            $current[$key] = $value;
33 8
            $prevDepth = $depth;
34 8
        }
35 8
        $res[] = $current;
36 8
        return $res;
37
    }
38
}
39