Conditions | 13 |
Paths | 14 |
Total Lines | 34 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 1 | 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 |
||
124 | public function afterElementSave(ElementInterface $element, bool $isNew): void |
||
125 | { |
||
126 | if (!self::$allowShortLinkUpdates || $element->getIsDraft() || !$element->getSite()->hasUrls) { |
||
127 | return; |
||
128 | } |
||
129 | |||
130 | $value = $element->getFieldValue($this->handle); |
||
131 | // Return for propagating elements |
||
132 | if ($this->redirectSrcMatch === 'pathonly') { |
||
133 | $parentElement = ElementHelper::rootElement($element); |
||
134 | if ($this->translationMethod === Field::TRANSLATION_METHOD_NONE && ($element->propagating || $parentElement->propagating)) { |
||
135 | return; |
||
136 | } |
||
137 | } elseif (!empty($value) && !StringHelper::startsWith($value, 'http')) { |
||
138 | $value = UrlHelper::siteUrl($value, null, null, $element->siteId); |
||
139 | } |
||
140 | |||
141 | $parentElement = ElementHelper::rootElement($element); |
||
142 | RetourPlugin::$plugin->redirects->removeElementRedirect($parentElement, false); |
||
143 | |||
144 | if (!empty($value)) { |
||
145 | $redirectSrcMatch = $this->redirectSrcMatch; |
||
146 | |||
147 | if ($this->translationMethod !== Field::TRANSLATION_METHOD_NONE) { |
||
148 | if (!UrlHelper::isAbsoluteUrl($value)) { |
||
149 | $value = UrlHelper::siteUrl($value, null, null, $parentElement->siteId); |
||
150 | $redirectSrcMatch = 'fullurl'; |
||
151 | } |
||
152 | } |
||
153 | |||
154 | RetourPlugin::$plugin->redirects->enableElementRedirect($parentElement, $value, $redirectSrcMatch, $this->redirectHttpCode); |
||
155 | } |
||
156 | |||
157 | parent::afterElementSave($element, $isNew); |
||
158 | } |
||
173 |