| Conditions | 10 |
| Paths | 48 |
| Total Lines | 75 |
| Code Lines | 33 |
| Lines | 75 |
| Ratio | 100 % |
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 |
||
| 102 | View Code Duplication | public function getTemplate($layout) |
|
| 103 | { |
||
| 104 | $size = $this->getColumnsSize(); |
||
|
|
|||
| 105 | $id = $this->getAttribute('id'); |
||
| 106 | $value = $this->getValue(); |
||
| 107 | |||
| 108 | if (empty($size)) { |
||
| 109 | $sizeTemp = $this->getInputSize(); |
||
| 110 | if (empty($size)) { |
||
| 111 | $sizeTemp = 8; |
||
| 112 | } |
||
| 113 | $size = array(2, $sizeTemp, 2); |
||
| 114 | } else { |
||
| 115 | if (is_array($size)) { |
||
| 116 | if (count($size) != 3) { |
||
| 117 | $sizeTemp = $this->getInputSize(); |
||
| 118 | if (empty($size)) { |
||
| 119 | $sizeTemp = 8; |
||
| 120 | } |
||
| 121 | $size = array(2, $sizeTemp, 2); |
||
| 122 | } |
||
| 123 | // else just keep the $size array as received |
||
| 124 | } else { |
||
| 125 | $size = array(2, intval($size), 2); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | if (!empty($value)) { |
||
| 130 | $value = api_format_date($value, DATE_TIME_FORMAT_LONG_24H); |
||
| 131 | } |
||
| 132 | |||
| 133 | switch ($layout) { |
||
| 134 | case FormValidator::LAYOUT_INLINE: |
||
| 135 | return ' |
||
| 136 | <div class="form-group {error_class}"> |
||
| 137 | <label {label-for} > |
||
| 138 | <!-- BEGIN required --><span class="form_required">*</span><!-- END required --> |
||
| 139 | {label} |
||
| 140 | </label> |
||
| 141 | |||
| 142 | {element} |
||
| 143 | </div>'; |
||
| 144 | break; |
||
| 145 | case FormValidator::LAYOUT_HORIZONTAL: |
||
| 146 | return ' |
||
| 147 | <div class="form-group {error_class}"> |
||
| 148 | <label {label-for} class="col-sm-'.$size[0].' control-label" > |
||
| 149 | <!-- BEGIN required --><span class="form_required">*</span><!-- END required --> |
||
| 150 | {label} |
||
| 151 | </label> |
||
| 152 | <div class="col-sm-'.$size[1].'"> |
||
| 153 | {icon} |
||
| 154 | |||
| 155 | {element} |
||
| 156 | |||
| 157 | <!-- BEGIN label_2 --> |
||
| 158 | <p class="help-block">{label_2}</p> |
||
| 159 | <!-- END label_2 --> |
||
| 160 | |||
| 161 | <!-- BEGIN error --> |
||
| 162 | <span class="help-inline">{error}</span> |
||
| 163 | <!-- END error --> |
||
| 164 | </div> |
||
| 165 | <div class="col-sm-'.$size[2].'"> |
||
| 166 | <!-- BEGIN label_3 --> |
||
| 167 | {label_3} |
||
| 168 | <!-- END label_3 --> |
||
| 169 | </div> |
||
| 170 | </div>'; |
||
| 171 | break; |
||
| 172 | case FormValidator::LAYOUT_BOX_NO_LABEL: |
||
| 173 | return '{element}'; |
||
| 174 | break; |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 179 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.