ch_personality::createForm()   C
last analyzed

Complexity

Conditions 13
Paths 144

Size

Total Lines 67
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 45
nc 144
nop 2
dl 0
loc 67
rs 6.25
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Class ch_personality.
6
 */
7
class ch_personality extends survey_question
8
{
9
    /**
10
     * This function creates the form elements for the multiple response questions.
11
     *
12
     * @author Patrick Cool <[email protected]>, Ghent University
13
     *
14
     * @version January 2007
15
     */
16
    public function createForm($survey_data, $form_content)
17
    {
18
        parent::createForm($survey_data, $form_content);
19
        $this->html .= '	<tr>';
0 ignored issues
show
Bug Best Practice introduced by
The property html does not exist on ch_personality. Did you maybe forget to declare it?
Loading history...
20
        $this->html .= '		<td colspan="2"><strong>'.get_lang('DisplayAnswersHorVert').'</strong></td>';
21
        $this->html .= '	</tr>';
22
        // Horizontal or vertical
23
        $this->html .= '	<tr>';
24
        $this->html .= '		<td align="right" valign="top">&nbsp;</td>';
25
        $this->html .= '		<td>';
26
        $this->html .= '		  <input name="horizontalvertical" type="radio" value="horizontal" ';
27
        if (empty($form_content['horizontalvertical']) || $form_content['horizontalvertical'] == 'horizontal') {
28
            $this->html .= 'checked="checked"';
29
        }
30
        $this->html .= '/>'.get_lang('Horizontal').'</label><br />';
31
        $this->html .= '		  <input name="horizontalvertical" type="radio" value="vertical" ';
32
33
        if (isset($form_content['horizontalvertical']) && $form_content['horizontalvertical'] == 'vertical') {
34
            $this->html .= 'checked="checked"';
35
        }
36
37
        $this->html .= ' />'.get_lang('Vertical').'</label>';
38
        $this->html .= '		</td>';
39
        $this->html .= '		<td>&nbsp;</td>';
40
        $this->html .= '	</tr>';
41
        $this->html .= '		<tr>
42
								<td colspan="">&nbsp;</td>
43
							</tr>';
44
45
        // The options
46
        $this->html .= '	<tr>';
47
        $this->html .= '		<td colspan="3"><strong>'.get_lang('AnswerOptions').'</strong></td>';
48
        $this->html .= '	</tr>';
49
        $total_number_of_answers = count($form_content['answers']);
50
51
        $question_values = [];
52
53
        // Values of question options
54
        if (is_array($form_content['values'])) { // Check if data is correct
55
            foreach ($form_content['values'] as $key => &$value) {
56
                $question_values[] = '<input size="3" type="text" id="values['.$key.']" name="values['.$key.']" value="'.$value.'" />';
57
            }
58
        }
59
        $count = 0;
60
        if (is_array($form_content['answers'])) {
61
            foreach ($form_content['answers'] as $key => &$value) {
62
                $this->html .= '<tr>';
63
                $this->html .= '<td align="right"><label for="answers['.$key.']">'.($key + 1).'</label></td>';
64
                $this->html .= '<td width="550">'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key])), '', '', null, ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120']).'</td>';
0 ignored issues
show
Bug introduced by
The function api_return_html_area was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
                $this->html .= '<td width="550">'./** @scrutinizer ignore-call */ api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key])), '', '', null, ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120']).'</td>';
Loading history...
65
                $this->html .= '<td>';
66
67
                if ($total_number_of_answers > 2) {
68
                    $this->html .= $question_values[$count];
69
                }
70
71
                if ($key < $total_number_of_answers - 1) {
72
                    $this->html .= '<input type="image" style="width:22px"   src="'.Display::returnIconPath('down.png').'"  value="move_down['.$key.']" name="move_down['.$key.']"/>';
73
                }
74
                if ($key > 0) {
75
                    $this->html .= '<input type="image" style="width:22px"   src="'.Display::returnIconPath('up.png').'"  value="move_up['.$key.']" name="move_up['.$key.']"/>';
76
                }
77
                if ($total_number_of_answers > 2) {
78
                    $this->html .= '<input type="image" style="width:22px"   src="'.Display::returnIconPath('delete.png').'"  value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
79
                }
80
                $this->html .= '</td>';
81
                $this->html .= '</tr>';
82
                $count++;
83
            }
84
        }
85
    }
86
87
    /**
88
     * @param array $questionData
89
     * @param array $answers
90
     */
91
    public function render(FormValidator $form, $questionData = [], $answers = [])
92
    {
93
        $question = new ch_yesno();
94
        $question->render($form, $questionData, $answers);
95
    }
96
}
97