DeepDumper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 21 4
1
<?php
2
3
namespace Dwo\Aggregator\Dumper;
4
5
use Dwo\Aggregator\Model\Aggregate;
6
use Symfony\Component\PropertyAccess\PropertyAccess;
7
8
/**
9
 * Class DeepDumper
10
 *
11
 * @author Dave Www <[email protected]>
12
 */
13
class DeepDumper
14
{
15
    /**
16
     * @param \Iterator $group
17
     *
18
     * @return array
19
     */
20
    public static function toArray(\Iterator $group)
21
    {
22
        $dump = array();
23
        $accessor = PropertyAccess::createPropertyAccessor();
24
25
        foreach ($group as $entry) {
26
            $values = array_values($entry->getGroup()->getKeys());
27
            $keys = sprintf('[%s]', implode('][', $values));
28
29
            if($entry instanceof \Iterator) {
30
                $entry = FlatDumper::toArray($entry);
31
            }
32
            else if($entry instanceof Aggregate) {
33
                $entry = $entry->getData();
34
            }
35
36
            $accessor->setValue($dump, $keys, $entry);
37
        }
38
39
        return $dump;
40
    }
41
}