Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
UnflattedArray
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
3 / 3
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getValue
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUnflattenedArray
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3namespace BO\Zmsentities\Schema;
4
5class UnflattedArray
6{
7    protected $value = null;
8
9    public function __construct($value)
10    {
11        $this->value = $value;
12    }
13
14    public function getValue()
15    {
16        return $this->value;
17    }
18
19    /**
20      * split fields
21      * If a key to a field has two underscores "__" it should go into a subarray
22      * ATTENTION: performance critical function, keep highly optimized!
23      * @param  array $hash
24      *
25      * @return array
26      */
27    public function getUnflattenedArray()
28    {
29        $hash = $this->value;
30        foreach ($hash as $key => $value) {
31            if (false !== strpos($key, '__')) {
32                $currentLevel =& $hash;
33                unset($hash[$key]);
34                foreach (explode('__', $key) as $currentKey) {
35                    if (!isset($currentLevel[$currentKey])) {
36                        $currentLevel[$currentKey] = [];
37                    }
38                    $currentLevel =& $currentLevel[$currentKey];
39                }
40                $currentLevel = $value;
41            }
42        }
43        $this->value = $hash;
44        return (array)$hash;
45    }
46}