Conditions | 5 |
Paths | 4 |
Total Lines | 23 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
34 | 26 | public function toArray(): array |
|
35 | { |
||
36 | 26 | $array = []; |
|
37 | |||
38 | 26 | $reflection = new ReflectionClass($this); |
|
39 | 26 | $classProperties = $reflection->getProperties(); |
|
40 | |||
41 | 26 | foreach ($classProperties as $classProperty) { |
|
42 | 25 | if ($classProperty->getValue($this)) { |
|
43 | 23 | $value = $classProperty->getValue($this); |
|
44 | 23 | $name = $classProperty->getName(); |
|
45 | |||
46 | 23 | $property = $this->getProperty($name); |
|
47 | |||
48 | 23 | if (\is_object($value) && \method_exists($value, 'toArray')) { |
|
49 | 9 | $array[$property->value] = $value->toArray(); |
|
50 | } else { |
||
51 | 23 | $array[$property->value] = $classProperty->getValue($this); |
|
52 | } |
||
53 | } |
||
54 | } |
||
55 | |||
56 | 26 | return $array; |
|
57 | } |
||
59 |