| Conditions | 27 |
| Paths | 26 |
| Total Lines | 100 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 215 | public function renderSummaryElement(ElementInterface $element) |
||
| 216 | { |
||
| 217 | if ($element instanceof Hidden || false === $element->getOption('render_summary')) { |
||
| 218 | return ''; |
||
| 219 | } |
||
| 220 | |||
| 221 | if ($element instanceof EmptySummaryAwareInterface && $element->isSummaryEmpty()) { |
||
| 222 | /* @var $element EmptySummaryAwareInterface|ElementInterface */ |
||
| 223 | $emptySummaryNotice = $this->getTranslator()->translate( |
||
| 224 | $element->getEmptySummaryNotice(), |
||
| 225 | $this->getTranslatorTextDomain() |
||
| 226 | ); |
||
| 227 | |||
| 228 | $markup = sprintf( |
||
| 229 | '<div id="%s-empty-alert" class="empty-summary-notice alert alert-info"><p>%s</p></div>', |
||
| 230 | $element->getAttribute('id'), |
||
| 231 | $emptySummaryNotice |
||
| 232 | ); |
||
| 233 | return $markup; |
||
| 234 | } |
||
| 235 | |||
| 236 | if ($element instanceof ViewPartialProviderInterface) { |
||
| 237 | $renderer = $this->getView(); /* @var $renderer \Zend\View\Renderer\PhpRenderer */ |
||
| 238 | $origPartial = $element->getViewPartial(); |
||
| 239 | $partial = "$origPartial.view"; |
||
| 240 | $partialParams = array( |
||
| 241 | 'element' => $element |
||
| 242 | ); |
||
| 243 | if (!$renderer->resolver($partial)) { |
||
| 244 | $partial = $origPartial; |
||
| 245 | $partialParams['renderSummary'] = true; |
||
| 246 | } |
||
| 247 | |||
| 248 | return $renderer->partial($partial, $partialParams); |
||
| 249 | } |
||
| 250 | |||
| 251 | $label = $this->getTranslator()->translate($element->getLabel()); |
||
| 252 | $markup = ''; |
||
| 253 | |||
| 254 | if ($element instanceof FieldsetInterface) { |
||
| 255 | if (!$element instanceof FormInterface && $label) { |
||
| 256 | $markup .= '<h4>' . $label . '</h4>'; |
||
| 257 | } |
||
| 258 | foreach ($element as $el) { |
||
| 259 | $markup .= $this->renderSummaryElement($el); |
||
| 260 | } |
||
| 261 | return $markup; |
||
| 262 | } |
||
| 263 | |||
| 264 | $elementValue = $element instanceof \Zend\Form\Element\Textarea |
||
| 265 | ? nl2br($element->getValue()) |
||
| 266 | : $element->getValue(); |
||
| 267 | |||
| 268 | if ('' != $elementValue && $element instanceof \Zend\Form\Element\Select) { |
||
| 269 | $generalOptGroupName = '__general__'; |
||
| 270 | $options = $element->getValueOptions(); |
||
| 271 | $translator = $this->getTranslator(); |
||
| 272 | if (true == $element->getAttribute('multiple')) { |
||
| 273 | |||
| 274 | $multiOptions = []; |
||
| 275 | foreach ($elementValue as $optionKey) { |
||
| 276 | if (isset($options[$optionKey])) { |
||
| 277 | $multiOptions[$generalOptGroupName][] = $translator->translate($options[$optionKey]); |
||
| 278 | continue; |
||
| 279 | } |
||
| 280 | |||
| 281 | foreach ($options as $optKey => $optVal) { |
||
| 282 | if (!is_array($optVal) || !array_key_exists($optionKey, $optVal['options'])) { continue; } |
||
| 283 | |||
| 284 | $optGroupLabel = isset($optVal['label']) ? $translator->translate($optVal['label']) : $optKey; |
||
| 285 | $multiOptions[$optGroupLabel][] = $translator->translate($optVal['options'][$optionKey]); |
||
| 286 | } |
||
| 287 | } |
||
| 288 | |||
| 289 | $elementValue = []; |
||
| 290 | $numberOfmultiOptions = count($multiOptions); |
||
| 291 | foreach ($multiOptions as $optGroupLabel => $vals) { |
||
| 292 | $elementValue[] = ($numberOfmultiOptions > 1 || $optGroupLabel !== $generalOptGroupName ? "<b>$optGroupLabel</b><br>" : '') . join(', ', $vals); |
||
| 293 | } |
||
| 294 | $elementValue = join('<br>', $elementValue) . '<br>'; |
||
| 295 | |||
| 296 | } else { |
||
| 297 | $elementValue = $translator->translate($options[$elementValue]); |
||
| 298 | } |
||
| 299 | } |
||
| 300 | |||
| 301 | if ('' != $elementValue && $element instanceOf \Zend\Form\Element\File) { |
||
| 302 | return ''; |
||
| 303 | } |
||
| 304 | |||
| 305 | $markup .= '<div class="row">'; |
||
| 306 | $col = 12; |
||
| 307 | if ($label) { |
||
| 308 | $markup .= '<div class="col-md-3 yk-label"><label>' . $label . '</label></div>'; |
||
| 309 | $col = 9; |
||
| 310 | } |
||
| 311 | $markup .= '<div class="col-md-' . $col . '">' . $elementValue . '</div>' |
||
| 312 | . '</div>'; |
||
| 313 | return $markup; |
||
| 314 | } |
||
| 315 | } |
||
| 316 |
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.