| Conditions | 23 |
| Paths | 7680 |
| Total Lines | 81 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 104 | protected function getInternalFormat(AbstractLogEntry $context): array |
||
| 105 | { |
||
| 106 | $array = []; |
||
| 107 | if ($context instanceof UserLoginLogEntry || $context instanceof UserLogoutLogEntry) { |
||
| 108 | $array['log.user_login.ip'] = htmlspecialchars($context->getIPAddress()); |
||
| 109 | } |
||
| 110 | |||
| 111 | if ($context instanceof ExceptionLogEntry) { |
||
| 112 | $array[] = sprintf( |
||
| 113 | '<i>%s</i> %s:%d : %s', |
||
| 114 | htmlspecialchars($context->getExceptionClass()), |
||
| 115 | htmlspecialchars($context->getFile()), |
||
| 116 | $context->getLine(), |
||
| 117 | htmlspecialchars($context->getMessage()) |
||
| 118 | ); |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($context instanceof DatabaseUpdatedLogEntry) { |
||
| 122 | $array[] = sprintf( |
||
| 123 | '<i>%s</i> %s <i class="fas fa-long-arrow-alt-right"></i> %s', |
||
| 124 | $this->translator->trans($context->isSuccessful() ? 'log.database_updated.success' : 'log.database_updated.failure'), |
||
| 125 | $context->getOldVersion(), |
||
| 126 | $context->getNewVersion() |
||
| 127 | ); |
||
| 128 | } |
||
| 129 | |||
| 130 | if ($context instanceof LogWithEventUndoInterface) { |
||
| 131 | if ($context->isUndoEvent()) { |
||
| 132 | if ($context->getUndoMode() === 'undo') { |
||
| 133 | $array['log.undo_mode.undo'] = (string) $context->getUndoEventID(); |
||
| 134 | } elseif ($context->getUndoMode() === 'revert') { |
||
| 135 | $array['log.undo_mode.revert'] = (string) $context->getUndoEventID(); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | if ($context instanceof LogWithCommentInterface && $context->hasComment()) { |
||
| 141 | $array[] = htmlspecialchars($context->getComment()); |
||
| 142 | } |
||
| 143 | |||
| 144 | if ($context instanceof ElementCreatedLogEntry && $context->hasCreationInstockValue()) { |
||
| 145 | $array['log.element_created.original_instock'] = (string) $context->getCreationInstockValue(); |
||
| 146 | } |
||
| 147 | |||
| 148 | if ($context instanceof ElementDeletedLogEntry) { |
||
| 149 | if ($context->getOldName() !== null) { |
||
| 150 | $array['log.element_deleted.old_name'] = htmlspecialchars($context->getOldName()); |
||
| 151 | } else { |
||
| 152 | $array['log.element_deleted.old_name'] = $this->translator->trans('log.element_deleted.old_name.unknown'); |
||
| 153 | } |
||
| 154 | } |
||
| 155 | |||
| 156 | if ($context instanceof ElementEditedLogEntry && $context->hasChangedFieldsInfo()) { |
||
| 157 | $array['log.element_edited.changed_fields'] = htmlspecialchars(implode(', ', $context->getChangedFields())); |
||
| 158 | } |
||
| 159 | |||
| 160 | if ($context instanceof InstockChangedLogEntry) { |
||
| 161 | $array[] = $this->translator->trans($context->isWithdrawal() ? 'log.instock_changed.withdrawal' : 'log.instock_changed.added'); |
||
| 162 | $array[] = sprintf( |
||
| 163 | '%s <i class="fas fa-long-arrow-alt-right"></i> %s (%s)', |
||
| 164 | $context->getOldInstock(), |
||
| 165 | $context->getNewInstock(), |
||
| 166 | (! $context->isWithdrawal() ? '+' : '-').$context->getDifference(true) |
||
| 167 | ); |
||
| 168 | $array['log.instock_changed.comment'] = htmlspecialchars($context->getComment()); |
||
| 169 | } |
||
| 170 | |||
| 171 | if ($context instanceof CollectionElementDeleted) { |
||
| 172 | $array['log.collection_deleted.deleted'] = sprintf( |
||
| 173 | '%s: %s (%s)', |
||
| 174 | $this->elementTypeNameGenerator->getLocalizedTypeLabel($context->getDeletedElementClass()), |
||
| 175 | $context->getOldName() ?? $context->getDeletedElementID(), |
||
| 176 | $context->getCollectionName() |
||
| 177 | ); |
||
| 178 | } |
||
| 179 | |||
| 180 | if ($context instanceof UserNotAllowedLogEntry) { |
||
| 181 | $array[] = htmlspecialchars($context->getMessage()); |
||
| 182 | } |
||
| 183 | |||
| 184 | return $array; |
||
| 185 | } |
||
| 212 |