| Conditions | 7 |
| Paths | 48 |
| Total Lines | 52 |
| Code Lines | 34 |
| Lines | 20 |
| Ratio | 38.46 % |
| 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 |
||
| 139 | public function createForm(&$form) |
||
| 140 | { |
||
| 141 | // Categories |
||
| 142 | $tabCat = TestCategory::getCategoriesIdAndName(); |
||
| 143 | $form->addSelect('questionCategory', get_lang('Category'), $tabCat); |
||
| 144 | // Advanced parameters |
||
| 145 | $levels = self::get_default_levels(); |
||
| 146 | $form->addSelect('questionLevel', get_lang('Difficulty'), $levels); |
||
| 147 | $form->addElement('hidden', 'answerType', READING_COMPREHENSION); |
||
| 148 | $form->addTextarea('questionDescription', get_lang('Text'), ['rows' => 20]); |
||
| 149 | // question name |
||
| 150 | View Code Duplication | if (api_get_configuration_value('save_titles_as_html')) { |
|
| 151 | $editorConfig = ['ToolbarSet' => 'Minimal']; |
||
| 152 | $form->addHtmlEditor( |
||
| 153 | 'questionName', |
||
| 154 | get_lang('Question'), |
||
| 155 | false, |
||
| 156 | false, |
||
| 157 | $editorConfig, |
||
| 158 | true |
||
| 159 | ); |
||
| 160 | } else { |
||
| 161 | $form->addText('questionName', get_lang('Question'), false); |
||
| 162 | } |
||
| 163 | |||
| 164 | // hidden values |
||
| 165 | $my_id = isset($_REQUEST['myid']) ? intval($_REQUEST['myid']) : null; |
||
| 166 | $form->addElement('hidden', 'myid', $my_id); |
||
| 167 | $form->addRule('questionName', get_lang('GiveQuestion'), 'required'); |
||
| 168 | |||
| 169 | $isContent = isset($_REQUEST['isContent']) ? intval($_REQUEST['isContent']) : null; |
||
| 170 | |||
| 171 | // default values |
||
| 172 | $defaults = array(); |
||
| 173 | $defaults['questionName'] = $this->question; |
||
| 174 | $defaults['questionDescription'] = $this->description; |
||
| 175 | $defaults['questionLevel'] = $this->level; |
||
| 176 | $defaults['questionCategory'] = $this->category; |
||
| 177 | |||
| 178 | // Came from he question pool |
||
| 179 | if (isset($_GET['fromExercise'])) { |
||
| 180 | $form->setDefaults($defaults); |
||
| 181 | } |
||
| 182 | |||
| 183 | View Code Duplication | if (!empty($_REQUEST['myid'])) { |
|
| 184 | $form->setDefaults($defaults); |
||
| 185 | } else { |
||
| 186 | if ($isContent == 1) { |
||
| 187 | $form->setDefaults($defaults); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 207 |