Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
17.02% |
8 / 47 |
|
9.09% |
1 / 11 |
CRAP | |
0.00% |
0 / 1 |
Base | |
17.02% |
8 / 47 |
|
9.09% |
1 / 11 |
475.94 | |
0.00% |
0 / 1 |
getId | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPath | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
hasValidOffset | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
4 | |||
getLocale | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getLink | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getType | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
subcount | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
__set | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
offsetSet | |
40.00% |
4 / 10 |
|
0.00% |
0 / 1 |
7.46 | |||
doubleUnterlineToArray | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | /** |
4 | * @package Zmsdldb |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsdldb\Entity; |
9 | |
10 | class Base extends \ArrayObject |
11 | { |
12 | /** |
13 | * return an ID for this entity |
14 | * |
15 | */ |
16 | public function getId() |
17 | { |
18 | if (!$this->offsetExists('id')) { |
19 | return false; |
20 | } |
21 | return $this['id']; |
22 | } |
23 | |
24 | /** |
25 | * return a name for this entity |
26 | * |
27 | */ |
28 | public function getName() |
29 | { |
30 | return $this['name']; |
31 | } |
32 | |
33 | /** |
34 | * return a path for this entity |
35 | * |
36 | */ |
37 | public function getPath() |
38 | { |
39 | if (!$this->offsetExists('path')) { |
40 | return false; |
41 | } |
42 | return $this['path']; |
43 | } |
44 | |
45 | public static function hasValidOffset($item, $index) |
46 | { |
47 | return ( |
48 | (is_object($item) && $item->offsetExists($index)) || |
49 | (is_array($item) && array_key_exists($index, $item)) |
50 | ); |
51 | } |
52 | |
53 | public function getLocale() |
54 | { |
55 | $meta = $this['meta']; |
56 | if (false === static::hasValidOffset($meta, 'locale')) { |
57 | return false; |
58 | } |
59 | return $this['meta']['locale']; |
60 | } |
61 | |
62 | public function getLink() |
63 | { |
64 | if (!$this->offsetExists('link')) { |
65 | return false; |
66 | } |
67 | return $this['link']; |
68 | } |
69 | |
70 | public function getType() |
71 | { |
72 | if (!$this->offsetExists('type')) { |
73 | return false; |
74 | } |
75 | return $this['type']; |
76 | } |
77 | |
78 | protected static function subcount($countable) |
79 | { |
80 | if (is_array($countable) || $countable instanceof \Countable) { |
81 | return count($countable); |
82 | } |
83 | return null; |
84 | } |
85 | |
86 | public function __set($name, $value) |
87 | { |
88 | $this->offsetSet($name, $value); |
89 | } |
90 | |
91 | public function offsetSet($index, $value): void |
92 | { |
93 | if ('data_json' == $index) { |
94 | $value = json_decode($value, true); |
95 | $this->exchangeArray($value); |
96 | } else { |
97 | if (stripos($index, '_json')) { |
98 | $value = json_decode($value, true); |
99 | $index = str_replace('_json', '', $index); |
100 | } |
101 | if (stripos($index, '__')) { |
102 | static::doubleUnterlineToArray($this, $index, $value); |
103 | return; |
104 | } |
105 | |
106 | parent::offsetSet($index, $value); |
107 | } |
108 | } |
109 | |
110 | public static function doubleUnterlineToArray(&$array, $key, $value) |
111 | { |
112 | if (is_null($key)) { |
113 | return $array = $value; |
114 | } |
115 | $keys = explode('__', $key); |
116 | |
117 | $numKeys = count($keys); |
118 | while ($numKeys > 1) { |
119 | $key = array_shift($keys); |
120 | $numKeys = count($keys); |
121 | if (! isset($array[$key]) || ! is_array($array[$key])) { |
122 | $array[$key] = []; |
123 | } |
124 | |
125 | $array = &$array[$key]; |
126 | } |
127 | |
128 | $array[array_shift($keys)] = $value; |
129 | |
130 | return $array; |
131 | } |
132 | } |