Conditions | 8 |
Paths | 12 |
Total Lines | 31 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 72 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php declare(strict_types=1); |
||
15 | public function jsonSerialize(): array |
||
16 | { |
||
17 | $dsm = static::getDoctrineStaticMeta(); |
||
18 | $toSerialize = []; |
||
19 | $getters = $dsm->getGetters(); |
||
20 | foreach ($getters as $getter) { |
||
21 | /** @var mixed $got */ |
||
22 | $got = $this->$getter(); |
||
23 | if ($got instanceof EntityInterface) { |
||
24 | continue; |
||
25 | } |
||
26 | if ($got instanceof Collection) { |
||
27 | continue; |
||
28 | } |
||
29 | if ($got instanceof Proxy) { |
||
30 | continue; |
||
31 | } |
||
32 | if ($got instanceof UuidInterface) { |
||
33 | $got = $got->toString(); |
||
34 | } |
||
35 | if (method_exists($got, '__toString')) { |
||
36 | $got = (string)$got; |
||
37 | } |
||
38 | if (false === is_scalar($got)) { |
||
39 | continue; |
||
40 | } |
||
41 | $property = $dsm->getPropertyNameFromGetterName($getter); |
||
42 | $toSerialize[$property] = $got; |
||
43 | } |
||
44 | |||
45 | return $toSerialize; |
||
46 | } |
||
51 | } |