| Conditions | 4 |
| Paths | 4 |
| Total Lines | 19 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 38 | 1 | public function prePersist(LifecycleEventArgs $args) |
|
| 39 | { |
||
| 40 | 1 | $entityManager = $args->getEntityManager(); |
|
| 41 | 1 | $object = $args->getObject(); |
|
| 42 | 1 | $metadata = $entityManager->getClassMetadata(get_class($object)); |
|
| 43 | |||
| 44 | 1 | foreach ($metadata->getFieldNames() as $field) { |
|
| 45 | 1 | $type = $metadata->getTypeOfField($field); |
|
| 46 | 1 | if ($type === Type::GUID) { |
|
| 47 | 1 | $property = $metadata->getReflectionProperty($field); |
|
| 48 | 1 | $value = $property->getValue($object); |
|
| 49 | |||
| 50 | 1 | if (empty($value)) { |
|
| 51 | 1 | $guid = $this->guidGenerator->generate($entityManager, $object); |
|
| 52 | 1 | $property->setValue($object, $guid); |
|
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | 1 | } |
|
| 57 | } |
||
| 58 |