| Conditions | 13 |
| Paths | 264 |
| Total Lines | 61 |
| Code Lines | 43 |
| 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 |
||
| 37 | public function thematic_advance($action) |
||
| 38 | { |
||
| 39 | $thematic = new Thematic(); |
||
| 40 | $attendance = new Attendance(); |
||
| 41 | $data = []; |
||
| 42 | $displayHeader = !empty($_REQUEST['display']) && 'no_header' === $_REQUEST['display'] ? false : true; |
||
| 43 | |||
| 44 | |||
| 45 | $thematic_id = intval($_REQUEST['thematic_id']); |
||
| 46 | $thematic_advance_id = isset($_REQUEST['thematic_advance_id']) ? (int) $_REQUEST['thematic_advance_id'] : null; |
||
| 47 | $thematic_advance_data = []; |
||
| 48 | switch ($action) { |
||
| 49 | case 'thematic_advance_delete': |
||
| 50 | |||
| 51 | break; |
||
| 52 | case 'thematic_advance_list': |
||
| 53 | if (!api_is_allowed_to_edit(null, true)) { |
||
| 54 | echo ''; |
||
| 55 | exit; |
||
| 56 | } |
||
| 57 | |||
| 58 | $data['action'] = $_REQUEST['action']; |
||
| 59 | $data['thematic_id'] = $_REQUEST['thematic_id']; |
||
| 60 | $data['attendance_select'] = $attendance_select; |
||
| 61 | if (isset($_REQUEST['thematic_advance_id'])) { |
||
| 62 | $data['thematic_advance_id'] = $_REQUEST['thematic_advance_id']; |
||
| 63 | $thematic_advance_data = $thematic->get_thematic_advance_list($_REQUEST['thematic_advance_id']); |
||
| 64 | $data['thematic_advance_data'] = $thematic_advance_data; |
||
| 65 | } |
||
| 66 | break; |
||
| 67 | default: |
||
| 68 | $thematic_advance_data = $thematic->get_thematic_advance_list($thematic_advance_id); |
||
| 69 | break; |
||
| 70 | } |
||
| 71 | |||
| 72 | // get calendar select by attendance id |
||
| 73 | $calendar_select = []; |
||
| 74 | if (!empty($thematic_advance_data)) { |
||
| 75 | if (!empty($thematic_advance_data['attendance_id'])) { |
||
| 76 | $attendance_calendar = $attendance->get_attendance_calendar($thematic_advance_data['attendance_id']); |
||
| 77 | if (!empty($attendance_calendar)) { |
||
| 78 | foreach ($attendance_calendar as $calendar) { |
||
| 79 | $calendar_select[$calendar['date_time']] = $calendar['date_time']; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | $data['action'] = $action; |
||
| 86 | $data['thematic_id'] = $thematic_id; |
||
| 87 | $data['thematic_advance_id'] = $thematic_advance_id; |
||
| 88 | $data['attendance_select'] = $attendance_select; |
||
| 89 | $data['thematic_advance_data'] = $thematic_advance_data; |
||
| 90 | $data['calendar_select'] = $calendar_select; |
||
| 91 | $layoutName = $displayHeader ? 'layout' : 'layout_no_header'; |
||
| 92 | |||
| 93 | // render to the view |
||
| 94 | $this->view->set_data($data); |
||
| 95 | $this->view->set_layout($layoutName); |
||
| 96 | $this->view->set_template('thematic_advance'); |
||
| 97 | $this->view->render(); |
||
| 98 | } |
||
| 100 |