| Conditions | 10 |
| Paths | 12 |
| Total Lines | 41 |
| Code Lines | 25 |
| 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 |
||
| 13 | public function createForm($survey_data, $formData) |
||
| 14 | { |
||
| 15 | parent::createForm($survey_data, $formData); |
||
| 16 | |||
| 17 | $options = [ |
||
| 18 | 'horizontal' => get_lang('Horizontal'), |
||
| 19 | 'vertical' => get_lang('Vertical'), |
||
| 20 | ]; |
||
| 21 | $this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options); |
||
| 22 | |||
| 23 | $formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal'; |
||
| 24 | $this->getForm()->setDefaults($formData); |
||
| 25 | |||
| 26 | $config = ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120']; |
||
| 27 | $total = count($formData['answers']); |
||
| 28 | |||
| 29 | if (is_array($formData['answers'])) { |
||
| 30 | foreach ($formData['answers'] as $key => $value) { |
||
| 31 | if ($value === 'other') { |
||
| 32 | continue; |
||
| 33 | } |
||
| 34 | $this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config); |
||
| 35 | if ($total > 2) { |
||
| 36 | $this->getForm()->addButton("delete_answer[$key]", get_lang('Delete'), 'trash', 'danger'); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | if (isset($formData['answersid']) && !empty($formData['answersid'])) { |
||
| 42 | $counter = 1; |
||
| 43 | $total = count($formData['answersid']); |
||
| 44 | foreach ($formData['answersid'] as $value) { |
||
| 45 | if ($counter === $total) { |
||
| 46 | break; |
||
| 47 | } |
||
| 48 | $this->getForm()->addHidden('answersid[]', $value); |
||
| 49 | $counter++; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | parent::addRemoveButtons($formData); |
||
| 54 | } |
||
| 121 |