Duplicates   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 32
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1
ccs 23
cts 23
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 26 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