DeepDumper::toArray()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 12
nc 4
nop 1
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
}