| Conditions | 27 |
| Paths | 111 |
| Total Lines | 68 |
| Code Lines | 45 |
| 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 |
||
| 81 | public function render($value, $context): string |
||
| 82 | { |
||
| 83 | if ($context instanceof UserNotAllowedLogEntry && $this->options['showAccessDeniedPath']) { |
||
| 84 | return htmlspecialchars($context->getPath()); |
||
| 85 | } |
||
| 86 | |||
| 87 | /** @var AbstractLogEntry $context */ |
||
| 88 | $target = $this->entryRepository->getTargetElement($context); |
||
| 89 | |||
| 90 | $tmp = ''; |
||
| 91 | |||
| 92 | //The element is existing |
||
| 93 | if ($target instanceof NamedElementInterface && !empty($target->getName())) { |
||
| 94 | try { |
||
| 95 | $tmp = sprintf( |
||
| 96 | '<a href="%s">%s</a>', |
||
| 97 | $this->entityURLGenerator->infoURL($target), |
||
|
|
|||
| 98 | $this->elementTypeNameGenerator->getTypeNameCombination($target, true) |
||
| 99 | ); |
||
| 100 | } catch (EntityNotSupportedException $exception) { |
||
| 101 | $tmp = $this->elementTypeNameGenerator->getTypeNameCombination($target, true); |
||
| 102 | } |
||
| 103 | } elseif ($target instanceof AbstractDBElement) { //Target does not have a name |
||
| 104 | $tmp = sprintf( |
||
| 105 | '<i>%s</i>: %s', |
||
| 106 | $this->elementTypeNameGenerator->getLocalizedTypeLabel($target), |
||
| 107 | $target->getID() |
||
| 108 | ); |
||
| 109 | } elseif (null === $target && $context->hasTarget()) { //Element was deleted |
||
| 110 | $tmp = sprintf( |
||
| 111 | '<i>%s</i>: %s [%s]', |
||
| 112 | $this->elementTypeNameGenerator->getLocalizedTypeLabel($context->getTargetClass()), |
||
| 113 | $context->getTargetID(), |
||
| 114 | $this->translator->trans('log.target_deleted') |
||
| 115 | ); |
||
| 116 | } |
||
| 117 | |||
| 118 | //Add a hint to the associated element if possible |
||
| 119 | if (null !== $target && $this->options['show_associated']) { |
||
| 120 | if ($target instanceof Attachment && null !== $target->getElement()) { |
||
| 121 | $on = $target->getElement(); |
||
| 122 | } elseif ($target instanceof AbstractParameter && null !== $target->getElement()) { |
||
| 123 | $on = $target->getElement(); |
||
| 124 | } elseif ($target instanceof PartLot && null !== $target->getPart()) { |
||
| 125 | $on = $target->getPart(); |
||
| 126 | } elseif ($target instanceof Orderdetail && null !== $target->getPart()) { |
||
| 127 | $on = $target->getPart(); |
||
| 128 | } elseif ($target instanceof Pricedetail && null !== $target->getOrderdetail() && null !== $target->getOrderdetail()->getPart()) { |
||
| 129 | $on = $target->getOrderdetail()->getPart(); |
||
| 130 | } elseif ($target instanceof ProjectBOMEntry && null !== $target->getProject()) { |
||
| 131 | $on = $target->getProject(); |
||
| 132 | } |
||
| 133 | |||
| 134 | if (isset($on) && is_object($on)) { |
||
| 135 | try { |
||
| 136 | $tmp .= sprintf( |
||
| 137 | ' (<a href="%s">%s</a>)', |
||
| 138 | $this->entityURLGenerator->infoURL($on), |
||
| 139 | $this->elementTypeNameGenerator->getTypeNameCombination($on, true) |
||
| 140 | ); |
||
| 141 | } catch (EntityNotSupportedException $exception) { |
||
| 142 | $tmp .= ' ('.$this->elementTypeNameGenerator->getTypeNameCombination($target, true).')'; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | //Log is not associated with an element |
||
| 148 | return $tmp; |
||
| 149 | } |
||
| 151 |