| Conditions | 3 |
| Paths | 9 |
| Total Lines | 13 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | public function getIdentifierValue(object $object): int|string|null |
||
| 17 | { |
||
| 18 | try { |
||
| 19 | $metadata = $this->entityManager->getClassMetadata(get_class($object)); |
||
| 20 | $entityClass = $metadata->getName(); |
||
| 21 | |||
| 22 | $identifier = $this->entityManager->getClassMetadata($entityClass)->getSingleIdentifierFieldName(); |
||
| 23 | $identifierGetter = 'get' . $identifier; |
||
| 24 | |||
| 25 | return $object->$identifierGetter(); |
||
| 26 | } catch (MappingException|HandlerFailedException) { |
||
| 27 | // object not mapped to doctrine, try with getId method or return null |
||
| 28 | return method_exists($object, 'getId') ? $object->getId() : null; |
||
| 29 | } |
||
| 32 |