| Conditions | 9 |
| Paths | 13 |
| Total Lines | 60 |
| 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 |
||
| 21 | public function renderDecorated($name) |
||
| 22 | { |
||
| 23 | if (!$this->has($name)) { |
||
| 24 | return "form element '$name' not found<br />"; |
||
| 25 | } |
||
| 26 | |||
| 27 | $this->helper = $this->getDI()->get('helper'); |
||
|
|
|||
| 28 | |||
| 29 | $element = $this->get($name); |
||
| 30 | $messages = $this->getMessagesFor($element->getName()); |
||
| 31 | |||
| 32 | $html = ''; |
||
| 33 | if (count($messages)) { |
||
| 34 | $html .= '<div class="ui error message">'; |
||
| 35 | $html .= '<div class="header">' . $this->helper->translate('Ошибка валидации формы') . '</div>'; |
||
| 36 | foreach ($messages as $message) { |
||
| 37 | $html .= '<p>' . $message . '</p>'; |
||
| 38 | } |
||
| 39 | $html .= '</div>'; |
||
| 40 | } |
||
| 41 | |||
| 42 | if ($element instanceof Hidden) { |
||
| 43 | echo $element; |
||
| 44 | } else { |
||
| 45 | switch (true) { |
||
| 46 | case $element instanceof Check: |
||
| 47 | $html .= '<div class="field checkbox">'; |
||
| 48 | $html .= '<div class="ui toggle checkbox">'; |
||
| 49 | $html .= $element; |
||
| 50 | if ($element->getLabel()) { |
||
| 51 | $html .= '<label>'; |
||
| 52 | $html .= $element->getLabel(); |
||
| 53 | $html .= '</label>'; |
||
| 54 | } |
||
| 55 | $html .= '</div>'; |
||
| 56 | $html .= '</div>'; |
||
| 57 | break; |
||
| 58 | |||
| 59 | case $element instanceof Image: |
||
| 60 | $html = $this->renderImage($element); |
||
| 61 | break; |
||
| 62 | |||
| 63 | case $element instanceof File: |
||
| 64 | $html .= '<div class="inline field">'; |
||
| 65 | $html .= $this->makeLabel($element); |
||
| 66 | $html .= $element; |
||
| 67 | $html .= '</div>'; |
||
| 68 | break; |
||
| 69 | |||
| 70 | default: |
||
| 71 | $html .= '<div class="field">'; |
||
| 72 | $html .= $this->makeLabel($element); |
||
| 73 | $html .= $element; |
||
| 74 | $html .= '</div>'; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | return $html; |
||
| 79 | |||
| 80 | } |
||
| 81 | |||
| 145 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.