| Conditions | 3 |
| Paths | 3 |
| Total Lines | 59 |
| 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 |
||
| 32 | public function renderDataTypes(&$params, &$tsObj) |
||
| 33 | { |
||
| 34 | |||
| 35 | $configuration = ConfigurationUtility::getInstance()->getConfiguration(); |
||
| 36 | $selectedDataTypes = GeneralUtility::trimExplode(',', $configuration['data_types']); |
||
| 37 | $options = ''; |
||
| 38 | foreach ($this->getDataTypes() as $dataType) { |
||
| 39 | $checked = ''; |
||
| 40 | |||
| 41 | if (in_array($dataType, $selectedDataTypes)) { |
||
| 42 | $checked = 'checked="checked"'; |
||
| 43 | } |
||
| 44 | $options .= sprintf( |
||
| 45 | '<li><label><input type="checkbox" class="fieldDataType" value="%s" %s /> %s</label></li>', |
||
| 46 | $dataType, |
||
| 47 | $checked, |
||
| 48 | $dataType |
||
| 49 | ); |
||
| 50 | } |
||
| 51 | |||
| 52 | $menu = sprintf('<ul class="list-unstyled" style="margin-top: 10px;">%s</ul>', $options); |
||
| 53 | |||
| 54 | // Assemble final output. |
||
| 55 | $output = <<<EOF |
||
| 56 | <div class="form-group form-group-dashed> |
||
| 57 | <div class="form-control-wrap"> |
||
| 58 | |||
| 59 | <div class="typo3-tstemplate-ceditor-row" id="userTS-dataTypes"> |
||
| 60 | <script type="text/javascript"> |
||
| 61 | (function($) { |
||
| 62 | $(function() { |
||
| 63 | |||
| 64 | // Handler which will concatenate selected data types. |
||
| 65 | $('.fieldDataType').change(function() { |
||
| 66 | |||
| 67 | var dataTypes = $('#fieldDataTypes').val(); |
||
| 68 | var currentValue = $(this).val(); |
||
| 69 | |||
| 70 | // In any case remove item |
||
| 71 | var expression = new RegExp(', *' + currentValue, 'i'); |
||
| 72 | dataTypes = dataTypes.replace(expression, ''); |
||
| 73 | $('#fieldDataTypes').val(dataTypes); |
||
| 74 | |||
| 75 | // Append new data type at the end if checked. |
||
| 76 | if ($(this).is(':checked')) { |
||
| 77 | $('#fieldDataTypes').val(dataTypes + ', ' + currentValue); |
||
| 78 | } |
||
| 79 | }); |
||
| 80 | }); |
||
| 81 | })(jQuery); |
||
| 82 | </script> |
||
| 83 | <input type="text" class="form-control" id="fieldDataTypes" name="tx_extensionmanager_tools_extensionmanagerextensionmanager[config][data_types][value]" value="{$configuration['data_types']}" /> |
||
| 84 | </div> |
||
| 85 | $menu |
||
| 86 | </div> |
||
| 87 | EOF; |
||
| 88 | |||
| 89 | return $output; |
||
| 90 | } |
||
| 91 | |||
| 116 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.