| Conditions | 4 | 
| Paths | 6 | 
| Total Lines | 121 | 
| Code Lines | 58 | 
| 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  | 
            ||
| 59 | public function __construct($target)  | 
            ||
| 60 |     { | 
            ||
| 61 | $this->helper = $target->helper;  | 
            ||
| 62 | |||
| 63 | $this->targetObject = $target;  | 
            ||
| 64 | |||
| 65 | $title = $this->targetObject->isNew() ? \sprintf(\AM_YOGURT_AUDIO_ADD) : \sprintf(\AM_YOGURT_AUDIO_EDIT);  | 
            ||
| 66 | |||
| 67 |         parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); | 
            ||
| 68 | |||
| 69 |         $this->setExtra('enctype="multipart/form-data"'); | 
            ||
| 70 | |||
| 71 | //include ID field, it's needed so the module knows if it is a new form or an edited form  | 
            ||
| 72 | |||
| 73 | $hidden = new XoopsFormHidden(  | 
            ||
| 74 | 'audio_id', $this->targetObject->getVar(  | 
            ||
| 75 | 'audio_id'  | 
            ||
| 76 | )  | 
            ||
| 77 | );  | 
            ||
| 78 | |||
| 79 | $this->addElement($hidden);  | 
            ||
| 80 | |||
| 81 | unset($hidden);  | 
            ||
| 82 | |||
| 83 | // Audio_id  | 
            ||
| 84 | |||
| 85 | $this->addElement(  | 
            ||
| 86 |             new XoopsFormLabel(\AM_YOGURT_AUDIO_AUDIO_ID, $this->targetObject->getVar('audio_id'), 'audio_id') | 
            ||
| 87 | );  | 
            ||
| 88 | |||
| 89 | // Uid_owner  | 
            ||
| 90 | |||
| 91 | $this->addElement(  | 
            ||
| 92 | new XoopsFormSelectUser(  | 
            ||
| 93 | \AM_YOGURT_AUDIO_UID_OWNER, 'uid_owner', false, $this->targetObject->getVar(  | 
            ||
| 94 | 'uid_owner'  | 
            ||
| 95 | ), 1, false  | 
            ||
| 96 | ),  | 
            ||
| 97 | false  | 
            ||
| 98 | );  | 
            ||
| 99 | |||
| 100 | // Title  | 
            ||
| 101 | |||
| 102 | $this->addElement(  | 
            ||
| 103 |             new XoopsFormText(\AM_YOGURT_AUDIO_TITLE, 'title', 50, 255, $this->targetObject->getVar('title')), | 
            ||
| 104 | false  | 
            ||
| 105 | );  | 
            ||
| 106 | |||
| 107 | // Author  | 
            ||
| 108 | |||
| 109 | $this->addElement(  | 
            ||
| 110 |             new XoopsFormText(\AM_YOGURT_AUDIO_AUTHOR, 'author', 50, 255, $this->targetObject->getVar('author')), | 
            ||
| 111 | false  | 
            ||
| 112 | );  | 
            ||
| 113 | |||
| 114 | // Description  | 
            ||
| 115 | |||
| 116 |         if (\class_exists('XoopsFormEditor')) { | 
            ||
| 117 | $editorOptions = [];  | 
            ||
| 118 | |||
| 119 | $editorOptions['name'] = 'description';  | 
            ||
| 120 | |||
| 121 |             $editorOptions['value'] = $this->targetObject->getVar('description', 'e'); | 
            ||
| 122 | |||
| 123 | $editorOptions['rows'] = 5;  | 
            ||
| 124 | |||
| 125 | $editorOptions['cols'] = 40;  | 
            ||
| 126 | |||
| 127 | $editorOptions['width'] = '100%';  | 
            ||
| 128 | |||
| 129 | $editorOptions['height'] = '400px';  | 
            ||
| 130 | |||
| 131 |             //$editorOptions['editor'] = xoops_getModuleOption('yogurt_editor', 'yogurt'); | 
            ||
| 132 | |||
| 133 | //$this->addElement( new \XoopsFormEditor(AM_YOGURT_AUDIO_DESCRIPTION, 'description', $editorOptions), false );  | 
            ||
| 134 | |||
| 135 |             if ($this->helper->isUserAdmin()) { | 
            ||
| 136 | $descEditor = new XoopsFormEditor(  | 
            ||
| 137 | \AM_YOGURT_AUDIO_DESCRIPTION, $this->helper->getConfig(  | 
            ||
| 138 | 'yogurtEditorAdmin'  | 
            ||
| 139 | ), $editorOptions, $nohtml = false, $onfailure = 'textarea'  | 
            ||
| 140 | );  | 
            ||
| 141 |             } else { | 
            ||
| 142 | $descEditor = new XoopsFormEditor(  | 
            ||
| 143 | \AM_YOGURT_AUDIO_DESCRIPTION, $this->helper->getConfig(  | 
            ||
| 144 | 'yogurtEditorUser'  | 
            ||
| 145 | ), $editorOptions, $nohtml = false, $onfailure = 'textarea'  | 
            ||
| 146 | );  | 
            ||
| 147 | }  | 
            ||
| 148 |         } else { | 
            ||
| 149 | $descEditor = new \XoopsFormDhtmlTextArea(  | 
            ||
| 150 | \AM_YOGURT_AUDIO_DESCRIPTION, 'description', $this->targetObject->getVar(  | 
            ||
| 151 | 'description',  | 
            ||
| 152 | 'e'  | 
            ||
| 153 | ), 5, 50  | 
            ||
| 154 | );  | 
            ||
| 155 | }  | 
            ||
| 156 | |||
| 157 | $this->addElement($descEditor);  | 
            ||
| 158 | |||
| 159 | // Url  | 
            ||
| 160 | |||
| 161 |         $this->addElement(new \XoopsFormFile(\AM_YOGURT_AUDIO_URL, 'filename', $this->helper->getConfig('maxsize')), false); | 
            ||
| 162 | |||
| 163 | // Data_creation  | 
            ||
| 164 | |||
| 165 | $this->addElement(  | 
            ||
| 166 | new XoopsFormTextDateSelect(  | 
            ||
| 167 |                 \AM_YOGURT_AUDIO_DATE_CREATED, 'date_created', 0, \formatTimestamp($this->targetObject->getVar('date_created'), 's') | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 168 | )  | 
            ||
| 169 | );  | 
            ||
| 170 | |||
| 171 | $this->addElement(  | 
            ||
| 172 | new XoopsFormTextDateSelect(  | 
            ||
| 173 |                 \AM_YOGURT_AUDIO_DATE_UPDATED, 'date_updated', 0, \formatTimestamp($this->targetObject->getVar('date_updated'), 's') | 
            ||
| 174 | )  | 
            ||
| 175 | );  | 
            ||
| 176 | |||
| 177 |         $this->addElement(new XoopsFormHidden('op', 'save')); | 
            ||
| 178 | |||
| 179 |         $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit')); | 
            ||
| 180 | }  | 
            ||
| 182 |