| Conditions | 13 |
| Paths | 24 |
| Total Lines | 127 |
| Code Lines | 87 |
| 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 |
||
| 47 | private function build_basic_form($edit = 0) |
||
| 48 | { |
||
| 49 | $this->addElement('header', get_plugin_lang('NewOutcomeFormTitle')); |
||
|
|
|||
| 50 | $this->addElement('hidden', 'hid_user_id'); |
||
| 51 | $this->addElement('hidden', 'hid_course_code'); |
||
| 52 | |||
| 53 | $this->addText( |
||
| 54 | 'name', |
||
| 55 | get_lang('EvaluationName'), |
||
| 56 | true, |
||
| 57 | [ |
||
| 58 | 'maxlength' => '50', |
||
| 59 | 'id' => 'evaluation_title', |
||
| 60 | ] |
||
| 61 | ); |
||
| 62 | |||
| 63 | $cat_id = $this->evaluation_object->get_category_id(); |
||
| 64 | |||
| 65 | $session_id = api_get_session_id(); |
||
| 66 | $course_code = api_get_course_id(); |
||
| 67 | $all_categories = Category:: load(null, null, $course_code, null, null, $session_id, false); |
||
| 68 | |||
| 69 | if (count($all_categories) == 1) { |
||
| 70 | $this->addElement('hidden', 'hid_category_id', $cat_id); |
||
| 71 | } else { |
||
| 72 | $select_gradebook = $this->addElement( |
||
| 73 | 'select', |
||
| 74 | 'hid_category_id', |
||
| 75 | get_lang('SelectGradebook'), |
||
| 76 | [], |
||
| 77 | ['id' => 'hid_category_id'] |
||
| 78 | ); |
||
| 79 | $this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'nonzero'); |
||
| 80 | $default_weight = 0; |
||
| 81 | if (!empty($all_categories)) { |
||
| 82 | foreach ($all_categories as $my_cat) { |
||
| 83 | if ($my_cat->get_course_code() == api_get_course_id()) { |
||
| 84 | $grade_model_id = $my_cat->get_grade_model_id(); |
||
| 85 | if (empty($grade_model_id)) { |
||
| 86 | if ($my_cat->get_parent_id() == 0) { |
||
| 87 | $default_weight = $my_cat->get_weight(); |
||
| 88 | $select_gradebook->addoption(get_lang('Default'), $my_cat->get_id()); |
||
| 89 | $cats_added[] = $my_cat->get_id(); |
||
| 90 | } else { |
||
| 91 | $select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id()); |
||
| 92 | $cats_added[] = $my_cat->get_id(); |
||
| 93 | } |
||
| 94 | } else { |
||
| 95 | $select_gradebook->addoption(get_lang('Select'), 0); |
||
| 96 | } |
||
| 97 | if ($this->evaluation_object->get_category_id() == $my_cat->get_id()) { |
||
| 98 | $default_weight = $my_cat->get_weight(); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | $this->addFloat( |
||
| 106 | 'weight_mask', |
||
| 107 | [ |
||
| 108 | get_lang('Weight'), |
||
| 109 | null, |
||
| 110 | ' [0 .. <span id="max_weight">'.$all_categories[0]->get_weight().'</span>] ', |
||
| 111 | ], |
||
| 112 | true, |
||
| 113 | [ |
||
| 114 | 'size' => '4', |
||
| 115 | 'maxlength' => '5', |
||
| 116 | ] |
||
| 117 | ); |
||
| 118 | |||
| 119 | if ($edit) { |
||
| 120 | if (!$this->evaluation_object->has_results()) { |
||
| 121 | $this->addText( |
||
| 122 | 'max', |
||
| 123 | get_lang('QualificationNumeric'), |
||
| 124 | true, |
||
| 125 | [ |
||
| 126 | 'maxlength' => '5', |
||
| 127 | ] |
||
| 128 | ); |
||
| 129 | } else { |
||
| 130 | $this->addText( |
||
| 131 | 'max', |
||
| 132 | [get_lang('QualificationNumeric'), get_lang('CannotChangeTheMaxNote')], |
||
| 133 | false, |
||
| 134 | [ |
||
| 135 | 'maxlength' => '5', |
||
| 136 | 'disabled' => 'disabled', |
||
| 137 | ] |
||
| 138 | ); |
||
| 139 | } |
||
| 140 | } else { |
||
| 141 | $this->addText( |
||
| 142 | 'max', |
||
| 143 | get_lang('QualificationNumeric'), |
||
| 144 | true, |
||
| 145 | [ |
||
| 146 | 'maxlength' => '5', |
||
| 147 | ] |
||
| 148 | ); |
||
| 149 | $default_max = api_get_setting('gradebook_default_weight'); |
||
| 150 | $defaults['max'] = isset($default_max) ? $default_max : 100; |
||
| 151 | $this->setDefaults($defaults); |
||
| 152 | } |
||
| 153 | |||
| 154 | $this->addElement('textarea', 'description', get_lang('Description')); |
||
| 155 | $this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'required'); |
||
| 156 | $this->addElement('checkbox', 'visible', null, get_lang('Visible')); |
||
| 157 | $this->addRule('max', get_lang('OnlyNumbers'), 'numeric'); |
||
| 158 | $this->addRule( |
||
| 159 | 'max', |
||
| 160 | get_lang('NegativeValue'), |
||
| 161 | 'compare', |
||
| 162 | '>=', |
||
| 163 | 'server', |
||
| 164 | false, |
||
| 165 | false, |
||
| 166 | 0 |
||
| 167 | ); |
||
| 168 | $setting = api_get_setting('tool_visible_by_default_at_creation'); |
||
| 169 | $visibility_default = 1; |
||
| 170 | if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') { |
||
| 171 | $visibility_default = 0; |
||
| 172 | } |
||
| 173 | $this->setDefaults(['visible' => $visibility_default]); |
||
| 174 | } |
||
| 193 | } |
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.