| Conditions | 2 |
| Paths | 2 |
| Total Lines | 66 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 57 | public function getEditForm($id = null, $fields = null) |
||
| 58 | { |
||
| 59 | $form = parent::getEditForm($id, $fields); |
||
| 60 | $fields = $form->Fields(); |
||
| 61 | |||
| 62 | // if ($form instanceof HTTPResponse) { |
||
| 63 | // return $form; |
||
| 64 | // } |
||
| 65 | // $fields->removeByName('LastVisited'); |
||
| 66 | $fields->push( |
||
| 67 | (new TextField('Keywords', 'Keyword(s)', $this->keywords ?? '')) |
||
| 68 | ->setAttribute('placeholder', 'e.g. agreement') |
||
| 69 | ); |
||
| 70 | $fields->push( |
||
| 71 | (new HiddenField('IsSubmitHiddenField', 'IsSubmitHiddenField', 1)) |
||
| 72 | ); |
||
| 73 | |||
| 74 | $options = QuickSearchBaseClass::get_list_of_quick_searches(); |
||
| 75 | $fields->push( |
||
| 76 | OptionsetField::create( |
||
| 77 | 'QuickSearchType', |
||
| 78 | 'Quick Search', |
||
| 79 | $options |
||
| 80 | )->setValue($this->bestSearchType()) |
||
| 81 | ); |
||
| 82 | |||
| 83 | $fields->push( |
||
| 84 | (new CheckboxField('SearchWholePhrase', 'Search exact phrase', $this->searchWholePhrase)) |
||
| 85 | ->setDescription('If ticked, any item will be included that includes the whole phrase (e.g. New Zealand, rather than New OR Zealand)') |
||
| 86 | ); |
||
| 87 | $fields->push( |
||
| 88 | ToggleCompositeField::create( |
||
| 89 | 'ReplaceToggle', |
||
| 90 | _t(__CLASS__ . '.ReplaceToggle', 'Replace with ... (optional - make a backup first!)'), |
||
| 91 | [ |
||
| 92 | (new CheckboxField('ApplyReplace', 'Run replace (please make sure to make a backup first!)', $this->applyReplace)) |
||
| 93 | ->setDescription('Check this to replace the searched value set above with its replacement value. Note that searches ignore uppercase / lowercase, but replace actions will only search and replace values with the same upper / lowercase.'), |
||
| 94 | (new TextField('ReplaceWith', 'Replace (optional - careful!)', $this->replace ?? '')) |
||
| 95 | ->setAttribute('placeholder', 'e.g. contract - make sure to also tick checkbox below'), |
||
| 96 | ] |
||
| 97 | )->setHeadingLevel(4) |
||
| 98 | ); |
||
| 99 | |||
| 100 | |||
| 101 | if (!$this->getRequest()->requestVar('Keywords')) { |
||
| 102 | $resultsTitle = 'Recently Edited'; |
||
| 103 | $this->listHTML = $this->renderWith(self::class . '_Results'); |
||
| 104 | } else { |
||
| 105 | $resultsTitle = 'Search Results'; |
||
| 106 | } |
||
| 107 | |||
| 108 | $form->setFormMethod('get', false); |
||
| 109 | |||
| 110 | $fields->push( |
||
| 111 | (new HTMLReadonlyField('List', $resultsTitle, DBField::create_field('HTMLText', $this->listHTML))) |
||
| 112 | ); |
||
| 113 | $form->Actions()->push( |
||
| 114 | FormAction::create('search', 'Find') |
||
| 115 | ->addExtraClass('btn-primary') |
||
| 116 | ->setUseButtonTag(true) |
||
| 117 | ); |
||
| 118 | $form->addExtraClass('root-form cms-edit-form center fill-height'); |
||
| 119 | // $form->disableSecurityToken(); |
||
| 120 | // $form->setFormMethod('get'); |
||
| 121 | |||
| 122 | return $form; |
||
| 123 | } |
||
| 234 |