| Conditions | 6 |
| Paths | 24 |
| Total Lines | 82 |
| Code Lines | 58 |
| 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 declare(strict_types=1); |
||
| 53 | public function __construct($target) |
||
| 54 | { |
||
| 55 | $this->helper = $target->helper; |
||
| 56 | $this->targetObject = $target; |
||
| 57 | $title = $this->targetObject->isNew() ? \AM_SUICO_NOTES_ADD : \AM_SUICO_NOTES_EDIT; |
||
| 58 | parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
| 59 | $this->setExtra('enctype="multipart/form-data"'); |
||
| 60 | //include ID field, it's needed so the module knows if it is a new form or an edited form |
||
| 61 | $hidden = new XoopsFormHidden( |
||
| 62 | 'note_id', |
||
| 63 | $this->targetObject->getVar( |
||
| 64 | 'note_id' |
||
| 65 | ) |
||
| 66 | ); |
||
| 67 | $this->addElement($hidden); |
||
| 68 | unset($hidden); |
||
| 69 | // Note_id |
||
| 70 | $this->addElement( |
||
| 71 | new XoopsFormLabel(\AM_SUICO_NOTES_NOTE_ID, $this->targetObject->getVar('note_id'), 'note_id') |
||
| 72 | ); |
||
| 73 | // Note_text |
||
| 74 | if (\class_exists('XoopsFormEditor')) { |
||
| 75 | $editorOptions = []; |
||
| 76 | $editorOptions['name'] = 'note_text'; |
||
| 77 | $editorOptions['value'] = $this->targetObject->getVar('note_text', 'e'); |
||
| 78 | $editorOptions['rows'] = 5; |
||
| 79 | $editorOptions['cols'] = 40; |
||
| 80 | $editorOptions['width'] = '100%'; |
||
| 81 | $editorOptions['height'] = '400px'; |
||
| 82 | //$editorOptions['editor'] = xoops_getModuleOption('suico_editor', 'suico'); |
||
| 83 | //$this->addElement( new \XoopsFormEditor(AM_SUICO_NOTES_NOTE_TEXT, 'note_text', $editorOptions), false ); |
||
| 84 | if ($this->helper->isUserAdmin()) { |
||
| 85 | $descEditor = new XoopsFormEditor( |
||
| 86 | \AM_SUICO_NOTES_NOTE_TEXT, $this->helper->getConfig( |
||
| 87 | 'suicoEditorAdmin' |
||
| 88 | ), $editorOptions, $nohtml = false, $onfailure = 'textarea' |
||
| 89 | ); |
||
| 90 | } else { |
||
| 91 | $descEditor = new XoopsFormEditor( |
||
| 92 | \AM_SUICO_NOTES_NOTE_TEXT, $this->helper->getConfig( |
||
| 93 | 'suicoEditorUser' |
||
| 94 | ), $editorOptions, $nohtml = false, $onfailure = 'textarea' |
||
| 95 | ); |
||
| 96 | } |
||
| 97 | } else { |
||
| 98 | $descEditor = new XoopsFormDhtmlTextArea( |
||
| 99 | \AM_SUICO_NOTES_NOTE_TEXT, 'description', $this->targetObject->getVar( |
||
| 100 | 'description', |
||
| 101 | 'e' |
||
| 102 | ), 5, 50 |
||
| 103 | ); |
||
| 104 | } |
||
| 105 | $this->addElement($descEditor); |
||
| 106 | // Note_from |
||
| 107 | $this->addElement( |
||
| 108 | new XoopsFormSelectUser( |
||
| 109 | \AM_SUICO_NOTES_NOTE_FROM, 'note_from', false, $this->targetObject->getVar( |
||
| 110 | 'note_from' |
||
| 111 | ), 1, false |
||
| 112 | ), |
||
| 113 | false |
||
| 114 | ); |
||
| 115 | // Note_to |
||
| 116 | $this->addElement( |
||
| 117 | new XoopsFormSelectUser( |
||
| 118 | \AM_SUICO_NOTES_NOTE_TO, 'note_to', false, $this->targetObject->getVar( |
||
| 119 | 'note_to' |
||
| 120 | ), 1, false |
||
| 121 | ), |
||
| 122 | false |
||
| 123 | ); |
||
| 124 | // Private |
||
| 125 | $private = $this->targetObject->isNew() ? 0 : $this->targetObject->getVar('private'); |
||
| 126 | $check_private = new XoopsFormCheckBox(\AM_SUICO_NOTES_PRIVATE, 'private', $private); |
||
| 127 | $check_private->addOption(1, ' '); |
||
| 128 | $this->addElement($check_private); |
||
| 129 | // Date |
||
| 130 | // $this->addElement(new XoopsFormTextDateSelect(AM_SUICO_NOTES_DATE, 'date',0, \strtotime($this->targetObject->getVar('date')))); |
||
| 131 | $noteCreated = $this->targetObject->isNew() ? 0 : $this->targetObject->getVar('date_created'); |
||
| 132 | $this->addElement(new \XoopsFormTextDateSelect(\AM_SUICO_NOTES_DATE, 'date_created', '', $noteCreated), true); |
||
|
|
|||
| 133 | $this->addElement(new XoopsFormHidden('op', 'save')); |
||
| 134 | $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit')); |
||
| 135 | } |
||
| 137 |