| Conditions | 5 |
| Paths | 7 |
| Total Lines | 60 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 77 | public static function getLpAcquisition( |
||
| 78 | array $lpInfo, |
||
| 79 | int $studentId, |
||
| 80 | int $courseId, |
||
| 81 | int $sessionId = 0, |
||
| 82 | bool $allowEdit = false |
||
| 83 | ): string { |
||
| 84 | $lpView = learnpath::findLastView($lpInfo['iid'], $studentId, $courseId, $sessionId); |
||
| 85 | |||
| 86 | if (empty($lpView)) { |
||
| 87 | return '-'; |
||
| 88 | } |
||
| 89 | |||
| 90 | $extraField = new ExtraField('lp_view'); |
||
| 91 | $field = $extraField->get_handler_field_info_by_field_variable(self::VARIABLE_ACQUISITION); |
||
| 92 | |||
| 93 | $extraFieldValue = new ExtraFieldValue('lp_view'); |
||
| 94 | $value = $extraFieldValue->get_values_by_handler_and_field_variable($lpView['iid'], self::VARIABLE_ACQUISITION); |
||
| 95 | |||
| 96 | $return = ''; |
||
| 97 | |||
| 98 | if (empty($value)) { |
||
| 99 | $return .= '-'; |
||
| 100 | } else { |
||
| 101 | $optionSelected = array_filter( |
||
| 102 | $field['options'], |
||
| 103 | function (array $option) use ($value) { |
||
| 104 | return $option['option_value'] == $value['value']; |
||
| 105 | } |
||
| 106 | ); |
||
| 107 | |||
| 108 | if (empty($optionSelected)) { |
||
| 109 | $return .= '-'; |
||
| 110 | } else { |
||
| 111 | $optionSelected = current($optionSelected); |
||
| 112 | $valueComment = json_decode($value['comment'], true); |
||
| 113 | |||
| 114 | $register = api_get_user_entity($valueComment['user']); |
||
| 115 | |||
| 116 | $return .= $optionSelected['display_text'].'<br>' |
||
| 117 | .Display::tag('small', $register->getCompleteName()).'<br>' |
||
| 118 | .Display::tag( |
||
| 119 | 'small', |
||
| 120 | api_convert_and_format_date($valueComment['datetime'], DATE_TIME_FORMAT_LONG) |
||
| 121 | ).'<br>'; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | $editUrl = api_get_path(WEB_AJAX_PATH).'student_follow_page.ajax.php?' |
||
| 126 | .http_build_query(['lp_view' => $lpView['iid'], 'a' => 'form_adquisition']); |
||
| 127 | |||
| 128 | if ($allowEdit) { |
||
| 129 | $return .= Display::url( |
||
| 130 | Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_TINY), |
||
| 131 | $editUrl, |
||
| 132 | ['class' => 'ajax', 'data-title' => $lpInfo['lp_name']] |
||
| 133 | ); |
||
| 134 | } |
||
| 135 | |||
| 136 | return '<div id="acquisition-'.$lpView['iid'].'">'.$return.'</div>'; |
||
| 137 | } |
||
| 210 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.