| Conditions | 21 |
| Paths | 204 |
| Total Lines | 76 |
| Code Lines | 57 |
| 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 |
||
| 52 | public function collection() |
||
| 53 | { |
||
| 54 | $maxium=$this->config['maxium'] ?? false; |
||
| 55 | $percent=$this->config['percent'] ?? false; |
||
| 56 | |||
| 57 | if ($this->config['mode']=='contest') { |
||
| 58 | $row_1=['Member', 'Total', '', '', '']; |
||
| 59 | $row_2=['', 'Elo', 'Rank', 'Solved', 'Penalty']; |
||
| 60 | foreach ($this->contest_data as $contest) { |
||
| 61 | array_push($row_1, $contest['name'], '', ''); |
||
| 62 | array_push($row_2, 'Rank', 'Solved', 'Penalty'); |
||
| 63 | } |
||
| 64 | $data=[$row_1, $row_2]; |
||
| 65 | foreach ($this->member_data as $member) { |
||
| 66 | $display_name=$member['name']; |
||
| 67 | if (!empty($member['nick_name'])) { |
||
| 68 | $display_name.=' ('.$member['nick_name'].')'; |
||
| 69 | } |
||
| 70 | $row=[ |
||
| 71 | $display_name, |
||
| 72 | $member['elo'], |
||
| 73 | !empty($member['rank_ave']) ? round($member['rank_ave'], 1) : '-', |
||
| 74 | $percent==='true' ? ($member['problem_all']!=0 ? round($member['solved_all'] / $member['problem_all'] * 100, 1) : '-').' %' |
||
| 75 | : ($maxium==='true' ? $member['solved_all'].' / '.$member['problem_all'] : $member['solved_all']), |
||
| 76 | round($member['penalty']), |
||
| 77 | ]; |
||
| 78 | foreach ($this->contest_data as $contest) { |
||
| 79 | if (in_array($contest['cid'], array_keys($member['contest_detial']))) { |
||
| 80 | $contest_detial=$member['contest_detial'][$contest['cid']]; |
||
| 81 | array_push( |
||
| 82 | $row, |
||
| 83 | $contest_detial['rank'], |
||
| 84 | $percent==='true' ? (round($contest_detial['solved'] / $contest_detial['problems'] * 100, 1).' %') |
||
| 85 | : ($maxium==='true' ? $contest_detial['solved'].' / '.$contest_detial['problems'] : $contest_detial['solved']), |
||
| 86 | round($contest_detial['penalty']) |
||
| 87 | ); |
||
| 88 | } else { |
||
| 89 | array_push( |
||
| 90 | $row, |
||
| 91 | '-', |
||
| 92 | $percent==='true' ? '- %' |
||
| 93 | : ($maxium==='true' ? '- / -' : ' - '), |
||
| 94 | 0 |
||
| 95 | ); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | array_push($data, $row); |
||
| 99 | } |
||
| 100 | } else { |
||
| 101 | $row_1=['Member']; |
||
| 102 | $row_2=['']; |
||
| 103 | foreach ($this->tag_problems as $tag => $tag_problem_set) { |
||
| 104 | array_push($row_1, $tag); |
||
| 105 | array_push($row_2, 'Solved'); |
||
| 106 | } |
||
| 107 | $data=[$row_1, $row_2]; |
||
| 108 | foreach ($this->member_data as $member) { |
||
| 109 | $display_name=$member['name']; |
||
| 110 | if (!empty($member['nick_name'])) { |
||
| 111 | $display_name.=' ('.$member['nick_name'].')'; |
||
| 112 | } |
||
| 113 | $row=[ |
||
| 114 | $display_name, |
||
| 115 | ]; |
||
| 116 | foreach ($member['completion'] as $tag => $tag_completion) { |
||
| 117 | $count=count($tag_completion); |
||
| 118 | $solved=eval('return '.join('+', array_values($tag_completion)).';'); |
||
|
|
|||
| 119 | array_push( |
||
| 120 | $row, |
||
| 121 | $percent==='true' ? (round($solved / $count * 100, 1).' %') : ($maxium==='true' ? $solved.' / '.$count : $solved) |
||
| 122 | ); |
||
| 123 | } |
||
| 124 | array_push($data, $row); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | return collect($data); |
||
| 128 | } |
||
| 163 |