Total Complexity | 9 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
22 | abstract class AbstractObject implements ObjectInterface |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * {@inheritDoc} |
||
27 | */ |
||
28 | 1 | public function toArray() : array |
|
29 | { |
||
30 | 1 | $fields = $this->getFields(); |
|
31 | |||
32 | 1 | $result = []; |
|
33 | 1 | foreach ($fields as $field => $value) { |
|
34 | 1 | if (!is_array($value)) { |
|
35 | 1 | $result[$field] = ($value instanceof ObjectInterface) ? $value->toArray() : $value; |
|
36 | 1 | continue; |
|
37 | } |
||
38 | |||
39 | 1 | foreach ($value as $key => $item) { |
|
40 | 1 | $result[$field][$key] = ($item instanceof ObjectInterface) ? $item->toArray() : $item; |
|
41 | } |
||
42 | } |
||
43 | |||
44 | 1 | return $result; |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * Gets only filled fields from the object |
||
49 | * |
||
50 | * @return array |
||
51 | */ |
||
52 | 1 | private function getFields() : array |
|
65 | } |
||
66 | } |
||
67 |