| Conditions | 3 |
| Paths | 3 |
| Total Lines | 71 |
| Code Lines | 44 |
| 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 |
||
| 67 | public function getEditForm($id = null, $fields = null) |
||
| 68 | { |
||
| 69 | $form = parent::getEditForm($id, $fields); |
||
| 70 | $fields = $form->Fields(); |
||
| 71 | |||
| 72 | // if ($form instanceof HTTPResponse) { |
||
| 73 | // return $form; |
||
| 74 | // } |
||
| 75 | // $fields->removeByName('LastVisited'); |
||
| 76 | $fields->push( |
||
| 77 | (new TextField('Keywords', 'Keyword(s)', $this->keywords ?? '')) |
||
| 78 | ->setAttribute('placeholder', 'e.g. agreement') |
||
| 79 | ); |
||
| 80 | $fields->push( |
||
| 81 | (new HiddenField('IsSubmitHiddenField', 'IsSubmitHiddenField', 1)) |
||
| 82 | ); |
||
| 83 | |||
| 84 | $options = QuickSearchBaseClass::get_list_of_quick_searches(); |
||
| 85 | $fields->push( |
||
| 86 | OptionsetField::create( |
||
| 87 | 'QuickSearchType', |
||
| 88 | 'Quick Search', |
||
| 89 | $options |
||
| 90 | )->setValue($this->bestSearchType()) |
||
| 91 | ); |
||
| 92 | |||
| 93 | $fields->push( |
||
| 94 | (new CheckboxField('SearchWholePhrase', 'Search exact phrase', $this->searchWholePhrase)) |
||
| 95 | ->setDescription('If ticked, any item will be included that includes the whole phrase (e.g. New Zealand, rather than New OR Zealand)') |
||
| 96 | ); |
||
| 97 | $fields->push( |
||
| 98 | ToggleCompositeField::create( |
||
| 99 | 'ReplaceToggle', |
||
| 100 | _t(__CLASS__ . '.ReplaceToggle', 'Replace with ... (optional - make a backup first!)'), |
||
| 101 | [ |
||
| 102 | (new CheckboxField('ApplyReplace', 'Run replace (please make sure to make a backup first!)', $this->applyReplace)) |
||
| 103 | ->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.'), |
||
| 104 | (new TextField('ReplaceWith', 'Replace (optional - careful!)', $this->replace ?? '')) |
||
| 105 | ->setAttribute('placeholder', 'e.g. contract - make sure to also tick checkbox below'), |
||
| 106 | ] |
||
| 107 | )->setHeadingLevel(4) |
||
| 108 | ); |
||
| 109 | |||
| 110 | |||
| 111 | if (!$this->getRequest()->requestVar('Keywords')) { |
||
| 112 | $lastResults = $this->lastSearchResults(); |
||
|
|
|||
| 113 | if($lastResults) { |
||
| 114 | $resultsTitle = 'Last Results'; |
||
| 115 | } else { |
||
| 116 | $resultsTitle = 'Last Edited'; |
||
| 117 | } |
||
| 118 | $this->listHTML = $this->renderWith(self::class . '_Results'); |
||
| 119 | } else { |
||
| 120 | $resultsTitle = 'Search Results'; |
||
| 121 | } |
||
| 122 | |||
| 123 | $form->setFormMethod('get', false); |
||
| 124 | |||
| 125 | $fields->push( |
||
| 126 | (new HTMLReadonlyField('List', $resultsTitle, DBField::create_field('HTMLText', $this->listHTML))) |
||
| 127 | ); |
||
| 128 | $form->Actions()->push( |
||
| 129 | FormAction::create('search', 'Find') |
||
| 130 | ->addExtraClass('btn-primary') |
||
| 131 | ->setUseButtonTag(true) |
||
| 132 | ); |
||
| 133 | $form->addExtraClass('root-form cms-edit-form center fill-height'); |
||
| 134 | // $form->disableSecurityToken(); |
||
| 135 | // $form->setFormMethod('get'); |
||
| 136 | |||
| 137 | return $form; |
||
| 138 | } |
||
| 286 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.