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