Conditions | 2 |
Paths | 2 |
Total Lines | 55 |
Code Lines | 32 |
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 |
||
50 | public function getEditForm($id = null, $fields = null) |
||
51 | { |
||
52 | $form = parent::getEditForm($id, $fields); |
||
53 | |||
54 | // if ($form instanceof HTTPResponse) { |
||
55 | // return $form; |
||
56 | // } |
||
57 | // $form->Fields()->removeByName('LastVisited'); |
||
58 | $form->Fields()->push( |
||
59 | (new TextField('Keywords', 'Keyword(s)', $this->keywords ?? '')) |
||
60 | ->setAttribute('placeholder', 'e.g. agreement') |
||
61 | ); |
||
62 | $form->Fields()->push( |
||
63 | (new CheckboxField('QuickSearch', 'Search Main Fields Only', $this->isQuickSearch)) |
||
64 | ->setDescription('This is faster but only searches a limited number of fields') |
||
65 | ); |
||
66 | $form->Fields()->push( |
||
67 | (new CheckboxField('SearchWholePhrase', 'Search exact phrase', $this->searchWholePhrase)) |
||
68 | ->setDescription('If ticked, any item will be included that includes the whole phrase (e.g. New Zealand, rather than New OR Zealand)') |
||
69 | ); |
||
70 | |||
71 | $form->Fields()->push( |
||
72 | (new TextField('ReplaceWith', 'Replace (optional - careful!)', $this->replace ?? '')) |
||
73 | ->setAttribute('placeholder', 'e.g. contract - make sure to also tick checkbox below') |
||
74 | ); |
||
75 | $form->Fields()->push( |
||
76 | (new CheckboxField('ApplyReplace', 'Run replace (please make sure to make a backup first!)', $this->applyReplace)) |
||
77 | ->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.') |
||
78 | ); |
||
79 | |||
80 | if (!$this->getRequest()->requestVar('Keywords')) { |
||
81 | $resultsTitle = 'Recently Edited'; |
||
82 | $this->listHTML = $this->renderWith(self::class . '_Results'); |
||
83 | } else { |
||
84 | $resultsTitle = 'Search Results'; |
||
85 | } |
||
86 | |||
87 | $form->setFormMethod('get', false); |
||
88 | |||
89 | $form->Fields()->push( |
||
90 | (new HTMLReadonlyField('List', $resultsTitle, DBField::create_field('HTMLText', $this->listHTML))) |
||
91 | ); |
||
92 | $form->Fields()->push( |
||
93 | (new LiteralField('Styling', $this->renderWith(self::class . '_Styling'))) |
||
94 | ); |
||
95 | $form->Actions()->push( |
||
96 | FormAction::create('search', 'Find') |
||
97 | ->addExtraClass('btn-primary') |
||
98 | ->setUseButtonTag(true) |
||
99 | ); |
||
100 | $form->addExtraClass('root-form cms-edit-form center fill-height'); |
||
101 | // $form->disableSecurityToken(); |
||
102 | // $form->setFormMethod('get'); |
||
103 | |||
104 | return $form; |
||
105 | } |
||
196 |