| Conditions | 13 |
| Paths | 24 |
| Total Lines | 127 |
| Code Lines | 87 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 62 | private function build_basic_form($edit = 0) |
||
| 63 | { |
||
| 64 | $this->addElement('header', get_plugin_lang('NewOutcomeFormTitle')); |
||
|
|
|||
| 65 | $this->addElement('hidden', 'hid_user_id'); |
||
| 66 | $this->addElement('hidden', 'hid_course_code'); |
||
| 67 | |||
| 68 | $this->addText( |
||
| 69 | 'name', |
||
| 70 | get_lang('EvaluationName'), |
||
| 71 | true, |
||
| 72 | [ |
||
| 73 | 'maxlength' => '50', |
||
| 74 | 'id' => 'evaluation_title', |
||
| 75 | ] |
||
| 76 | ); |
||
| 77 | |||
| 78 | $cat_id = $this->evaluation_object->get_category_id(); |
||
| 79 | |||
| 80 | $session_id = api_get_session_id(); |
||
| 81 | $course_code = api_get_course_id(); |
||
| 82 | $all_categories = Category:: load(null, null, $course_code, null, null, $session_id, false); |
||
| 83 | |||
| 84 | if (count($all_categories) == 1) { |
||
| 85 | $this->addElement('hidden', 'hid_category_id', $cat_id); |
||
| 86 | } else { |
||
| 87 | $select_gradebook = $this->addElement( |
||
| 88 | 'select', |
||
| 89 | 'hid_category_id', |
||
| 90 | get_lang('SelectGradebook'), |
||
| 91 | [], |
||
| 92 | ['id' => 'hid_category_id'] |
||
| 93 | ); |
||
| 94 | $this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'nonzero'); |
||
| 95 | $default_weight = 0; |
||
| 96 | if (!empty($all_categories)) { |
||
| 97 | foreach ($all_categories as $my_cat) { |
||
| 98 | if ($my_cat->get_course_code() == api_get_course_id()) { |
||
| 99 | $grade_model_id = $my_cat->get_grade_model_id(); |
||
| 100 | if (empty($grade_model_id)) { |
||
| 101 | if ($my_cat->get_parent_id() == 0) { |
||
| 102 | $default_weight = $my_cat->get_weight(); |
||
| 103 | $select_gradebook->addOption(get_lang('Default'), $my_cat->get_id()); |
||
| 104 | $cats_added[] = $my_cat->get_id(); |
||
| 105 | } else { |
||
| 106 | $select_gradebook->addOption($my_cat->get_name(), $my_cat->get_id()); |
||
| 107 | $cats_added[] = $my_cat->get_id(); |
||
| 108 | } |
||
| 109 | } else { |
||
| 110 | $select_gradebook->addOption(get_lang('Select'), 0); |
||
| 111 | } |
||
| 112 | if ($this->evaluation_object->get_category_id() == $my_cat->get_id()) { |
||
| 113 | $default_weight = $my_cat->get_weight(); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | $this->addFloat( |
||
| 121 | 'weight_mask', |
||
| 122 | [ |
||
| 123 | get_lang('Weight'), |
||
| 124 | null, |
||
| 125 | ' [0 .. <span id="max_weight">'.$all_categories[0]->get_weight().'</span>] ', |
||
| 126 | ], |
||
| 127 | true, |
||
| 128 | [ |
||
| 129 | 'size' => '4', |
||
| 130 | 'maxlength' => '5', |
||
| 131 | ] |
||
| 132 | ); |
||
| 133 | |||
| 134 | if ($edit) { |
||
| 135 | if (!$this->evaluation_object->has_results()) { |
||
| 136 | $this->addText( |
||
| 137 | 'max', |
||
| 138 | get_lang('QualificationNumeric'), |
||
| 139 | true, |
||
| 140 | [ |
||
| 141 | 'maxlength' => '5', |
||
| 142 | ] |
||
| 143 | ); |
||
| 144 | } else { |
||
| 145 | $this->addText( |
||
| 146 | 'max', |
||
| 147 | [get_lang('QualificationNumeric'), get_lang('CannotChangeTheMaxNote')], |
||
| 148 | false, |
||
| 149 | [ |
||
| 150 | 'maxlength' => '5', |
||
| 151 | 'disabled' => 'disabled', |
||
| 152 | ] |
||
| 153 | ); |
||
| 154 | } |
||
| 155 | } else { |
||
| 156 | $this->addText( |
||
| 157 | 'max', |
||
| 158 | get_lang('QualificationNumeric'), |
||
| 159 | true, |
||
| 160 | [ |
||
| 161 | 'maxlength' => '5', |
||
| 162 | ] |
||
| 163 | ); |
||
| 164 | $default_max = api_get_setting('gradebook_default_weight'); |
||
| 165 | $defaults['max'] = isset($default_max) ? $default_max : 100; |
||
| 166 | $this->setDefaults($defaults); |
||
| 167 | } |
||
| 168 | |||
| 169 | $this->addElement('textarea', 'description', get_lang('Description')); |
||
| 170 | $this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'required'); |
||
| 171 | $this->addElement('checkbox', 'visible', null, get_lang('Visible')); |
||
| 172 | $this->addRule('max', get_lang('OnlyNumbers'), 'numeric'); |
||
| 173 | $this->addRule( |
||
| 174 | 'max', |
||
| 175 | get_lang('NegativeValue'), |
||
| 176 | 'compare', |
||
| 177 | '>=', |
||
| 178 | 'server', |
||
| 179 | false, |
||
| 180 | false, |
||
| 181 | 0 |
||
| 182 | ); |
||
| 183 | $setting = api_get_setting('tool_visible_by_default_at_creation'); |
||
| 184 | $visibility_default = 1; |
||
| 185 | if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') { |
||
| 186 | $visibility_default = 0; |
||
| 187 | } |
||
| 188 | $this->setDefaults(['visible' => $visibility_default]); |
||
| 189 | } |
||
| 191 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.