| Conditions | 25 |
| Paths | 26 |
| Total Lines | 98 |
| Code Lines | 62 |
| 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 |
||
| 193 | protected function renderSummaryElement(ElementInterface $element) |
||
| 194 | { |
||
| 195 | if ($element instanceof Hidden || false === $element->getOption('render_summary')) { |
||
| 196 | return ''; |
||
| 197 | } |
||
| 198 | |||
| 199 | if ($element instanceof ViewPartialProviderInterface) { |
||
| 200 | $renderer = $this->getView(); /* @var $renderer \Zend\View\Renderer\PhpRenderer */ |
||
| 201 | $origPartial = $element->getViewPartial(); |
||
| 202 | $partial = "$origPartial.view"; |
||
| 203 | $partialParams = array( |
||
| 204 | 'element' => $element |
||
| 205 | ); |
||
| 206 | if (!$renderer->resolver($partial)) { |
||
| 207 | $partial = $origPartial; |
||
| 208 | $partialParams['renderSummary'] = true; |
||
| 209 | } |
||
| 210 | |||
| 211 | return $renderer->partial($partial, $partialParams); |
||
| 212 | } |
||
| 213 | |||
| 214 | if ($element instanceof EmptySummaryAwareInterface && $element->isSummaryEmpty()) { |
||
| 215 | /* @var $element EmptySummaryAwareInterface|ElementInterface */ |
||
| 216 | $emptySummaryNotice = $this->getTranslator()->translate( |
||
| 217 | $element->getEmptySummaryNotice(), |
||
| 218 | $this->getTranslatorTextDomain() |
||
| 219 | ); |
||
| 220 | |||
| 221 | $markup = sprintf( |
||
| 222 | '<div id="%s-empty-alert" class="empty-summary-notice alert alert-info"><p>%s</p></div>', |
||
| 223 | $element->getAttribute('id'), |
||
| 224 | $emptySummaryNotice |
||
| 225 | ); |
||
| 226 | return $markup; |
||
| 227 | } |
||
| 228 | |||
| 229 | $label = $this->getTranslator()->translate($element->getLabel()); |
||
| 230 | $markup = ''; |
||
| 231 | |||
| 232 | if ($element instanceof FieldsetInterface) { |
||
| 233 | if (!$element instanceof FormInterface && $label) { |
||
| 234 | $markup .= '<h4>' . $label . '</h4>'; |
||
| 235 | } |
||
| 236 | foreach ($element as $el) { |
||
| 237 | $markup .= $this->renderSummaryElement($el); |
||
| 238 | } |
||
| 239 | return $markup; |
||
| 240 | } |
||
| 241 | |||
| 242 | $elementValue = $element instanceof \Zend\Form\Element\Textarea |
||
| 243 | ? nl2br($element->getValue()) |
||
| 244 | : $element->getValue(); |
||
| 245 | |||
| 246 | if ('' != $elementValue && $element instanceof \Zend\Form\Element\Select) { |
||
| 247 | $options = $element->getValueOptions(); |
||
| 248 | $translator = $this->getTranslator(); |
||
| 249 | if (true == $element->getAttribute('multiple')) { |
||
| 250 | |||
| 251 | $multiOptions = []; |
||
| 252 | foreach ($elementValue as $optionKey) { |
||
| 253 | if (isset($options[$optionKey])) { |
||
| 254 | $multiOptions['__general__'][] = $translator->translate($options[$optionKey]); |
||
| 255 | continue; |
||
| 256 | } |
||
| 257 | |||
| 258 | foreach ($options as $optKey => $optVal) { |
||
| 259 | if (!is_array($optVal) || !array_key_exists($optionKey, $optVal['options'])) { continue; } |
||
| 260 | |||
| 261 | $optGroupLabel = isset($optVal['label']) ? $translator->translate($optVal['label']) : $optKey; |
||
| 262 | $multiOptions[$optGroupLabel][] = $translator->translate($optVal['options'][$optionKey]); |
||
| 263 | } |
||
| 264 | } |
||
| 265 | |||
| 266 | $elementValue = []; |
||
| 267 | foreach ($multiOptions as $optGroupLabel => $vals) { |
||
| 268 | $elementValue[] = "<b>$optGroupLabel</b><br>" . join(', ', $vals); |
||
| 269 | } |
||
| 270 | $elementValue = join('<br>', $elementValue) . '<br>'; |
||
| 271 | |||
| 272 | } else { |
||
| 273 | $elementValue = $translator->translate($options[$elementValue]); |
||
| 274 | } |
||
| 275 | } |
||
| 276 | |||
| 277 | if ('' != $elementValue && $element instanceOf \Zend\Form\Element\File) { |
||
| 278 | return ''; |
||
| 279 | } |
||
| 280 | |||
| 281 | $markup .= '<div class="row">'; |
||
| 282 | $col = 12; |
||
| 283 | if ($label) { |
||
| 284 | $markup .= '<div class="col-md-3 yk-label"><label>' . $label . '</label></div>'; |
||
| 285 | $col = 9; |
||
| 286 | } |
||
| 287 | $markup .= '<div class="col-md-' . $col . '">' . $elementValue . '</div>' |
||
| 288 | . '</div>'; |
||
| 289 | return $markup; |
||
| 290 | } |
||
| 291 | } |
||
| 292 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.