Conditions | 4 |
Paths | 6 |
Total Lines | 61 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 declare(strict_types=1); |
||
48 | public function __construct($target) |
||
49 | { |
||
50 | $this->helper = $target->helper; |
||
51 | $this->targetObject = $target; |
||
52 | |||
53 | $title = $this->targetObject->isNew() ? \AM_ADSLIGHT_REPLIES_ADD : \AM_ADSLIGHT_REPLIES_EDIT; |
||
54 | parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
55 | $this->setExtra('enctype="multipart/form-data"'); |
||
56 | |||
57 | //include ID field, it's needed so the module knows if it is a new form or an edited form |
||
58 | |||
59 | $hidden = new \XoopsFormHidden('r_lid', $this->targetObject->getVar('r_lid')); |
||
60 | $this->addElement($hidden); |
||
61 | unset($hidden); |
||
62 | |||
63 | // R_lid |
||
64 | $this->addElement(new \XoopsFormLabel(\AM_ADSLIGHT_REPLIES_R_LID, $this->targetObject->getVar('r_lid'), 'r_lid')); |
||
65 | // Lid |
||
66 | //$listingHandler = $this->helper->getHandler('Listing'); |
||
67 | //$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
68 | /** @var \XoopsPersistableObjectHandler $listingHandler */ |
||
69 | $listingHandler = $this->helper->getHandler('Listing'); |
||
70 | |||
71 | $listing_id_select = new \XoopsFormSelect(\AM_ADSLIGHT_REPLIES_LID, 'lid', $this->targetObject->getVar('lid')); |
||
72 | $listing_id_select->addOptionArray($listingHandler->getList()); |
||
73 | $this->addElement($listing_id_select, false); |
||
74 | // Title |
||
75 | $this->addElement(new \XoopsFormText(\AM_ADSLIGHT_REPLIES_TITLE, 'title', 50, 255, $this->targetObject->getVar('title')), false); |
||
76 | // Date |
||
77 | $this->addElement(new \XoopsFormTextDateSelect(\AM_ADSLIGHT_REPLIES_DATE, 'date', 0, \formatTimestamp($this->targetObject->getVar('date'), 's'))); |
||
|
|||
78 | // Submitter |
||
79 | $this->addElement(new \XoopsFormSelectUser(\AM_ADSLIGHT_REPLIES_SUBMITTER, 'submitter', false, $this->targetObject->getVar('submitter'), 1, false), false); |
||
80 | // Message |
||
81 | if (\class_exists('XoopsFormEditor')) { |
||
82 | $editorOptions = []; |
||
83 | $editorOptions['name'] = 'message'; |
||
84 | $editorOptions['value'] = $this->targetObject->getVar('message', 'e'); |
||
85 | $editorOptions['rows'] = 5; |
||
86 | $editorOptions['cols'] = 40; |
||
87 | $editorOptions['width'] = '100%'; |
||
88 | $editorOptions['height'] = '400px'; |
||
89 | //$editorOptions['editor'] = xoops_getModuleOption('adslight_editor', 'adslight'); |
||
90 | //$this->addElement( new \XoopsFormEditor(AM_ADSLIGHT_REPLIES_MESSAGE, 'message', $editorOptions), false ); |
||
91 | if ($this->helper->isUserAdmin()) { |
||
92 | $descEditor = new \XoopsFormEditor(\AM_ADSLIGHT_REPLIES_MESSAGE, $this->helper->getConfig('adslightEditorAdmin'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
93 | } else { |
||
94 | $descEditor = new \XoopsFormEditor(\AM_ADSLIGHT_REPLIES_MESSAGE, $this->helper->getConfig('adslightEditorUser'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
95 | } |
||
96 | } else { |
||
97 | $descEditor = new \XoopsFormDhtmlTextArea(\AM_ADSLIGHT_REPLIES_MESSAGE, 'description', $this->targetObject->getVar('description', 'e'), 5, 50); |
||
98 | } |
||
99 | $this->addElement($descEditor); |
||
100 | // Tele |
||
101 | $this->addElement(new \XoopsFormText(\AM_ADSLIGHT_REPLIES_TELE, 'tele', 50, 255, $this->targetObject->getVar('tele')), false); |
||
102 | |||
103 | $this->addElement(new \XoopsFormText(\AM_ADSLIGHT_REPLIES_EMAIL, 'email', 50, 255, $this->targetObject->getVar('email')), false); |
||
104 | // R_usid |
||
105 | $this->addElement(new \XoopsFormSelectUser(\AM_ADSLIGHT_REPLIES_R_USID, 'r_usid', false, $this->targetObject->getVar('r_usid'), 1, false), false); |
||
106 | |||
107 | $this->addElement(new \XoopsFormHidden('op', 'save')); |
||
108 | $this->addElement(new \XoopsFormButton('', 'submit', \_SUBMIT, 'submit')); |
||
109 | } |
||
111 |