| Conditions | 14 |
| Paths | 476 |
| Total Lines | 70 |
| Code Lines | 46 |
| Lines | 14 |
| Ratio | 20 % |
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 |
||
| 70 | public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) { |
||
| 71 | |||
| 72 | $is_western_name_order = api_is_western_name_order(); |
||
| 73 | $scoredisplay = ScoreDisplay :: instance(); |
||
| 74 | |||
| 75 | // determine sorting type |
||
| 76 | $col_adjust = $this->iscourse == '1' ? 1 : 0; |
||
| 77 | |||
| 78 | switch ($this->column) { |
||
| 79 | // first name or last name |
||
| 80 | View Code Duplication | case (0 + $col_adjust): |
|
| 81 | if ($is_western_name_order) { |
||
| 82 | $sorting = ResultsDataGenerator :: RDG_SORT_FIRSTNAME; |
||
| 83 | } else { |
||
| 84 | $sorting = ResultsDataGenerator :: RDG_SORT_LASTNAME; |
||
| 85 | } |
||
| 86 | break; |
||
| 87 | // first name or last name |
||
| 88 | View Code Duplication | case (1 + $col_adjust): |
|
| 89 | if ($is_western_name_order) { |
||
| 90 | $sorting = ResultsDataGenerator :: RDG_SORT_LASTNAME; |
||
| 91 | } else { |
||
| 92 | $sorting = ResultsDataGenerator :: RDG_SORT_FIRSTNAME; |
||
| 93 | } |
||
| 94 | break; |
||
| 95 | //Score |
||
| 96 | case (2 + $col_adjust): |
||
| 97 | $sorting = ResultsDataGenerator :: RDG_SORT_SCORE; |
||
| 98 | break; |
||
| 99 | case (3 + $col_adjust): |
||
| 100 | $sorting = ResultsDataGenerator :: RDG_SORT_MASK; |
||
| 101 | break; |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($this->direction == 'DESC') { |
||
| 105 | $sorting |= ResultsDataGenerator :: RDG_SORT_DESC; |
||
| 106 | } else { |
||
| 107 | $sorting |= ResultsDataGenerator :: RDG_SORT_ASC; |
||
| 108 | } |
||
| 109 | |||
| 110 | $data_array = $this->datagen->get_data($sorting, $from, $this->per_page); |
||
| 111 | |||
| 112 | // generate the data to display |
||
| 113 | $sortable_data = array(); |
||
| 114 | foreach ($data_array as $item) { |
||
| 115 | $row = array (); |
||
| 116 | if ($this->iscourse == '1') { |
||
| 117 | $row[] = $item['result_id']; |
||
| 118 | } |
||
| 119 | if ($is_western_name_order) { |
||
| 120 | $row[] = $item['firstname']; |
||
| 121 | $row[] = $item['lastname']; |
||
| 122 | } else { |
||
| 123 | $row[] = $item['lastname']; |
||
| 124 | $row[] = $item['firstname']; |
||
| 125 | } |
||
| 126 | |||
| 127 | $row[] = Display::bar_progress($item['percentage_score'], false, $item['score']); |
||
| 128 | //$row[] = Display::bar_progress($item['percentage_score'], true); |
||
| 129 | if ($scoredisplay->is_custom()) { |
||
| 130 | $row[] = $item['display']; |
||
| 131 | } |
||
| 132 | if (!$this->forprint) { |
||
| 133 | $row[] = $this->build_edit_column ($item); |
||
| 134 | } |
||
| 135 | $sortable_data[] = $row; |
||
| 136 | } |
||
| 137 | |||
| 138 | return $sortable_data; |
||
| 139 | } |
||
| 140 | |||
| 176 |
This check marks private properties in classes that are never used. Those properties can be removed.