| Conditions | 4 |
| Paths | 8 |
| Total Lines | 52 |
| 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 |
||
| 17 | public function __construct($controller, $name, $fields = null, $actions = null, $validator = null) { |
||
| 18 | if(!$fields) { |
||
| 19 | $helpHtml = _t( |
||
| 20 | 'GroupImportForm.Help1', |
||
| 21 | '<p>Import one or more groups in <em>CSV</em> format (comma-separated values).' |
||
| 22 | . ' <small><a href="#" class="toggle-advanced">Show advanced usage</a></small></p>' |
||
| 23 | ); |
||
| 24 | $helpHtml .= _t( |
||
| 25 | 'GroupImportForm.Help2', |
||
| 26 | '<div class="advanced">' |
||
| 27 | . '<h4>Advanced usage</h4>' |
||
| 28 | . '<ul>' |
||
| 29 | . '<li>Allowed columns: <em>%s</em></li>' |
||
| 30 | . '<li>Existing groups are matched by their unique <em>Code</em> value, and updated with any new values from the ' |
||
| 31 | . 'imported file</li>' |
||
| 32 | . '<li>Group hierarchies can be created by using a <em>ParentCode</em> column.</li>' |
||
| 33 | . '<li>Permission codes can be assigned by the <em>PermissionCode</em> column. Existing permission codes are not ' |
||
| 34 | . 'cleared.</li>' |
||
| 35 | . '</ul>' |
||
| 36 | . '</div>' |
||
| 37 | ); |
||
| 38 | |||
| 39 | $importer = new GroupCsvBulkLoader(); |
||
| 40 | $importSpec = $importer->getImportSpec(); |
||
| 41 | $helpHtml = sprintf($helpHtml, implode(', ', array_keys($importSpec['fields']))); |
||
| 42 | |||
| 43 | $fields = new FieldList( |
||
| 44 | new LiteralField('Help', $helpHtml), |
||
| 45 | $fileField = new FileField( |
||
| 46 | 'CsvFile', |
||
| 47 | _t( |
||
| 48 | 'SecurityAdmin_MemberImportForm.FileFieldLabel', |
||
| 49 | 'CSV File <small>(Allowed extensions: *.csv)</small>' |
||
| 50 | ) |
||
| 51 | ) |
||
| 52 | ); |
||
| 53 | $fileField->getValidator()->setAllowedExtensions(array('csv')); |
||
| 54 | } |
||
| 55 | |||
| 56 | if(!$actions) { |
||
| 57 | $action = new FormAction('doImport', _t('SecurityAdmin_MemberImportForm.BtnImport', 'Import from CSV')); |
||
| 58 | $action->addExtraClass('ss-ui-button'); |
||
| 59 | $actions = new FieldList($action); |
||
| 60 | } |
||
| 61 | |||
| 62 | if(!$validator) $validator = new RequiredFields('CsvFile'); |
||
| 63 | |||
| 64 | parent::__construct($controller, $name, $fields, $actions, $validator); |
||
| 65 | |||
| 66 | $this->addExtraClass('cms'); |
||
| 67 | $this->addExtraClass('import-form'); |
||
| 68 | } |
||
| 69 | |||
| 98 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.