| Conditions | 12 |
| Paths | 257 |
| Total Lines | 63 |
| Code Lines | 35 |
| 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 |
||
| 79 | private function applyAuditableEvent(AuditableEvent $event, DomainMessage $domainMessage): void |
||
| 80 | { |
||
| 81 | $auditLogMetadata = $event->getAuditLogMetadata(); |
||
| 82 | |||
| 83 | $metadata = $domainMessage->getMetadata()->serialize(); |
||
| 84 | $entry = new AuditLogEntry(); |
||
| 85 | $entry->id = (string)Uuid::uuid4(); |
||
| 86 | |||
| 87 | if (isset($metadata['actorId'])) { |
||
| 88 | $actor = $this->identityRepository->find($metadata['actorId']); |
||
| 89 | |||
| 90 | if (!$actor instanceof Identity) { |
||
| 91 | throw new RuntimeException( |
||
| 92 | sprintf( |
||
| 93 | 'Cannot create AuditLogEntry, given Actor Identity "%s" does not exist', |
||
| 94 | $metadata['actorId'], |
||
| 95 | ), |
||
| 96 | ); |
||
| 97 | } |
||
| 98 | |||
| 99 | $entry->actorId = $metadata['actorId']; |
||
| 100 | $entry->actorCommonName = $actor->commonName; |
||
| 101 | } |
||
| 102 | |||
| 103 | $this->augmentActorCommonName($entry, $auditLogMetadata); |
||
| 104 | |||
| 105 | if (isset($metadata['actorInstitution'])) { |
||
| 106 | $entry->actorInstitution = new Institution($metadata['actorInstitution']); |
||
| 107 | } |
||
| 108 | |||
| 109 | $entry->identityId = (string)$auditLogMetadata->identityId; |
||
| 110 | $entry->identityInstitution = $auditLogMetadata->identityInstitution; |
||
| 111 | $entry->event = $event::class; |
||
| 112 | $entry->recordedOn = new DateTime(new CoreDateTime($domainMessage->getRecordedOn()->toString())); |
||
| 113 | |||
| 114 | if ($auditLogMetadata->secondFactorId instanceof SecondFactorId) { |
||
| 115 | $entry->secondFactorId = (string)$auditLogMetadata->secondFactorId; |
||
| 116 | } |
||
| 117 | |||
| 118 | if ($auditLogMetadata->secondFactorType instanceof SecondFactorType) { |
||
| 119 | $entry->secondFactorType = (string)$auditLogMetadata->secondFactorType; |
||
| 120 | } |
||
| 121 | |||
| 122 | if (!$event instanceof RecoveryTokenRevokedEvent |
||
|
|
|||
| 123 | && !$event instanceof CompliedWithRecoveryCodeRevocationEvent |
||
| 124 | && $auditLogMetadata->recoveryTokenId |
||
| 125 | ) { |
||
| 126 | $entry->recoveryTokenIdentifier = (string)$auditLogMetadata->recoveryTokenId; |
||
| 127 | } |
||
| 128 | |||
| 129 | if ($auditLogMetadata->recoveryTokenType instanceof RecoveryTokenType) { |
||
| 130 | $entry->recoveryTokenType = (string)$auditLogMetadata->recoveryTokenType; |
||
| 131 | } |
||
| 132 | |||
| 133 | if ($auditLogMetadata->secondFactorIdentifier instanceof SecondFactorIdentifier) { |
||
| 134 | $entry->secondFactorIdentifier = (string)$auditLogMetadata->secondFactorIdentifier; |
||
| 135 | } |
||
| 136 | |||
| 137 | if ($auditLogMetadata->raInstitution instanceof Institution) { |
||
| 138 | $entry->raInstitution = (string)$auditLogMetadata->raInstitution; |
||
| 139 | } |
||
| 140 | |||
| 141 | $this->auditLogRepository->save($entry); |
||
| 142 | } |
||
| 175 |