| Conditions | 4 |
| Paths | 8 |
| Total Lines | 55 |
| 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 |
||
| 66 | public function getForm($action = false) |
||
| 67 | { |
||
| 68 | global $xoopsDB; |
||
| 69 | |||
| 70 | if ($action === false) { |
||
| 71 | $action = $_SERVER["REQUEST_URI"]; |
||
| 72 | } |
||
| 73 | |||
| 74 | $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_TEMPLATE_ADD) : sprintf(_AM_XNEWSLETTER_TEMPLATE_EDIT); |
||
| 75 | |||
| 76 | include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php"; |
||
| 77 | $form = new XoopsThemeForm($title, "form", $action, "post", true); |
||
| 78 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 79 | |||
| 80 | $form->addElement(new XoopsFormText(_AM_XNEWSLETTER_TEMPLATE_TITLE, "template_title", 50, 255, $this->getVar("template_title", 'e')), true); |
||
| 81 | |||
| 82 | $editor_configs = array(); |
||
| 83 | $editor_configs["name"] = "template_description"; |
||
| 84 | $editor_configs["value"] = $this->getVar("template_description", "e"); |
||
| 85 | $editor_configs["rows"] = 10; |
||
| 86 | $editor_configs["cols"] = 80; |
||
| 87 | $editor_configs["width"] = "100%"; |
||
| 88 | $editor_configs["height"] = "400px"; |
||
| 89 | $editor_configs["editor"] = $this->xnewsletter->getConfig('xnewsletter_editor'); |
||
| 90 | $template_description_editor = new XoopsFormEditor(_AM_XNEWSLETTER_TEMPLATE_DESCRIPTION, "template_description", $editor_configs); |
||
| 91 | $template_description_editor->setDescription(_AM_XNEWSLETTER_TEMPLATE_DESCRIPTION_DESC); |
||
| 92 | $form->addElement($template_description_editor, false); |
||
| 93 | |||
| 94 | $editor_configs = array(); |
||
| 95 | $editor_configs["name"] = "template_content"; |
||
| 96 | $editor_configs["value"] = $this->getVar("template_content", "e"); |
||
| 97 | $editor_configs["rows"] = 10; |
||
| 98 | $editor_configs["cols"] = 80; |
||
| 99 | $editor_configs["width"] = "100%"; |
||
| 100 | $editor_configs["height"] = "400px"; |
||
| 101 | $editor_configs["editor"] = $this->xnewsletter->getConfig('template_editor'); |
||
| 102 | $template_content_editor = new XoopsFormEditor(_AM_XNEWSLETTER_TEMPLATE_CONTENT, "template_content", $editor_configs); |
||
| 103 | $template_content_editor->setDescription(_AM_XNEWSLETTER_TEMPLATE_CONTENT_DESC); |
||
| 104 | $form->addElement($template_content_editor, true); |
||
| 105 | |||
| 106 | $time = ($this->isNew()) ? time() : $this->getVar("template_created"); |
||
| 107 | $form->addElement(new XoopsFormHidden("template_submitter", $GLOBALS['xoopsUser']->uid())); |
||
| 108 | $form->addElement(new XoopsFormHidden("template_created", $time)); |
||
| 109 | |||
| 110 | $form->addElement(new XoopsFormLabel(_AM_XNEWSLETTER_TEMPLATE_SUBMITTER, $GLOBALS['xoopsUser']->uname())); |
||
| 111 | $form->addElement(new XoopsFormLabel(_AM_XNEWSLETTER_TEMPLATE_CREATED, formatTimestamp($time, 's'))); |
||
| 112 | |||
| 113 | //$form->addElement(new XoopsFormSelectUser(_AM_XNEWSLETTER_TEMPLATE_SUBMITTER, "template_submitter", false, $this->getVar("template_submitter"), 1, false), true); |
||
| 114 | //$form->addElement(new XoopsFormTextDateSelect(_AM_XNEWSLETTER_TEMPLATE_CREATED, "template_created", "", $this->getVar("template_created"))); |
||
| 115 | |||
| 116 | $form->addElement(new XoopsFormHidden("op", "save_template")); |
||
| 117 | $form->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit")); |
||
| 118 | |||
| 119 | return $form; |
||
| 120 | } |
||
| 121 | } |
||
| 143 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.