| 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 |
||
| 59 | public static function getLpAcquisition( |
||
| 60 | array $lpInfo, |
||
| 61 | int $studentId, |
||
| 62 | int $courseId, |
||
| 63 | int $sessionId = 0, |
||
| 64 | bool $allowEdit = false |
||
| 65 | ): string { |
||
| 66 | $lpView = learnpath::findLastView($lpInfo['iid'], $studentId, $courseId, $sessionId); |
||
| 67 | |||
| 68 | if (empty($lpView)) { |
||
| 69 | return '-'; |
||
| 70 | } |
||
| 71 | |||
| 72 | $extraField = new ExtraField('lp_view'); |
||
| 73 | $field = $extraField->get_handler_field_info_by_field_variable(self::VARIABLE_ACQUISITION); |
||
| 74 | |||
| 75 | $extraFieldValue = new ExtraFieldValue('lp_view'); |
||
| 76 | $value = $extraFieldValue->get_values_by_handler_and_field_variable($lpView['iid'], self::VARIABLE_ACQUISITION); |
||
| 77 | |||
| 78 | $return = ''; |
||
| 79 | |||
| 80 | if (empty($value)) { |
||
| 81 | $return .= '-'; |
||
| 82 | } else { |
||
| 83 | $optionSelected = array_filter( |
||
| 84 | $field['options'], |
||
| 85 | function (array $option) use ($value) { |
||
| 86 | return $option['option_value'] == $value['value']; |
||
| 87 | } |
||
| 88 | ); |
||
| 89 | |||
| 90 | if (empty($optionSelected)) { |
||
| 91 | $return .= '-'; |
||
| 92 | } else { |
||
| 93 | $optionSelected = current($optionSelected); |
||
| 94 | $valueComment = json_decode($value['comment'], true); |
||
| 95 | |||
| 96 | $register = api_get_user_entity($valueComment['user']); |
||
| 97 | |||
| 98 | $return .= $optionSelected['display_text'].'<br>' |
||
| 99 | .Display::tag('small', $register->getCompleteName()).'<br>' |
||
| 100 | .Display::tag( |
||
| 101 | 'small', |
||
| 102 | api_convert_and_format_date($valueComment['datetime'], DATE_TIME_FORMAT_LONG) |
||
| 103 | ).'<br>'; |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | $editUrl = api_get_path(WEB_AJAX_PATH).'student_follow_page.ajax.php?' |
||
| 108 | .http_build_query(['lp_view' => $lpView['iid'], 'a' => 'form_adquisition']); |
||
| 109 | |||
| 110 | if ($allowEdit) { |
||
| 111 | $return .= Display::url( |
||
| 112 | Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_TINY), |
||
| 113 | $editUrl, |
||
| 114 | ['class' => 'ajax', 'data-title' => $lpInfo['lp_name']] |
||
| 115 | ); |
||
| 116 | } |
||
| 117 | |||
| 118 | return '<div id="acquisition-'.$lpView['iid'].'">'.$return.'</div>'; |
||
| 119 | } |
||
| 192 |
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.