| Conditions | 2 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 55 | public function getCMSFields() |
||
| 56 | { |
||
| 57 | $this->beforeUpdateCMSFields(function (FieldList $fields) { |
||
| 58 | $originalLabel = ReadonlyField::create('OriginalLabel') |
||
| 59 | ->setDescription(_t( |
||
| 60 | __CLASS__ . '.ORIGINAL_LABEL_DESCRIPTION', |
||
| 61 | 'Title of this field as provided by the CKAN resource' |
||
| 62 | )); |
||
| 63 | $fields->replaceField('OriginalLabel', $originalLabel); |
||
| 64 | |||
| 65 | $readableLabel = $fields->dataFieldByName('ReadableLabel'); |
||
| 66 | $readableLabel->setAttribute('placeholder', $this->OriginalLabel); |
||
| 67 | |||
| 68 | $fields->removeByName('Type'); |
||
| 69 | |||
| 70 | $positionField = NumericField::create('Position') |
||
| 71 | ->setTitle(_t(__CLASS__ . '.ORDER_LABEL', 'Presented order')) |
||
| 72 | ->setDescription(_t( |
||
| 73 | __CLASS__ . '.ORDER_DENOMINATOR', |
||
| 74 | 'of {count} columns', |
||
| 75 | ['count' => static::get()->filter('ResourceID', $this->ResourceID)->count()] |
||
| 76 | )) |
||
| 77 | ->addExtraClass('ckan-resource__order'); |
||
| 78 | $fields->replaceField('Position', $positionField); |
||
| 79 | |||
| 80 | $summary = $fields->dataFieldByName('ShowInResultsView') |
||
| 81 | ->addExtraClass('visibility-options__option'); |
||
| 82 | $detail = $fields->dataFieldByName('ShowInDetailView') |
||
| 83 | ->addExtraClass('visibility-options__option'); |
||
| 84 | $duplicates = $fields->dataFieldByName('RemoveDuplicates') |
||
| 85 | ->setTitle( |
||
| 86 | _t(__CLASS__ . '.REMOVE_DUPLICATES_LABEL', 'Only show one value if duplicates exist') |
||
| 87 | ) |
||
| 88 | ->addExtraClass('visibility-options__option'); |
||
| 89 | |||
| 90 | // Present the visibility fields in a group |
||
| 91 | $fields->removeByName(['ShowInResultsView', 'ShowInDetailView', 'RemoveDuplicates']); |
||
| 92 | $visibilityOptions = FieldGroup::create('Visibility', [$summary, $detail, $duplicates]) |
||
| 93 | ->addExtraClass('visibility-options'); |
||
| 94 | $fields->insertBefore($visibilityOptions, 'Position'); |
||
| 95 | |||
| 96 | $fields->removeByName('ResourceID'); |
||
| 97 | |||
| 98 | $fields->replaceField( |
||
| 99 | 'DisplayConditions', |
||
| 100 | ResultConditionsField::create( |
||
| 101 | 'DisplayConditions', |
||
| 102 | _t(__CLASS__ . '.RESULT_CONDITIONS', 'Result conditions') |
||
| 103 | ) |
||
| 104 | ); |
||
| 105 | |||
| 106 | // See https://github.com/silverstripe/silverstripe-framework/issues/8696 |
||
| 107 | foreach ([$summary, $detail, $readableLabel, $originalLabel] as $field) { |
||
| 108 | $field->setTitle(ucfirst(strtolower($field->Title()))); |
||
| 109 | } |
||
| 110 | }); |
||
| 111 | return parent::getCMSFields(); |
||
| 112 | } |
||
| 124 |