| Conditions | 10 |
| Paths | 129 |
| Total Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 76 | private function applyAuditableEvent(AuditableEvent $event, DomainMessage $domainMessage) |
||
| 77 | { |
||
| 78 | $auditLogMetadata = $event->getAuditLogMetadata(); |
||
| 79 | $metadata = $domainMessage->getMetadata()->serialize(); |
||
| 80 | |||
| 81 | $entry = new AuditLogEntry(); |
||
| 82 | $entry->id = (string) Uuid::uuid4(); |
||
| 83 | |||
| 84 | if (isset($metadata['actorId'])) { |
||
| 85 | $actor = $this->identityRepository->find($metadata['actorId']); |
||
| 86 | |||
| 87 | if (!$actor) { |
||
| 88 | throw new RuntimeException(sprintf( |
||
| 89 | 'Cannot create AuditLogEntry, given Actor Identity "%s" does not exist', |
||
| 90 | $metadata['actorId'] |
||
| 91 | )); |
||
| 92 | } |
||
| 93 | |||
| 94 | $entry->actorId = $metadata['actorId']; |
||
| 95 | $entry->actorCommonName = $actor->commonName; |
||
| 96 | } |
||
| 97 | if ($event instanceof SecondFactorVettedEvent || |
||
| 98 | $event instanceof SecondFactorVettedWithoutTokenProofOfPossession |
||
| 99 | ) { |
||
| 100 | $entry->actorCommonName .= $event->vettingType->auditLog(); |
||
| 101 | } |
||
| 102 | |||
| 103 | if (isset($metadata['actorInstitution'])) { |
||
| 104 | $entry->actorInstitution = $metadata['actorInstitution']; |
||
| 105 | } |
||
| 106 | |||
| 107 | $entry->identityId = (string) $auditLogMetadata->identityId; |
||
| 108 | $entry->identityInstitution = $auditLogMetadata->identityInstitution; |
||
| 109 | $entry->event = get_class($event); |
||
| 110 | $entry->recordedOn = new DateTime(new CoreDateTime($domainMessage->getRecordedOn()->toString())); |
||
| 111 | |||
| 112 | if ($auditLogMetadata->secondFactorId) { |
||
| 113 | $entry->secondFactorId = (string) $auditLogMetadata->secondFactorId; |
||
| 114 | } |
||
| 115 | |||
| 116 | if ($auditLogMetadata->secondFactorType) { |
||
| 117 | $entry->secondFactorType = (string) $auditLogMetadata->secondFactorType; |
||
| 118 | } |
||
| 119 | |||
| 120 | if ($auditLogMetadata->secondFactorIdentifier) { |
||
| 121 | $entry->secondFactorIdentifier = (string) $auditLogMetadata->secondFactorIdentifier; |
||
| 122 | } |
||
| 123 | |||
| 124 | if ($auditLogMetadata->raInstitution) { |
||
| 125 | $entry->raInstitution = (string) $auditLogMetadata->raInstitution; |
||
| 126 | } |
||
| 127 | |||
| 128 | $this->auditLogRepository->save($entry); |
||
| 129 | } |
||
| 130 | |||
| 142 |