Conditions | 28 |
Paths | > 20000 |
Total Lines | 96 |
Code Lines | 61 |
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 |
||
106 | protected function getInternalFormat(AbstractLogEntry $context): array |
||
107 | { |
||
108 | $array = []; |
||
109 | if ($context instanceof UserLoginLogEntry || $context instanceof UserLogoutLogEntry || $context instanceof SecurityEventLogEntry) { |
||
110 | $array['log.user_login.ip'] = htmlspecialchars($context->getIPAddress()); |
||
111 | } |
||
112 | |||
113 | if ($context instanceof ExceptionLogEntry) { |
||
114 | $array[] = sprintf( |
||
115 | '<i>%s</i> %s:%d : %s', |
||
116 | htmlspecialchars($context->getExceptionClass()), |
||
117 | htmlspecialchars($context->getFile()), |
||
118 | $context->getLine(), |
||
119 | htmlspecialchars($context->getMessage()) |
||
120 | ); |
||
121 | } |
||
122 | |||
123 | if ($context instanceof DatabaseUpdatedLogEntry) { |
||
124 | $array[] = sprintf( |
||
125 | '<i>%s</i> %s <i class="fas fa-long-arrow-alt-right"></i> %s', |
||
126 | $this->translator->trans($context->isSuccessful() ? 'log.database_updated.success' : 'log.database_updated.failure'), |
||
127 | $context->getOldVersion(), |
||
128 | $context->getNewVersion() |
||
129 | ); |
||
130 | } |
||
131 | |||
132 | if (($context instanceof LogWithEventUndoInterface) && $context->isUndoEvent()) { |
||
133 | if ('undo' === $context->getUndoMode()) { |
||
134 | $array['log.undo_mode.undo'] = (string) $context->getUndoEventID(); |
||
135 | } elseif ('revert' === $context->getUndoMode()) { |
||
136 | $array['log.undo_mode.revert'] = (string) $context->getUndoEventID(); |
||
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 (null !== $context->getOldName()) { |
||
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'] = $this->getChangedFieldsTranslated($context); |
||
158 | } |
||
159 | |||
160 | if ($context instanceof LegacyInstockChangedLogEntry) { |
||
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() ?? (string) $context->getDeletedElementID(), |
||
176 | $context->getCollectionName() |
||
177 | ); |
||
178 | } |
||
179 | |||
180 | if ($context instanceof UserNotAllowedLogEntry) { |
||
181 | $array[] = htmlspecialchars($context->getMessage()); |
||
182 | } |
||
183 | |||
184 | if ($context instanceof PartStockChangedLogEntry) { |
||
185 | $array['log.part_stock_changed.change'] = sprintf("%s %s %s (%s)", |
||
186 | $context->getOldStock(), |
||
187 | '<i class="fa-solid fa-right-long"></i>', |
||
188 | $context->getNewStock(), |
||
189 | ($context->getNewStock() > $context->getOldStock() ? '+' : '-'). $context->getChangeAmount(), |
||
190 | ); |
||
191 | if (!empty($context->getComment())) { |
||
192 | $array['log.part_stock_changed.comment'] = htmlspecialchars($context->getComment()); |
||
193 | } |
||
194 | if ($context->getInstockChangeType() === PartStockChangedLogEntry::TYPE_MOVE) { |
||
195 | $array['log.part_stock_changed.move_target'] = |
||
196 | $this->elementTypeNameGenerator->getLocalizedTypeLabel(PartLot::class) |
||
197 | .' ' . $context->getMoveToTargetID(); |
||
198 | } |
||
199 | } |
||
200 | |||
201 | return $array; |
||
202 | } |
||
221 |