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