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      *
24      * @return array
25      */
26    public function getUnflattenedArray()
27    {
28        $hash = $this->value;
29        foreach ($hash as $key => $value) {
30            if (false !== strpos($key, '__')) {
31                $currentLevel =& $hash;
32                unset($hash[$key]);
33                foreach (explode('__', $key) as $currentKey) {
34                    if (!isset($currentLevel[$currentKey])) {
35                        $currentLevel[$currentKey] = [];
36                    }
37                    $currentLevel =& $currentLevel[$currentKey];
38                }
39                $currentLevel = $value;
40            }
41        }
42        $this->value = $hash;
43        return (array)$hash;
44    }
45}