| Conditions | 9 |
| Paths | 20 |
| Total Lines | 34 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 90 |
| Changes | 2 | ||
| 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 ($got instanceof \DateTimeImmutable) { |
||
| 36 | $got = $got->format('Y-m-d H:i:s'); |
||
| 37 | } |
||
| 38 | if (method_exists($got, '__toString')) { |
||
| 39 | $got = (string)$got; |
||
| 40 | } |
||
| 41 | if (false === is_scalar($got)) { |
||
| 42 | continue; |
||
| 43 | } |
||
| 44 | $property = $dsm->getPropertyNameFromGetterName($getter); |
||
| 45 | $toSerialize[$property] = $got; |
||
| 46 | } |
||
| 47 | |||
| 48 | return $toSerialize; |
||
| 49 | } |
||
| 54 | } |