| Conditions | 2 |
| Paths | 2 |
| Total Lines | 56 |
| 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 getFormFeedback($action = false) |
||
| 67 | { |
||
| 68 | if (false === $action) { |
||
| 69 | $action = $_SERVER['REQUEST_URI']; |
||
|
|
|||
| 70 | } |
||
| 71 | $moduleDirName = basename(dirname(dirname(__DIR__))); |
||
| 72 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); |
||
| 73 | // Get Theme Form |
||
| 74 | xoops_load('XoopsFormLoader'); |
||
| 75 | $form = new \XoopsThemeForm(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_FORM_TITLE'), 'formfeedback', 'feedback.php', 'post', true); |
||
| 76 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 77 | |||
| 78 | $recipient = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_RECIPIENT'), 'recipient', 50, 255, $GLOBALS['xoopsModule']->getInfo('author_mail')); |
||
| 79 | $recipient->setExtra('disabled="disabled"'); |
||
| 80 | $form->addElement($recipient); |
||
| 81 | $your_name = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_NAME'), 'your_name', 50, 255, $this->name); |
||
| 82 | $your_name->setExtra('placeholder="' . constant('CO_' . $moduleDirNameUpper . '_' . 'FB_NAME_PLACEHOLER') . '"'); |
||
| 83 | $form->addElement($your_name); |
||
| 84 | $your_site = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_SITE'), 'your_site', 50, 255, $this->site); |
||
| 85 | $your_site->setExtra('placeholder="' . constant('CO_' . $moduleDirNameUpper . '_' . 'FB_SITE_PLACEHOLER') . '"'); |
||
| 86 | $form->addElement($your_site); |
||
| 87 | $your_mail = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_MAIL'), 'your_mail', 50, 255, $this->email); |
||
| 88 | $your_mail->setExtra('placeholder="' . constant('CO_' . $moduleDirNameUpper . '_' . 'FB_MAIL_PLACEHOLER') . '"'); |
||
| 89 | $form->addElement($your_mail); |
||
| 90 | |||
| 91 | $fbtypeSelect = new \XoopsFormSelect(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE'), 'fb_type', $this->type); |
||
| 92 | $fbtypeSelect->addOption('', ''); |
||
| 93 | $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_SUGGESTION'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_SUGGESTION')); |
||
| 94 | $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_BUGS'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_BUGS')); |
||
| 95 | $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_TESTIMONIAL'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_TESTIMONIAL')); |
||
| 96 | $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_FEATURES'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_FEATURES')); |
||
| 97 | $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_OTHERS'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_OTHERS')); |
||
| 98 | $form->addElement($fbtypeSelect, true); |
||
| 99 | |||
| 100 | $editorConfigs = []; |
||
| 101 | $editorConfigs['name'] = 'fb_content'; |
||
| 102 | $editorConfigs['value'] = $this->content; |
||
| 103 | $editorConfigs['rows'] = 5; |
||
| 104 | $editorConfigs['cols'] = 40; |
||
| 105 | $editorConfigs['width'] = '100%'; |
||
| 106 | $editorConfigs['height'] = '400px'; |
||
| 107 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 108 | $moduleHandler = xoops_getHandler('module'); |
||
| 109 | $module = $moduleHandler->getByDirname('system'); |
||
| 110 | /** @var \XoopsConfigHandler $configHandler */ |
||
| 111 | $configHandler = xoops_getHandler('config'); |
||
| 112 | $config = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 113 | $editorConfigs['editor'] = $config['general_editor']; |
||
| 114 | $editor = new \XoopsFormEditor(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_CONTENT'), 'fb_content', $editorConfigs); |
||
| 115 | $form->addElement($editor, true); |
||
| 116 | |||
| 117 | $form->addElement(new \XoopsFormHidden('op', 'send')); |
||
| 118 | $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)); |
||
| 119 | |||
| 120 | return $form; |
||
| 121 | } |
||
| 122 | } |
||
| 123 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.