| Conditions | 23 |
| Paths | 1 |
| Total Lines | 202 |
| Code Lines | 132 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 110 | public function configure(DataTable $dataTable, array $options): void |
||
| 111 | { |
||
| 112 | $resolver = new OptionsResolver(); |
||
| 113 | $this->configureOptions($resolver); |
||
| 114 | $options = $resolver->resolve($options); |
||
| 115 | |||
| 116 | //This special $$rowClass column is used to set the row class depending on the log level. The class gets set by the frontend controller |
||
| 117 | $dataTable->add('dont_matter', RowClassColumn::class, [ |
||
| 118 | 'render' => static function ($value, AbstractLogEntry $context) { |
||
| 119 | switch ($context->getLevel()) { |
||
| 120 | case AbstractLogEntry::LEVEL_EMERGENCY: |
||
| 121 | case AbstractLogEntry::LEVEL_ALERT: |
||
| 122 | case AbstractLogEntry::LEVEL_CRITICAL: |
||
| 123 | case AbstractLogEntry::LEVEL_ERROR: |
||
| 124 | return 'table-danger'; |
||
| 125 | case AbstractLogEntry::LEVEL_WARNING: |
||
| 126 | return 'table-warning'; |
||
| 127 | case AbstractLogEntry::LEVEL_NOTICE: |
||
| 128 | return 'table-info'; |
||
| 129 | default: |
||
| 130 | return ''; |
||
| 131 | } |
||
| 132 | }, |
||
| 133 | ]); |
||
| 134 | |||
| 135 | $dataTable->add('symbol', TextColumn::class, [ |
||
| 136 | 'label' => '', |
||
| 137 | 'className' => 'no-colvis', |
||
| 138 | 'render' => static function ($value, AbstractLogEntry $context) { |
||
| 139 | switch ($context->getLevelString()) { |
||
| 140 | case LogLevel::DEBUG: |
||
| 141 | $symbol = 'fa-bug'; |
||
| 142 | |||
| 143 | break; |
||
| 144 | case LogLevel::INFO: |
||
| 145 | $symbol = 'fa-info'; |
||
| 146 | |||
| 147 | break; |
||
| 148 | case LogLevel::NOTICE: |
||
| 149 | $symbol = 'fa-flag'; |
||
| 150 | |||
| 151 | break; |
||
| 152 | case LogLevel::WARNING: |
||
| 153 | $symbol = 'fa-exclamation-circle'; |
||
| 154 | |||
| 155 | break; |
||
| 156 | case LogLevel::ERROR: |
||
| 157 | $symbol = 'fa-exclamation-triangle'; |
||
| 158 | |||
| 159 | break; |
||
| 160 | case LogLevel::CRITICAL: |
||
| 161 | $symbol = 'fa-bolt'; |
||
| 162 | |||
| 163 | break; |
||
| 164 | case LogLevel::ALERT: |
||
| 165 | $symbol = 'fa-radiation'; |
||
| 166 | |||
| 167 | break; |
||
| 168 | case LogLevel::EMERGENCY: |
||
| 169 | $symbol = 'fa-skull-crossbones'; |
||
| 170 | |||
| 171 | break; |
||
| 172 | default: |
||
| 173 | $symbol = 'fa-question-circle'; |
||
| 174 | |||
| 175 | break; |
||
| 176 | } |
||
| 177 | |||
| 178 | return sprintf( |
||
| 179 | '<i class="fas fa-fw %s" title="%s"></i>', |
||
| 180 | $symbol, |
||
| 181 | $context->getLevelString() |
||
| 182 | ); |
||
| 183 | }, |
||
| 184 | ]); |
||
| 185 | |||
| 186 | $dataTable->add('id', TextColumn::class, [ |
||
| 187 | 'label' => 'log.id', |
||
| 188 | 'visible' => false, |
||
| 189 | ]); |
||
| 190 | |||
| 191 | $dataTable->add('timestamp', LocaleDateTimeColumn::class, [ |
||
| 192 | 'label' => 'log.timestamp', |
||
| 193 | 'timeFormat' => 'medium', |
||
| 194 | ]); |
||
| 195 | |||
| 196 | $dataTable->add('type', TextColumn::class, [ |
||
| 197 | 'label' => 'log.type', |
||
| 198 | 'propertyPath' => 'type', |
||
| 199 | 'render' => function (string $value, AbstractLogEntry $context) { |
||
| 200 | $text = $this->translator->trans('log.type.'.$value); |
||
| 201 | |||
| 202 | if ($context instanceof PartStockChangedLogEntry) { |
||
| 203 | $text .= sprintf( |
||
| 204 | ' (<i>%s</i>)', |
||
| 205 | $this->translator->trans('log.part_stock_changed.' . $context->getInstockChangeType()) |
||
| 206 | ); |
||
| 207 | } |
||
| 208 | |||
| 209 | return $text; |
||
| 210 | }, |
||
| 211 | ]); |
||
| 212 | |||
| 213 | $dataTable->add('level', TextColumn::class, [ |
||
| 214 | 'label' => 'log.level', |
||
| 215 | 'visible' => 'system_log' === $options['mode'], |
||
| 216 | 'propertyPath' => 'levelString', |
||
| 217 | 'render' => function (string $value, AbstractLogEntry $context) { |
||
|
|
|||
| 218 | return $this->translator->trans('log.level.'.$value); |
||
| 219 | }, |
||
| 220 | ]); |
||
| 221 | |||
| 222 | $dataTable->add('user', TextColumn::class, [ |
||
| 223 | 'label' => 'log.user', |
||
| 224 | 'render' => function ($value, AbstractLogEntry $context) { |
||
| 225 | $user = $context->getUser(); |
||
| 226 | |||
| 227 | //If user was deleted, show the info from the username field |
||
| 228 | if ($user === null) { |
||
| 229 | return sprintf( |
||
| 230 | '@%s [%s]', |
||
| 231 | htmlentities($context->getUsername()), |
||
| 232 | $this->translator->trans('log.target_deleted'), |
||
| 233 | ); |
||
| 234 | } |
||
| 235 | |||
| 236 | $img_url = $this->userAvatarHelper->getAvatarSmURL($user); |
||
| 237 | |||
| 238 | return sprintf( |
||
| 239 | '<img src="%s" data-thumbnail="%s" class="avatar-xs" data-controller="elements--hoverpic"> <a href="%s">%s</a>', |
||
| 240 | $img_url, |
||
| 241 | $this->userAvatarHelper->getAvatarMdURL($user), |
||
| 242 | $this->urlGenerator->generate('user_info', ['id' => $user->getID()]), |
||
| 243 | htmlentities($user->getFullName(true)) |
||
| 244 | ); |
||
| 245 | }, |
||
| 246 | ]); |
||
| 247 | |||
| 248 | $dataTable->add('target_type', TextColumn::class, [ |
||
| 249 | 'label' => 'log.target_type', |
||
| 250 | 'visible' => false, |
||
| 251 | 'render' => function ($value, AbstractLogEntry $context) { |
||
| 252 | $class = $context->getTargetClass(); |
||
| 253 | if (null !== $class) { |
||
| 254 | return $this->elementTypeNameGenerator->getLocalizedTypeLabel($class); |
||
| 255 | } |
||
| 256 | |||
| 257 | return ''; |
||
| 258 | }, |
||
| 259 | ]); |
||
| 260 | |||
| 261 | $dataTable->add('target', LogEntryTargetColumn::class, [ |
||
| 262 | 'label' => 'log.target', |
||
| 263 | 'show_associated' => 'element_history' !== $options['mode'], |
||
| 264 | ]); |
||
| 265 | |||
| 266 | $dataTable->add('extra', LogEntryExtraColumn::class, [ |
||
| 267 | 'label' => 'log.extra', |
||
| 268 | ]); |
||
| 269 | |||
| 270 | $dataTable->add('timeTravel', IconLinkColumn::class, [ |
||
| 271 | 'label' => '', |
||
| 272 | 'icon' => 'fas fa-fw fa-eye', |
||
| 273 | 'href' => function ($value, AbstractLogEntry $context) { |
||
| 274 | if ( |
||
| 275 | ($context instanceof TimeTravelInterface |
||
| 276 | && $context->hasOldDataInformations()) |
||
| 277 | || $context instanceof CollectionElementDeleted |
||
| 278 | ) { |
||
| 279 | try { |
||
| 280 | $target = $this->logRepo->getTargetElement($context); |
||
| 281 | if (null !== $target) { |
||
| 282 | return $this->entityURLGenerator->timeTravelURL($target, $context->getTimestamp()); |
||
| 283 | } |
||
| 284 | } catch (EntityNotSupportedException $exception) { |
||
| 285 | return null; |
||
| 286 | } |
||
| 287 | } |
||
| 288 | |||
| 289 | return null; |
||
| 290 | }, |
||
| 291 | 'disabled' => function ($value, AbstractLogEntry $context) { |
||
| 292 | return !$this->security->isGranted('show_history', $context->getTargetClass()); |
||
| 293 | }, |
||
| 294 | ]); |
||
| 295 | |||
| 296 | $dataTable->add('actionRevert', RevertLogColumn::class, [ |
||
| 297 | 'label' => '', |
||
| 298 | ]); |
||
| 299 | |||
| 300 | $dataTable->addOrderBy('timestamp', DataTable::SORT_DESCENDING); |
||
| 301 | |||
| 302 | $dataTable->createAdapter(ORMAdapter::class, [ |
||
| 303 | 'entity' => AbstractLogEntry::class, |
||
| 304 | 'query' => function (QueryBuilder $builder) use ($options): void { |
||
| 305 | $this->getQuery($builder, $options); |
||
| 306 | }, |
||
| 307 | 'criteria' => [ |
||
| 308 | function (QueryBuilder $builder) use ($options): void { |
||
| 309 | $this->buildCriteria($builder, $options); |
||
| 310 | }, |
||
| 311 | new SearchCriteriaProvider(), |
||
| 312 | ], |
||
| 357 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.